increase the size of features,surf!!

asked 2017-05-17 06:06:58 -0600

kzbr93 gravatar image

updated 2017-05-17 06:14:22 -0600

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

edit retag flag offensive close merge delete

Comments

" 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 !)

berak gravatar imageberak ( 2017-05-17 06:37:49 -0600 )edit

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

kzbr93 gravatar imagekzbr93 ( 2017-05-17 07:07:36 -0600 )edit

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

kzbr93 gravatar imagekzbr93 ( 2017-05-17 07:09:45 -0600 )edit

what are you trying to achieve, in general ? (and no, atm it's entirely unclear)

berak gravatar imageberak ( 2017-05-17 07:19:00 -0600 )edit

i am trying to do obstacke avoidance using SURF features detector

kzbr93 gravatar imagekzbr93 ( 2017-05-17 08:34:10 -0600 )edit

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 ?

kzbr93 gravatar imagekzbr93 ( 2017-05-17 08:36:45 -0600 )edit

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) ?

berak gravatar imageberak ( 2017-05-17 09:14:18 -0600 )edit

http://citeseerx.ist.psu.edu/viewdoc/... this is what i mean from scale expansion @berak

kzbr93 gravatar imagekzbr93 ( 2017-05-17 09:34:09 -0600 )edit

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..

berak gravatar imageberak ( 2017-05-17 09:59:02 -0600 )edit

what i could do is, compare the previous frame with that of current, and do a template matching, what say ??

kzbr93 gravatar imagekzbr93 ( 2017-05-17 10:01:16 -0600 )edit