hello guys, i am working on algorithm based on SURF feature detector, and i need to increase the size of the feature if the object in the frame in getting closer and ignore those features whose size is not changing...
so far i have this code :..
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/calib3d.hpp>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
/** @function main */
int main( int argc, char** argv )
{
VideoCapture cap(0);
//Mat curr, prev;
if(!cap.isOpened())return -1;
Mat frame;
Mat prevframe;
while (cap.isOpened()) {
cap.read(frame);
// more code goes here which I haven't written here
frame.copyTo(prevframe); // set previous frame to current frame
//imshow("Video current", frame);
// imshow("Videoprevious", frame);
char key = waitKey(33);
if (key == 'q')
{
break;
}
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 100;
Ptr<SURF> detector = SURF::create( minHessian );
detector->setHessianThreshold(minHessian);
std::vector<KeyPoint> keypoints1,keypoints2;
Mat descriptors_1, descriptors_2;
detector->detectAndCompute( frame, Mat(), keypoints1, descriptors_1 );
detector->detectAndCompute( prevframe, Mat(), keypoints2, descriptors_2 );
//-- Step 2: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_1.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
//-- small)
//-- PS.- radiusMatch can also be used here.
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_1.rows; i++ )
{ if( matches[i].distance <= max(2*min_dist, 0.02) )
{ good_matches.push_back( matches[i]);}
}
//-- Draw only "good" matches
Mat img_matches;
drawMatches( frame, keypoints1, prevframe, keypoints2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Show detected matches
imshow( "Good Matches", img_matches );
if( (good_matches.size() >=20)){
for( unsigned int i = 0; i < good_matches.size(); i++ )
{
}
}
}
waitKey(0);
return 0;
}
please help
thanks all