cv::boundingRect
时间: 2023-10-21 08:06:12 浏览: 111
cv::boundingRect is a function in OpenCV library that calculates the minimum bounding rectangle for a set of points or a contour. This function takes a single argument, which is the input array or vector of points or contours. The output of this function is a rectangle that encloses all the points or contour vertices.
The bounding rectangle is defined by the coordinates of the top-left corner (x,y), and its width and height. This function is commonly used in computer vision tasks like object detection, tracking, and segmentation.
Example Usage:
```
// Create a vector of points
std::vector<cv::Point> points = {cv::Point(10,20), cv::Point(30,40), cv::Point(50,60)};
// Calculate the bounding rectangle
cv::Rect rect = cv::boundingRect(points);
// Print the rectangle coordinates
std::cout << "Bounding Rectangle: x=" << rect.x << ", y=" << rect.y << ", width=" << rect.width << ", height=" << rect.height << std::endl;
```
Output:
```
Bounding Rectangle: x=10, y=20, width=41, height=41
```
阅读全文