Object detection using SURF is scale and rotation invariant which makes it very powerful. Also it doesn’t require long and tedious training as in case of using cascaded haar classifier based detection. But the detection time of SURF is a little longer than Haar, but it doesn’t make much problem in most situations if the robot takes some tens of millisecond more for detection. Since this method is rotation invariant, it is possible to successfully detect objects in any orientation. This will be particularly useful in mobile robots where it may encounter situations in which it has to recognize objects which may be at different orientations than the trained image, say for example , the robot was trained with the upright image of an object and it has to detect a fallen object. Detection using haar features fails miserably in this case. OK, lets now move from theory to practical, the actual way things works.
OpenCV library provides an example of detection called find_obj.cpp. It can be found at the OpenCV-x.x.x/samples/c/ folder of the source tar file, where x.x.x stands for the version number. It loads two images, finds the SURF keypoints and descriptors , compares them and finds a matching if there is any. But this sample code will be a bit tough for beginners. So let us move slowly, step by step. As the first step , we can find the SURF keypoints and descriptors in an frame captured from the webcam. The code for the same is given below:
//*******************surf.cpp******************//
//********** SURF implementation in OpenCV*****//
//**loads video from webcam, grabs frames computes SURF keypoints and descriptors**// //** and marks them**//
//****author: achu_wilson@rediffmail.com****//
#include
#include
#include
#include
using namespace std;
int main(int argc, char** argv)
{
CvMemStorage* storage = cvCreateMemStorage(0);
cvNamedWindow("Image", 1);
int key = 0;
static CvScalar red_color[] ={0,0,255};
CvCapture* capture = cvCreateCameraCapture(0);
CvMat* prevgray = 0, *image = 0, *gray =0;
while( key != 'q' )
{
int firstFrame = gray == 0;
IplImage* frame = cvQueryFrame(capture);
if(!frame)
break;
if(!gray)
{
image = cvCreateMat(frame->height, frame->width, CV_8UC1);
}
//Convert the RGB image obtained from camera into Grayscale
cvCvtColor(frame, image, CV_BGR2GRAY);
//Define sequence for storing surf keypoints and descriptors
CvSeq *imageKeypoints = 0, *imageDescriptors = 0;
int i;
//Extract SURF points by initializing parameters
CvSURFParams params = cvSURFParams(500, 1);
cvExtractSURF( image, 0, &imageKeypoints, &imageDescriptors, storage, params );
printf("Image Descriptors: %d\n", imageDescriptors->total);
//draw the keypoints on the captured frame
for( i = 0; i total; i++ )
{
CvSURFPoint* r = (CvSURFPoint*)cvGetSeqElem( imageKeypoints, i );
CvPoint center;
int radius;
center.x = cvRound(r->pt.x);
center.y = cvRound(r->pt.y);
radius = cvRound(r->size*1.2/9.*2);
cvCircle( frame, center, radius, red_color[0], 1, 8, 0 );
}
cvShowImage( "Image", frame );
cvWaitKey(30);
}
cvDestroyWindow("Image");
return 0;
}
- SURF keypoints of my mobile phone
- The above picture shows the SURF keypoints captured by myself holding a mobile phone. The background wall has no strong intensity variations and hence no keypoints exist. An average of about 125 keypoints are detected in the above image and is shown in th terminal. Below are some more images.
-
From the above set of images, it can be clearly seen that SURF keypoints are those pixels whose average intensity values differ much greatly from the immediate neighbors, and by using the descriptor, a relation between the reliable keypoints and the neighboring pixels are obtained. Once the SURF descriptors and keypoints of two images are calculated, then they can be compared using one of the many algorithms like nearest neighbour , k-means clustering etc. SURF finds usage not only in object detection. It is used in many other applications like 3-D reconstruction.
Here are a few more screenshots of object recognition using surf:
Hi I am currently writing a surf program to detect multiple objects, however when i tried to detect more than 4 objects or above, my cpu is almost hit 100% and hang there, i not sure which part is wrong or any other ways to solve this. do you mind to help me? my email is jinhonglu89@gmail.com
Can you please share the complete code for object matching.. Please
Could you share the code for the matching part. I need to match some objects..
ok..what help do you need?
Hi Achu can u help me out with using surf for detection of an image in a video capture.
Hi,
How ı use surf library from here http://www.vision.ee.ethz.ch/~surf/download.html .and I dont know how I use it?
Can you help me plss!!!
“Error 3 error LNK2001: unresolved external symbol _cvSURFParams” I take this error.Please help me!!!!!!
somebody please reply..
I am usig SURF to extract features.I need to print the descriptors..can somebody help me how to convert the descriptor vector to matrix.I hav used reshape command..but its not working..this is wat i hav used..
cvExtractSURF( image, 0, &imageKeypoints, &imageDescriptors, storage, params );
and i hav used
CvMat desc = CvMat(imageDescriptors).reshape(0, keypoints.size());
But its not working…
If you dont want the detection to be scale invariant, it would be easier to implement using template matching.
Hello! I am trying to implement object detection as a hobby project. I came across SURF features and wrote some code based on OpenCV's tutorials that tries to find my object in the video coming from my laptop webcam.
Works, but the false-positive rate is too high. I mean even if my object is not present in front of the camera, the program manages to find scores of matches.
Do you know of a remedy?
Thanks!
I am doing a project on object recognition.ie to recognize object from video samples.I tried to use SURF algorithm to recognize object.But as the object is not scale invariant i am not able to extract the features accurately..is there any good algorithm to extract features even if the objects are not scale invariant..
The extracted SURF descriptors are present in the sequence “imageDescriptors”
i have been using SURF implementation to recognize object from images..Can somebody tell me how to get the descriptors rather than getting the number of descriptors..
Hey can you guide me on how to use these features in classification of objects. I am presently working on a project where i need to classify car in the image according to their make(eg. Ford, Fiat, Tata etc.) How can i proceed after getting the features from the car image.
Alisson, you should probably use Template Matching for bank-note recognition.
where are part2
Hello there. I'm from Brazil too and started using SURF just a few weeks ago. Anyway, i got some faster results using OpenMP with it (like 28% faster extraction). Congratulation for your tutorial, i'm really looking foward the second part.
Thanks.. Part 2 will be posted soon. I am a little busy now with my studies..
Hello, Very Nice Post, when is part 2 coming up?
Hi, I’m brazilian, I’m based in your work to develop an program for my monography. I would like an opinion. I need to make an program to recognize banknotes. Do you recommend that I do this with HaarTraining? Do you think I will have success? Otherwise, I would like an opinion how could I have a good result! Thank you.