CUVI by Example
<syntaxhighlight lang="c">
static const float MovementThreshold = 0.33f; //Mark as motion if a feature moves 0.33 Pixels
//Checks if the feature has moved from is original location bool FeatureHasMoved(CuviPointValue2D point1, CuviPointValue2D point2, float thresh) { if(point2.val != 0.0f) return false; return ((fabsf(point1.x - point2.x)>thresh) || (fabsf(point1.y - point2.y)>thresh)); }
void main() { //Read a Video Frame CuviImage* gFrame = new CuviImage(Width,Height,GetOpenCVPitch(Width,Height,8,3),8,3); CuviImage* gimg1 = new CuviImage(Width,Height,GetOpenCVPitch(Width,Height,8,1),8,1); CuviImage* gimg2 = new CuviImage(Width,Height,GetOpenCVPitch(Width,Height,8,1),8,1); CuviROI roi = cuviROI(0,0,Width,Height); CuviPointValue2D *features1, *features2; int feature_count = 0; do { //Read Frame gFrame->upload(frame->imageData); cuvi::colorConvert(gFrame,gimg1); //Read Next Frame gFrame->upload(frame->imageData); cuvi::colorConvert(gFrame,gimg2); feature_count = RequestedFeatures; //Reset feature count to original if(AdjustImage) { cuvi::adjust(gimg1); cuvi::adjust(gimg2); } if(SmoothBeforeSelecting) { //Apply Gaussian Smoothing Filter On Both The Images cuvi::imFilter(gimg1,roi,Gauss); cuvi::imFilter(gimg2,roi,Gauss); } //Call A Feature Detector ( KLT | HARRIS | PETER ) cuvi::goodFeaturesToTrack(gimg1,roi,features1,&feature_count,CUVI_FEATURES_HARRIS,FeatureQuality,FeatureMinDistance,3,k); //Track Features Using KLT Method cuvi::trackFeatures(gimg1,gimg2,features1,features2,feature_count,PyramidLevels,TrackingWindow,Residue,Iterations); //Plot The Tracked Features for(int i=0; i<feature_count; i++) if(FeatureHasMoved(features1[i],features2[i],MovementThreshold)) //Plot Only If The Feature Has Moved From Its Location
|