2013-05-21 27 views
0

我使用camshift跟蹤tennisballs,並在找到它之後在tennisball周圍繪製橢圓。然而,每隔一段時間我得到這個錯誤OpenCV從camshift算法輸出中繪製一個橢圓。

OpenCV Error: Assertion failed (box.size.width >= 0 && box.size.height >= 0 &&  thickness <= 255) in ellipse, file /home/eanders/src/OpenCV-2.4.2/modules/core/src/drawing.cpp, line 1678 terminate called after throwing an instance of 'cv::Exception' 
what(): /home/eanders/src/OpenCV-2.4.2/modules/core/src/drawing.cpp:1678: error: (-215) box.size.width >= 0 && box.size.height >= 0 && thickness <= 255 in function ellipse 

我假設的CAMSHIFT方法返回一個RotatedRect對象,在某種程度上是正確的尺寸的橢圓內要繪製的不是。任何想法如何糾正這一點?代碼如下。先謝謝你們。

Rect trackWindow = Rect(p1, box); 
///employ camshift algorithm 
RotatedRect trackBox = CamShift(backproj, trackWindow, TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1)); 
ellipse(image, trackBox, Scalar(255,255,255), 3, CV_AA); 
ellipse(backproj, trackBox, Scalar(255,255,255), 3, CV_AA); 

回答

0

在我看來好像算法不能跟蹤對象。 這將是很好的知道爲什麼,但現在我會檢查旋轉矩形的尺寸。 這顯然是這個說法抱怨的。

+0

耶,這是可能的。我決定只需轉儲橢圓並在RotatedRect的中心座標處放一個小圓圈就簡單了,因爲我最感興趣的是該中心點。感謝你的回答。 – cirea22

+0

RotatedRect有一個有用的位置? I ** guess **,算法不能跟蹤對象,因此返回一個默認的矩形(尺寸爲0x0,也許位置爲0,0)。因此,您可能會將這些點繪製在錯誤的位置...... – elactic

+0

是的,RotatedRect似乎大部分都在跟隨對象。我的工作似乎很順利。 – cirea22