Tomazi Tomazi - 1 year ago 152
C++ Question

OpenCV Drawing Bounding Box CenterPoint

I am trying to draw a Dot in Bounding Box that will represent the Center Point of that box.
I have computed the center Point but it is only outputted in CMD and I wont this Point to be visible on a image.

I am working with OpenCV2.4.3 on Visual Studio 2010 C++

for(int i= 0; i < boundRect.size(); i++ )
//BoundingBox Area
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;

The above is the code that i use well only a small part but a part that is responsible for calculations on Bounding Boxes

Answer Source

oh, you already calculated the area, and now you're trying to assing the center(Point) to that ? oh, no. replace your last lines with:

//Bounding Box Centroid
Point center = Point((boundRect[i].x + boundRect[i].width)/2, (boundRect[i].y + boundRect[i].height)/2);

// print it:
cout<<"Rectangle " <<i<< " Centroid position is at: " << center.x << " " << center.y << endl;

also, your boundingBoxArea is wrong. take the original boundingRect[i] instead (for calculating the area), please!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download