boundingRect

Python

point_array1=[x1,y1]
point_array2=[x2,y2]
point_array3=[x3,y3]
point_array4=[x4,y4]
x, y, w, h = cv2.boundingRect(np.array([point_array1,point_array2,point_array3,point_array4],dtype=np.float32))

注意两点:

  1. 以点的形式来获取外接矩形以数组形式输入,并转化为numpy数组
  2. np数据类型为f32

C++

vector<cv::Point> allPoint;
allPoint.push_back(point1);
allPoint.push_back(point2);
allPoint.push_back(point3);
allPoint.push_back(point4);
cv::rect rect1 = cv::boundingRect(allPoint);

总结

boundingRect方法在Python/Cpp中几乎完全一样,只是Python数组初始化起来方便一些

你可能感兴趣的:(CV,python,numpy,c++)