David Lowe's sift has always been used by everyone. We can't compile it by ourselves. It's not as good as we can compile it.
First, use sift to extract feature points from the target object as the basis for subsequent judgment.
The purpose of the demo is to detect the target object in another video.
We use opencv to read a video.
Use sift to extract the feature points of each frame and then perform matching.
At first, I wanted to delete the error detection points, but I found that it was not very good at processing, algorithm time, number of error points, and how to achieve the best was troublesome.
Finally, I think that the number of matching points should be determined if the target is to be detected.
If the number is large enough, an alarm is triggered. That is, to define a threshold value.
The program source code is as follows:
void main(){int i = 0;int num =0;CvCapture *capture; IplImage *frame;IplImage *tempframe;IplImage *object;Keypoint k1 = NULL, k2 = NULL;//tempframe = cvCreateImage(capture = cvCaptureFromFile("D:\\My Documents\\Visual Studio 2008\\Projects\\siftobject\\PETS-09.avi");////////////////////////////////////////object = cvLoadImage("object.png",1);IplImage *objecttemp;objecttemp = cvCreateImage(cvGetSize(object),8,1);cvCvtColor(object,objecttemp,CV_BGR2GRAY);char filename1[1024];sprintf(filename1,"D:\\My Documents\\Visual Studio 2008\\Projects\\siftobject\\siftobject\\object.pgm",i);cvSaveImage(filename1,objecttemp);system("siftWin32.exe <object.pgm >object.key");cvNamedWindow("Webcam",0);////////////////////////////////while(i<10) { frame = cvQueryFrame(capture);tempframe = cvCreateImage(cvGetSize(frame),8,1);cvCvtColor(frame,tempframe,CV_BGR2GRAY);//cvShowImage("Webcam",frame); //cvWriteFrame(writer,frame);char filename[1024];sprintf(filename,"D:\\My Documents\\Visual Studio 2008\\Projects\\siftobject\\siftobject\\test.pgm",i);cvSaveImage(filename,tempframe); //cvShowImage("Webcam",tempframe); printf("%d\n",i);//cvWaitKey(0); //if(cvWaitKey(20)>0) break; i++;system("siftWin32.exe <test.pgm >test.key");char* test = "test.key";char* object = "object.key";k1 = ReadKeyFile(test);k2 = ReadKeyFile(object);num = FindMatches(k1,k2,tempframe);cout<<num<<endl;num = 0;//cvShowImage("Webcam",tempframe);//system("siftWin32.exe <test.pgm >test.key"); } cvReleaseCapture(&capture); cvDestroyWindow("Webcam");}
Because the source code of the program is very long, only the main function is provided here.
For other code, see David Lowe's personal website.
Http://www.cs.ubc.ca /~ Lowe/
In addition, the homepage of another cool man is provided.
Andrea vedaldi: http://www.vlfeat.org /~ Vedaldi/his code is more efficient and more effective.
If you want to do the same job, contact me and discuss it together.