Python中的cv::Rect功能?
OpenCV的Python接口似乎没有为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
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]
。你怎么认为?