2013-03-18 64 views
5

我正在製作一個跟蹤來自OpenCV(2.43)的ORB功能的程序,我跟着 this tutorial和使用建議from hereOpenCV的findHomography產生無意義的結果

我的目標是追蹤視頻中的物體(臉部)並在其周圍畫一個矩形。

我的程序找到關鍵點,正確匹配他們,但是當我嘗試使用findHomography + perspectiveTransform尋找新的角落的圖像通常返回一些廢話類型值(雖然有時它返回正確的單應)。

下面是一個例子圖片: example

這裏是對應問題的部分:

代碼
Mat H = findHomography(obj, scene, CV_RANSAC); 

//-- 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); 
std::vector<Point2f> scene_corners(4); 

perspectiveTransform(obj_corners, scene_corners, H); 

//-- 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); 

休息是幾乎相同的,如我提供的鏈接。 繪製的線條看起來完全隨機,我的目標只是在新場景中獲取源對象的最小矩形,所以如果有替代使用單應性的作品。

P.S.要跟蹤的源圖像是從視頻輸入中複製的區域,然後從該輸入的新圖像中進行跟蹤,這是否重要?

+0

提供更多信息,例如輸出圖像會很有用。 – 2013-03-18 21:22:32

+0

好吧,它就像這裏:http://dl.dropbox.com/u/5481096/Clipboard02.jpg。 – user2184001 2013-03-18 21:47:29

+0

我編輯了圖像到你的問題。如果您想在將來提供更多信息,最好編輯您的問題,以便更多人可以輕鬆查看。 – 2013-03-18 21:55:02

回答

0

函數perspectiveTransform在假設您的對應點集不容易出錯的情況下估計單應性。但是,在現實世界的數據中,你不能假設這一點。解決方案是使用穩健的估計函數,如RANSAC來解決單應性問題,作爲超定方程組。

您可以使用findHomography函數來代替它,它返回一個單應性。這個函數的輸入是一組點。這個集合至少需要4個點,但更大的集合更好。單應性只是一個估計,但對錯誤更加穩健。通過使用CV_RANSAC標誌,可以內部刪除異常值(錯誤的點對應關係)。

相關問題