I have vector of points i drawed by my self :
std::vector<CvPoint> shape1 = paintshape(0);
Now i need to get a bounding box object (points) around this shape ,
i have searched the web for answeres but every topic is talking about recognizing the edge of some object inside whol image file and then making the bounding box.
in my case its different ,
Thanks !
Use the boundingRect() Function of OpenCV to Find Bounding Boxes Around Shapes Present in an Image. We can find and add a bounding rectangle or box around shapes present in an image using the boundingRect() function of OpenCV.
The bounding box is an imaginary rectangle drawn around a given object and it serves as the region of interest. To draw a bounding box around an object in the given image, we make use of a function called selectROI() function in OpenCV.
boundingRect() returns the 4 points of the bounding box as shown below. # The first order of the contours. c_0 = contours[0]# Get the 4 points of the bounding rectangle. x, y, w, h = cv2.boundingRect(c_0)# Draw a straight rectangle with the points.
get the boundingRect for your points:
#include "opencv2/imgproc/imgproc.hpp"
// please use stuff from the cv:: namespace, not the outdated Cv*
std::vector<cv::Point> shape1 = paintshape(0);
cv::Rect r = cv::boundingRect(shape1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With