Ask Your Question
0

OpenCV Drawing Bounding Box CenterPoint

asked 2013-02-19 16:46:10 -0500

Tomazi gravatar image

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.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;
     }

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-02-19 16:57:05 -0500

SR gravatar image

updated 2013-02-19 16:57:35 -0500

Use cv::circle() to draw a point onto an image. Simply set the radius to 3 and thickness to -1 to ge a filled dot at the specified coordinate.

There is no function drawPoint() or similar as a point itself has no size. If you want to change the color of a single pixel you could simply set the pixel in your image by accessing the corresponding row/column in your cv::Mat object.

edit flag offensive delete link more

Comments

Yes i used this evenly but before i found few issues with the code i provided

Tomazi gravatar imageTomazi ( 2013-02-19 18:05:13 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-02-19 16:46:10 -0500

Seen: 2,554 times

Last updated: Feb 19 '13