【发布时间】:2020-05-08 16:51:36
【问题描述】:
cv2.rectangle 有两种调用方式:
- img = cv.rectangle(img, pt1, pt2, color[,粗细[, lineType[, shift]]])
- img = cv.rectangle(img, rec, color[,粗细[, lineType[, shift]]]
来源:https://docs.opencv.org/4.1.2/d6/d6e/group__imgproc__draw.html#ga07d2f74cadcf8e305e810ce8eed13bc9
我将矩形称为如下:
cv2.rectangle(img=cv2_im, pt1=a, pt2=b, 颜色=(0, 255, 0), 厚度=3,线型=cv2.LINE_AA)
错误信息:
cv2.rectangle(img=cv2_im, pt1=a, pt2=b, color=(0, 255, 0), 粗细=3, lineType=cv2.LINE_AA) TypeError: rectangle() 缺少必需的参数 'rec' (pos 2)
我不明白为什么应用程序会尝试调用方法的重载版本。 U 明确定义版本 1 调用。 我尝试用 (x,y) 等更改变量 a ,但它不起作用。正确的方法调用仅在第一次我调用 retangle() 之后它希望我使用它的重载版本。
- Python 3.7.5 64 位
- 枕头 7.0.0
- numpy 1.18.1
-
opencv-contrib-python 4.1.2.30
imgname='fly_1.jpg' im = Image.open(imgname) cv2_im = np.array(im) #x,y,w,h aus Image Labeler box= [505.54, 398.334, 1334.43, 2513.223] x,y,w,h = box a = (x, y) b = (x+w, y+h) #First rectanglecall cv2.rectangle(img=cv2_im, pt1=a, pt2=b, color=(0, 255, 0), thickness=3, lineType=cv2.LINE_AA) #calls two cv2 methods which shouldn't influence rectangle rects = getRegionProposals(im,'f',normalized=True) for i,rect in enumerate(rects): x, x_max, y, y_max = rect a = (x*width,y*height) b = (x_max*width, y_max*height) if (IoU is not False and IoU > 0.5): #second and further calls cv2.rectangle(img=cv2_im, pt1=a, pt2=b, color=(0, 255, 0), thickness=3, lineType=cv2.LINE_AA)
在第二次调用之间,我使用了 cv2 选择性搜索并设置了以下内容: cv2.setUseOptimized(True) cv2.setNumThreads(4)
希望你们看到我做错了什么。
【问题讨论】:
标签: python opencv overloading rectangles