Python中的cv::Rect功能?

Python中的cv::Rect功能?,python,opencv,computer-vision,Python,Opencv,Computer Vision,OpenCV的Python接口似乎没有为cv::Rect提供相应的类。它的功能是否以python中某些函数的形式移植 我尝试了C++中的下面代码,在Python中也尝试过,并得到一些错误: border2=5 cv::矩形(边框、边框、image.cols-border2、image.rows-border2) 但当我尝试python代码时,如下所示 rect=cv2.rectangle(边框,边框,img.shape[1]-border2,img.shape[0]-border2) 错误:re

OpenCV的Python接口似乎没有为
cv::Rect
提供相应的类。它的功能是否以python中某些函数的形式移植

我尝试了C++中的下面代码,在Python中也尝试过,并得到一些错误:

border2=5
cv::矩形(边框、边框、image.cols-border2、image.rows-border2)

但当我尝试python代码时,如下所示

rect=cv2.rectangle(边框,边框,img.shape[1]-border2,img.shape[0]-border2)


错误
rect=cv2.rectangle(边框、边框、img.shape[1]-border2、img.shape[0]-border2)

您应该执行以下操作:

cv2.rectangle(img, (border, border), (img.shape[1]-border2,img.shape[0]-border2), color, thickness = 1)

cv2.rectangle
,类似于
cv::rectangle
,是在
mat
上绘制矩形的函数。尝试
cv2.rectangle(边框、边框、img.shape[1]-border2、img.shape[0]-border2)
而不是将其分配给变量。我不认为cv::Rect或cv::Rect是在Python中实现的,因为最好使用切片。您可以尝试
img[border:img.shape[1]-border2,border:img.shape[0]-border2]
。你怎么认为?