我正在尝试在边界框中绘制一个点,它将代表该框的中心点。我已经计算了中心点,但它只在 CMD 中输出,我不会在图像上看到这个点。
我在 Visual Studio 2010 C++ 上使用 OpenCV2.4.3
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;
}
以上是我很好用的代码,只有一小部分,但有一部分负责边界框的计算