利用 David Lowe 的sift源碼實現遺留物檢測

來源:互聯網
上載者:User

 David Lowe 的sift一直被大家拿來使用,自己編不出來,編出來估計也不如人家編的好,就拿來用了

首先利用sift對目標物提取特徵點,作為之後的判斷依據

demo的目的是再一段視頻中檢測到目標物體。

我們利用了opencv去讀取一段視頻

利用sift去提取每一幀的特徵點,之後進行匹配

起初想去除錯檢測點,但發現確實不太好處理,演算法時間,錯誤點數量,如何達到最優都比較麻煩。

最後覺得既然是要檢測出目標那麼判斷匹配點的數量

如果數量足夠多那麼就發出警示。也就是規定一個閥值而已。

程式源碼如下:

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");}

由於程式源碼很長,這裡僅僅貼出了主函數部分。

其他代碼大家可以參看 David Lowe 的個人網站。

http://www.cs.ubc.ca/~lowe/

另外給出另一個牛人的homepage

Andrea Vedaldi:http://www.vlfeat.org/~vedaldi/ 他的代碼效率更高,效果更好。

希望做同樣工作的同學跟我聯絡,共同討論。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.