Difference between revisions of "Function:TrackFeatures"

From CUVI Wiki
(Created page with "__NOTOC__ CUVI Feature tracker tracks input features from frame 1 onto frame 2. The function is ideal for tracking selected number of features through an image sequence or a v...")
 
Line 80: Line 80:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">


//Create an 8-bit Grays-scale CuviImage
CuviImage *gpu_image = new CuviImage(size,img->depth,img->nChannels);


//Populate the Image
//Image size
gpu_image->upload(img->imageData,img->widthStep);
CuviSize size = cuviSize(img1->width,img1->height);


CuviPointValue2D *features;
//Create two 8-bit Grays-scale CuviImage
CuviImage* gimg1 = new CuviImage(size,img1->depth,img1->nChannels);
CuviImage* gimg2 = new CuviImage(size,img1->depth,img1->nChannels);


//Desired number of features
//Populate the GPU Images
int featureCount = 100;
gimg1->upload(img1->imageData,img1->widthStep);
gimg2->upload(img2->imageData,img2->widthStep);


//Selecting complete image for the process
CuviPointValue2D* features1, *features2;
CuviROI roi = cuviROI(0,0,img->width,img->height);


//Setting Feature selection parameters
//selection and tracking criteria
CuviFeaturesCriteria criteria = cuviFeaturesCriteria(CUVI_FEATURES_HARRIS_PETER,0.006f,15,3,-2.0f);
CuviFeaturesCriteria fc = cuviFeaturesCriteria(CUVI_FEATURES_HARRIS,0.006f,22);
CuviTrackingCriteria tc = cuviTrackingCriteria(2,cuviSize(12,12),15,10.0f);
 
//ROI for selection
CuviROI roi = cuviROI(0,0,img1->width,img1->height);
 
int featureCount = 50;
 
//Select Features
cuvi::ComputerVision::goodFeaturesToTrack(gimg1,roi,&features1,&featureCount,fc);
 
//Track the selected features from first frame onto second frame
cuvi::ComputerVision::trackFeatures(gimg1,gimg2,features1,&features2,featureCount,tc);


//Calling GoodFeaturesToTrack
cuvi::computerVision::goodFeaturesToTrack(&gimg,roi,&features,&featureCount,criteria);


</syntaxhighlight>
</syntaxhighlight>
|}
|}

Revision as of 07:13, 26 April 2012

CUVI Feature tracker tracks input features from frame 1 onto frame 2. The function is ideal for tracking selected number of features through an image sequence or a video stream. This is a custom algorithm and does not use optical flows to estimate motion. Check out Motion Estimate section for more details on Optical Flow based motion tracking.

Function

CuviStatus trackFeatures(CuviImage* previousImage,
                         CuviImage* nextImage,
                         CuviPointValue2D* inputFeatures,
                         CuviPointValue2D** trackedFeatures,
                         Cuvi32s featureCount,
                         CuviTrackingCriteria criteria,
                         CuviStream* stream = NULL);

Parameters

Name Type Description
previousImage CuviImage* The first image whose features are to be tracked
nextImage CuviImage* Second image, in which to look for features of first image
inputFeatures CuviPointValue2D* Feature of first image
trackedFeatures CuviPointValue2D** Output feature list containing the location of tracked features from first image onto second image
featureCount Cuvi32s Number of features to track
criteria CuviFeaturesCriteria A structure containing various parameters that affect feature tracking behavior
stream CuviStream* GPU stream ID for execution


Image Type Support

Input Output
8uC1 CuviPointValue2D


Samples

Frame0.jpg
Frame1.jpg


Example

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

//Create two 8-bit Grays-scale CuviImage
CuviImage* gimg1 = new CuviImage(size,img1->depth,img1->nChannels);
CuviImage* gimg2 = new CuviImage(size,img1->depth,img1->nChannels);

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

CuviPointValue2D* features1, *features2;

//selection and tracking criteria
CuviFeaturesCriteria fc = cuviFeaturesCriteria(CUVI_FEATURES_HARRIS,0.006f,22);
CuviTrackingCriteria tc = cuviTrackingCriteria(2,cuviSize(12,12),15,10.0f);

//ROI for selection
CuviROI roi = cuviROI(0,0,img1->width,img1->height);

int featureCount = 50;

//Select Features
cuvi::ComputerVision::goodFeaturesToTrack(gimg1,roi,&features1,&featureCount,fc);

//Track the selected features from first frame onto second frame
cuvi::ComputerVision::trackFeatures(gimg1,gimg2,features1,&features2,featureCount,tc);