Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ OpenCV get Bounding Box From Vector Of Points

Tags:

c++

opencv

I have vector of points i drawed by my self :

std::vector<CvPoint> shape1 = paintshape(0);

http://s29.postimg.org/brkfri6uv/box.jpg

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 !

like image 721
Stav Bodik Avatar asked Oct 08 '14 07:10

Stav Bodik


People also ask

How do I get bounding box in OpenCV?

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.

What is BBOX in 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.

What does boundingRect return?

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.


1 Answers

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);
like image 149
berak Avatar answered Sep 30 '22 00:09

berak