Saturday, March 3, 2012

SURF Source code

When you install openCV, openCV samples folder also gets installed. The samples will be present in your InstallationDirectory/samples/C. For me it's present in OpenCV-2.1.0/samples/c.This folder contains the sample codes of many good openCV programmes that can be used for a wide variety of purposes. One more thing is that, it also contains the compiled object files along with the source code for each programme. The programme , we will be looking is find_obj.cpp and the compiled code will be with the name find_obj. This programme uses SURF to do an object detection.

I have modified the code to make it work for recognition. I did my summer project at IIT Kharagpur, and there we performed the experiments on face recognition with SURF. For the first time in face recognition history, we worked with color FERET database. We wrote a paper, describing our approach and writing the results of our work. The Research paper was sent to the proceedings of an international conference. Till that gets published, I cannot share my work. But it's so simple and intuitive, when you look at the code I mentioned. Best of luck with your work.

Update (29/06/12) :
I will release the modified source code on or before 8th July

24 comments:

Ed Watson said...

You are obviously obligated to keep your work unreleased until the paper you have written is published, but are there any hints you can give as to how you have modified the code for facial recognition. I am attempting to perform facial recognition using images from photographs for training, which obviously introduces a lot of variation, whether that is from the lighting, rotation, scale etc.
If you cannot give us any hints on your modifications, can you possibly release the statistics, or even just whether the research was successful in the testing stage?
Any light you can shed on the situation will be much appreciated.
Thank you very much indeed in advance.

Dileep said...

I want to make the code open source because if the code which I used hadn't has been available, I would not have performed the experiments at all. But, have to. And regarding the experiments..

At testing stage it was a success. With 100 images, it took out the perfect match. But when we performed the test with 1000 images, it took out perfect match only 80% of the times. Note that the images we tested against the original images were the same images, except with a different facial expression (Person opens his mouth, blinks one eye etc.,), some rotation and scale variant. Also, SURF itself is both rotation and scale invariant. So you can ignore scale and rotation variance when testing with SURF.

Ed Watson said...

Thank you for such a quick response!

Is your design able to work at real-time or near real-time speeds?

80% would be a great achievement for my project, especially if I can do it at near real-time speeds (I can do tracking after the face is recognised once).

Did you use just one image of each person for comparison? And can you disclose whether you used grayscale images or images with colour information?

Many thanks.

Dileep said...

Let me answer your questions one by one

Real time speeds : It depends on the number of descriptors you obtain, since SURF is essentially distance matching between descriptors. Less descriptors implies more speed. So while comparing take only the face region and usually the region between forehead to chin and cheek to cheek is enough. It took around 40 seconds to match one image of 300*300 pixels against 1000 of the same sized images.

Images : Yeah, I just used one image for comparison; the 1000 images are faces of unique people (no two faces were of same person) and one of them is our match. As stated in the post we used color images, but we converted them into black and white using Image Magick program in the pre-processing stage.

prit said...

hey,i am a student of B.tech 2nd year ece, VNIT Nagpur...i am trying to learn opencv by my own n m through with the basics.so nw i want to do advanced programming n detect no. of cars in traffic video.I've tried 2 learn algorithms bt nt getting ny idea.so please help me and give me some idea or related code if possible.I would be really thankful to you.

Dileep said...

Hey,

Honestly, you don't need SURF at all for the problem. You use SURF, when you have an object and you need to detect the exact object in the scene. But the cars in a traffic video, you cannot be exact about them. Their color may change, and as time proceeds new models may come etc., What you need here is a haar cascade classifier which is a general purpose way to distinguish objects belonging to the same class like pens or faces of people etc., The things you need to do are roughly:


1. Create a haar cascade XML file to detect car http://opencvuser.blogspot.in/2011/08/creating-haar-cascade-classifier-aka.html

2. Use it to detect cars in a photograph initially, just like the face detector was used for faces here http://opencvuser.blogspot.in/2011/06/face-detector.html

3. Then go for the video level. I haven't worked with videos but I read some posts about ffmpeg, which can help you in the same

Unknown said...

hi Dileep,
This is Shantanu,MCA student,persuing project in face recognition.
New to Iphone prog,gone through basics,done with detection,can you provide me more info about surf with some example.I m stuck with face matching,gone through various documentations,but failed.Please help me,n=m having exam in 20 days and i have submit it before,else i get detained.mail me back @
shantanu.chande@gmail.com

Regards,
Shantanu Chande

prit said...

thanx 4 your reply.I dont know much about haar training and I wanted to track those cars by blob-detection.And I am using CBlobResult in that.But its not working.Its giving lot of errors.Actually I am using Codeblocks with opencv2.0..I am just not getting what is wrong with this CBlobResult.Can you suggest some setup for it?Or another blob detecion and tracking code which uses very normal commands that can run easily on the system I am using currently?

majasheh said...

hi,
i want to detect vehicle and then dvanceetect type of vehicle...can u suggest me fastest way to detect vehicle...thanks in ad

Dileep said...

Hi majasheh,
the fastest way to detect the type of vehicle is by detecting it's logo and comparing it with the standard logos of automobile companies.

Hi Prit,
I have actually no knowledge using the blob techniques. Check the openCV documentation carefully and there is a yahoo group for open cv users. Google it and post your query there. May be someone can help.

Hi Shantanu,
Sorry, that I am busy with my new job and all, I could not help you at that time. But seriously, the things in this blog are enough to get started and keep going.

Unknown said...

Hi, I need to count fingers in hands with a webcam, Can you suggest me some ideas?
Thanks.

Dileep said...

First you need to train a haar cascade classifier, that could detect one finger, using atleast a 100 images of a finger. This is explained in one of my previous posts. Or atleast you need to get one such finger detector from net - a .xml file. Using that you can you the same face detector code, used in my previous posts (replacing the .xml file, with the .xml of finger detector) and give a counter, to count the fingers. SURF is not needed for this purpose.

Unknown said...

Hi, i need to extend the circumference of a circle detection in opencv using c++. Can you suggest to me some ideas ? thank you

Dileep said...

Am not getting you. Actually, if you train a haar cascade classifier, it can detect the object of size greater than a minimum threshold, irrespective of it's original size

Unknown said...

Hello,
Your code has helped us a lot.I actually need to compare all stored logos with a sequence of continuous frames(video) to detect TV advertisement.How should i approach with this code?
Do u have any idea regarding audio processing in openCV?

Unknown said...

Hello,
Your code has helped us a lot.I actually need to compare all stored logos with a sequence of continuous frames(video) to detect TV advertisement.How should i approach with this code?
Do u have any idea regarding audio processing in openCV?

Dileep said...

Thank you for your compliment.
Using my code, I have done a face detector, that takes video from my webcam(post related to that is present in this blog only). So, I don't think there should be a problem with detecting faces(logo in your case) in a running video, though I haven't tried it.
Sorry, I have no idea about audio processing.

Dileep said...

Hi,
Yesterday before going to sleep, I got an idea related to audio processing. There are many tools that could generate graphs, from a given audio. So, you can use those graphs to compare against each other, which comes back to the problem, similar to comparing logos.

Unknown said...

Hi ,
I see you have good experience on SURF ... I would like to ask you a specific question so I can improve my results in my project ...

I am using SURF to identify a specific object in videos
Actually I have 4 object I am trying to find them .... one of them is big enough to get it correctly in all frames ...
my problem is finding the other objects which are small little bit
for example if the image size is 720 * 480
the big one that works good has size 125*110
the others that do not give good results have the following size
(100 , 45) , (90 , 40) , (80,40)
BTW: the videos are X-ray
I would like to know how can I change the parameters of the SURF to get these object correctly
if you want I can show you my code and example of my images....
please help me in this issue

Dileep said...

Hii Seereen,

It's hard to get interest points when the object sizes are small. One thing you can do is..increase the size of the descriptor. Use a 128 sized vector descriptor, instead of the 64 one. It may take more time for detection, but ultimately it works. You can check my code in the next two posts, where I wrote the code, to get an idea.

Unknown said...

Thanks for your replay
but i did not got how can I increase the size of the vector
I am using built in function in openCV

Unknown said...

hi,dileep,we are currently working on a robotic eye with gaze stabilization. One of the focus of our study is to make the robotic eye to follow the target object we choose by clicking it through the monitor of our computer & make the robotic eye with camera to follow it fast(at least 500 degrees per second)...Can you give us some advice or pointers on how to apply the SURF algorithm on our project,we are using visual studio with OpenCV...my email is wacky0627@gmail.com..thank u and it will be of great help to us.

Anonymous said...

Hi Dileep,

For my B.Tech(CSE)project in the title "Mobile medical Content Based Image information retrieval", can I go with the opencv surf algorithm. Because I haven't a clear idea about it, will u help me by sending coding if u r having means..

Dileep said...

Hi SelvaRathi,
You can proceed. Please go through all my posts, to get a understanding of openCV and SURF and you can use the code for free which is here. This has no license and crap, so you can embed this in your university projects also.

Post a Comment