0

I am working on Real Time object Detection using SVM in OpenCV. My objects include, book, mug, box, monitor and negative training samples.

  1. Feature Detector - SURF
  2. Sample of Each Positive Images - 200 each (acquired from Web)
  3. Negative Sample - 400 images

After training SVM I can correctly recognise the frame containing the object. But I am unable to place a correct bounding box around the object.

For a single object and a scene image, http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html this tutorial from OpenCV gives insight on how to perform detection and placing of the bounding box.

Now in my case, I have 200 cropped image of the object, How can I determine the correct location and the size of the correct bounding box around the object in the environment. That is how I know which image from the training set is the best match.

kcc__
  • 1,638
  • 4
  • 30
  • 59

1 Answers1

1

If you now, from your SVM, which object is propably in the Image you can just use an Image that contains only your Object as "object image" and your current sample as "scene image".
Than you can follow the Example "Features2D + Homography to find a known object" (that you already mentioned) to find the Position of your Object in the Scene. If you want to draw only the Bounding Box (and not the matched features) just extract the Corner Points from your Object (Code from the Example):

 //-- Get the corners from the image_1 ( the object to be "detected" )
std::vector<Point2f> obj_corners(4);
obj_corners[0] = cvPoint(0,0); 
obj_corners[1] = cvPoint( img_object.cols, 0 );
obj_corners[2] = cvPoint( img_object.cols, img_object.rows ); 
obj_corners[3] = cvPoint( 0, img_object.rows );

and convert them into scene coordinates

std::vector<Point2f> scene_corners(4);

perspectiveTransform( obj_corners, scene_corners, H);

assuming you have already computed the Homography Matrix H.

Now you have the Corner Point in Scene Coordinates and can simply draw the Lines between the Corner Points to get your Bounding Box (Code from the Example):

//-- Draw lines between the corners (the mapped object in the scene - image_2 )
  line( img_matches, scene_corners[0] + Point2f( img_object.cols, 0), scene_corners[1] + Point2f( img_object.cols, 0), Scalar(0, 255, 0), 4 );
  line( img_matches, scene_corners[1] + Point2f( img_object.cols, 0), scene_corners[2] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
  line( img_matches, scene_corners[2] + Point2f( img_object.cols, 0), scene_corners[3] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
  line( img_matches, scene_corners[3] + Point2f( img_object.cols, 0), scene_corners[0] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );

Important is that your "object_image" contains only the Object and nothing else.

If you want to get the best Sample from your Class you must compute scores for each sample. This can be done using the Method described in: "Probability Estimates for Multi-class Classification by Pairwise Coupling" from Wu et. al. which you can find here.

However this could be too slow for a real-time application.

Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46
  • Thank you for your solution and that seems great idea. However, the problem here is computation of the boundary which is hard to achieve real time performance. Also like for an object I can have multiple view in the environment so therefore no single image for the object will guarantee detection of the true boundary. This is actually my problem at the moment – kcc__ Nov 26 '13 at 04:27
  • Ok this is how I understand your Problem:(simplified) You have two Classes A & B. After deciding which Class your Sample belongs to (A or B) you wan´t the best Sample from your Class that matches your current Sample to get the orientation and view correctly. Ok. You can compute per-class scores for each sample. There is a good Paper about this: http://www.csie.ntu.edu.tw/~cjlin/papers/svmprob/svmprob.pdf but it could be too slow for you. – Mailerdaimon Nov 26 '13 at 07:36
  • that is correct. However I have multiple class to be precise 4 class of positive and 1 class of negative. Ok i will read the paper and see if it works for me. Thanks for your help. I will come back incase if I find problem please bear me since I am new to image processing field. Thank you – kcc__ Nov 26 '13 at 07:51