increase the size of features,surf!!
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 is 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
" and i need to increase the size of the feature if the object in the frame is getting closer" -- what ? why that ?
also, i'm pretty sure, you did not mean "increasing the size of the features", but the number of keypoints detected ? (quite a difference !)
no i mean size of the feature by a factor of say 1.2 or some thing,, only those feature then i need to display whole size is changing , or the object is approaching near
then if i could do this then all the features of a table,window , wall etc unless my vehicle is getting closer to it wont be considered as obstacle. . i hope i am clear
what are you trying to achieve, in general ? (and no, atm it's entirely unclear)
i am trying to do obstacke avoidance using SURF features detector
and motive is to compare current frame with that of previous and analyse, if the drone or vehicle is approaching towards an obstacle, its features diameter increases , i.e. the obstacle is getting bigger for the vehicle, and we need to avoid those points which are not growing in size or can not be considered as obstacle,, am i clear now ?
SURF features have a fixed size (128 bytes) you can't in or decrease that.
but i'm certain, you did not mean the actual SURF features, but something else (unspecified), thus the confusion.
then, how do you plan to use feature matching for obstacle detection (it seems quite unrelated) ?
http://citeseerx.ist.psu.edu/viewdoc/... this is what i mean from scale expansion @berak
oh, you should have come up with that much earlier, i guess ;)
but the only takeaway from a quick glance at the paper is: the keypoint radius increases (they get further spaced apart), if you get closer to "the object" -- well oh, here's the bummer: feature detection is not really restricted to "objects", it finds points & features in whole images. sieving out , what is actually relevant, will be painful, if not impossible..
what i could do is, compare the previous frame with that of current, and do a template matching, what say ??