我想在邊界框中繪製一個點,表示該框的中心點。 我已經計算了中心點,但它只能在CMD中輸出,並且我不會將此點顯示在圖像上。OpenCV繪圖邊界框CenterPoint
我與OpenCV2.4.3工作的Visual Studio 2010的C++
for(int i= 0; i < boundRect.size(); i++)
{
//BoundingBox Area
boundingBoxArea.clear();
boundingBoxArea.push_back(Point2f(boundRect[i].x, boundRect[i].y));
boundingBoxArea.push_back(Point2f(boundRect[i].x + boundRect[i].width, boundRect[i].y));
boundingBoxArea.push_back(Point2f(boundRect[i].x + boundRect[i].width, boundRect[i].y + boundRect[i].height));
boundingBoxArea.push_back(Point2f(boundRect[i].x, boundRect[i].y + boundRect[i].height));
double area0 = contourArea(boundingBoxArea);
cout << "area of bounding box no." << i << " = " << area0 << endl;
//Bounding Box Centroid
area0 = (boundRect[i].x + boundRect[i].width)/2, (boundRect[i].y + boundRect[i].height)/2;
cout<<"Rectangle " <<i<< " Centroid possition is at: " "=" <<area0<<endl;
cout<<""<<endl;
cout<<""<<endl;
}
以上是我用得好只是一小部分,但是,負責包圍盒計算的一部分代碼
看起來這實際上現在允許我使用Circle()函數來繪製我的點/中心點 – Tomazi 2013-02-19 23:16:32
但是,中心點會在邊界框外繪製,所以此代碼存在更多問題:D – Tomazi 2013-02-19 23:19:06
再次發現;)boundingBoxArea是錯誤的,請使用初始boundRect代替 – berak 2013-02-19 23:34:11