Ask Your Question

viratan's profile - activity

2013-12-05 10:53:56 -0600 asked a question Homography for set of trainimages

How can I use findhomography()and perspectiveTransform() methods in the case where you have keypoints obtained from the trainset of images.

following is my code.

cv::BruteForceMatcher<cv::HammingLUT > descriptormatcher; 
descriptormatcher.add(addtraindesc); 
descriptormatcher.train();  
descriptormatcher.match(descriptor1,matches1);
 //calculate min and max distance between keypoints
 double max_dist =  0;
 double min_dist = 100;
 for (int i_desc=0; i_desc< descriptor1.rows;i_desc++)
 {
     double dist=matches1[i_desc].distance;
     if( dist < min_dist ) min_dist = dist;
     if( dist > max_dist ) max_dist = dist;
 }
 //Get only good matches
 vector<DMatch> goodmatches;
 for (int i_desc=0; i_desc< descriptor1.rows;i_desc++)
    {
      double good_dist=3*min_dist ;
     if( matches1[i_desc].distance < good_dist )
      { goodmatches.push_back( matches1[i_desc]); }
    }
// calculate object and scene points
 std::vector<Point2f> obj;
 std::vector<Point2f> scene;
 vector<vector<KeyPoint> > newtrainkeypoints=gettrainkeypoints();
for(int i_gm=0; i_gm<goodmatches.size(); i_gm++)
 {
  DMatch imatch = goodmatches[i_gm];
  obj.push_back(newtrainkeypoints[imatch.imgIdx][imatch.trainIdx].pt);
  scene.push_back(v1[imatch.queryIdx].pt);
 }
Mat H = findHomography( obj, scene, CV_RANSAC );
std::vector<Point2f> obj_corners(4);
 // how to calculate the obj_corners for array of images from training set
std::vector<Point2f> scene_corners(4);
     perspectiveTransform( obj_corners, scene_corners, H);
   line( mRgb1, scene_corners[0], scene_corners[1], Scalar(0, 255, 0), 4 );
   line( mRgb1, scene_corners[1], scene_corners[2], Scalar( 0, 255, 0), 4 );
   line( mRgb1, scene_corners[2], scene_corners[3], Scalar( 0, 255, 0), 4 );
   line( mRgb1, scene_corners[3], scene_corners[0], Scalar( 0, 255, 0), 4 );

One quick dirty solution would be to put this entire part of code in a forloop for all the images in training set and perform homography if the number of good matches is greater than 4 .but that would be very ineffective in terms of performance since i plan to use this code for the JNI part of android project im working on.

Can anyone please guide me on how do the perspective transform and draw a rectangle around the detected object or suggest any better methods of doing it.(so far in my search through internet,i could only find 1 to 1 image matching and then draw homography for the detected object)

2013-11-15 06:38:33 -0600 received badge  Student (source)
2013-11-15 04:36:57 -0600 asked a question Training Kd tree for object detection android

I am working on real time object recognition using Opancv4android, i am able to detect, extract feature points using ORB detector and descriptor extractor from the image i capture using camera . Now, i want to build a Kdtree and train them with these feature points and later i match these feature points in the tree with feature points detected by the camera in real time and recognizance the object . Please help me on how do i go about building a KD tree in opencv or any pointers or references/tutorials on KDtree for opencv will be very helpful.