我想在边界框中绘制一个点,表示该框的中心点。 我已经计算了中心点,但它只能在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