Difference between revisions of "Function:OpticalFlowPyrLKDense"

From CUVI Wiki
Line 5: Line 5:
|style="font-size:150%;"|
|style="font-size:150%;"|
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
CuviStatus opticalFlowPyrLKDense(CuviImage* previousImage,
CuviStatus opticalFlowPyrLKDense(const CuviImage& previous,
                                 CuviImage* nextImage,
                                 const CuviImage& next,
                                 Cuvi32f* flowX
                                 Cuvi32f* flowX
                                 Cuvi32f* flowY,
                                 Cuvi32f* flowY,
                                 CuviTrackingCriteria criteria,
                                 const CuviTrackingCriteria criteria,
                                 CuviStream* stream = NULL);
                                 const CuviStream& stream = CuviStream());
</syntaxhighlight>
</syntaxhighlight>
|}
|}
Line 21: Line 21:
! Description
! Description
|-
|-
| previousImage
| previous
| CuviImage*
| CuviImage&
| The first image whose features are to be tracked
| The first image whose features are to be tracked
|-
|-
| nextImage
| next
| CuviImage*
| CuviImage&
| Second image, in which to look for features of first image
| Second image, in which to look for features of first image
|-
|-
Line 38: Line 38:
|-
|-
| criteria
| criteria
| CuviFeaturesCriteria
| const CuviFeaturesCriteria
| A structure containing various parameters that affect optical flow calculation  
| A structure containing various parameters that affect optical flow calculation  
|-
|-
| stream
| stream
| CuviStream*
| const CuviStream&
| GPU stream ID for execution
| GPU stream ID for execution


Line 78: Line 78:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">


//Image size
CuviSize size = cuviSize(width,height);


//Create two 8-bit Grays-scale CuviImage objects
//Create two 8-bit Grays-scale CuviImage objects
CuviImage* gimg1 = new CuviImage(size,8,1);
CuviImage gimg1 = cuvi::io::loadImage(path,CUVI_LOAD_IMAGE_GRAYSCALE);
CuviImage* gimg2 = new CuviImage(size,8,1);
CuviImage gimg2 = cuvi::io::loadImage(path,CUVI_LOAD_IMAGE_GRAYSCALE);


//Populate the GPU Images
gimg1->upload(img1->imageData,img1->widthStep);
gimg2->upload(img2->imageData,img2->widthStep);


Cuvi32f* flowX = new Cuvi32f[width * height];
Cuvi32f* flowX = new Cuvi32f[gimg1.width() * gimg1.height()];
Cuvi32f* flowY = new Cuvi32f[width * height];
Cuvi32f* flowY = new Cuvi32f[gimg1.width() * gimg1.height()];


//tracking criteria
//tracking criteria
CuviTrackingCriteria tc = cuviTrackingCriteria(2,cuviSize(12,12));
CuviTrackingCriteria tc;
 


//Compute optical flow between first frame and second frame
//Compute optical flow between first frame and second frame

Revision as of 15:55, 19 April 2013

Computes Dense Optical Flow between each pixel of two images using pyramidal Lucas-Kanade method.

Function

CuviStatus opticalFlowPyrLKDense(const CuviImage& previous,
                                 const CuviImage& next,
                                 Cuvi32f* flowX
                                 Cuvi32f* flowY,
                                 const CuviTrackingCriteria criteria,
                                 const CuviStream& stream = CuviStream());

Parameters

Name Type Description
previous CuviImage& The first image whose features are to be tracked
next CuviImage& Second image, in which to look for features of first image
flowX Cuvi32f* Horizontal optical flow
flowY Cuvi32f* Vertical optical flow
criteria const CuviFeaturesCriteria A structure containing various parameters that affect optical flow calculation
stream const CuviStream& GPU stream ID for execution


Image Type Support

Input Output
2x 8uC1 2x Cuvi32f*


Samples

Error creating thumbnail: Unable to save thumbnail to destination
First Input Image (8-bit)
Error creating thumbnail: Unable to save thumbnail to destination
Second Input Image (8-bit)
Error creating thumbnail: Unable to save thumbnail to destination
Optical Flow Magnitude
Error creating thumbnail: Unable to save thumbnail to destination
Flow of selected points


Example

//Create two 8-bit Grays-scale CuviImage objects
CuviImage gimg1 = cuvi::io::loadImage(path,CUVI_LOAD_IMAGE_GRAYSCALE);
CuviImage gimg2 = cuvi::io::loadImage(path,CUVI_LOAD_IMAGE_GRAYSCALE);


Cuvi32f* flowX = new Cuvi32f[gimg1.width() * gimg1.height()];
Cuvi32f* flowY = new Cuvi32f[gimg1.width() * gimg1.height()];

//tracking criteria
CuviTrackingCriteria tc;

//Compute optical flow between first frame and second frame
cuvi::computerVision::opticalFlowPyrLKDense(gimg1,gimg2,flowX,flowY,tc);