【发布时间】:2018-03-23 20:32:37
【问题描述】:
我目前正在使用 opencv 尝试检测一组标志中每个单独停车标志周围的矩形。使用“findContours”和“approxPolyDP”让我很接近,但我想将轮廓合并成一个矩形。使用“boundingRect”不起作用,因为形状中有中断。
如果您对如何解决此问题有任何建议,请告诉我。
这是我的代码:
image = cv2.imread(sign_directory)
# find all the 'red' shapes in the image
lower = np.array([0, 0, 110])
upper = np.array([100, 100, 250])
shapeMask = cv2.inRange(image, lower, upper)
# find the contours in the mask
(img, cnts, _) = cv2.findContours(shapeMask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
x,y,w,h = cv2.boundingRect(c)
cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imshow("Image", image)
cv2.waitKey(0)
【问题讨论】:
-
您希望外部矩形是唯一绘制的?
-
是的,完全正确。我只是想为红色标志绘制外部矩形。我最终也会想要绿色标志的矩形,但我不想在这里这样做。
-
能否也附上原图?
-
@ZdaR 刚刚上传了原图。
-
opencv scene text detection 在这里有用吗?我认为这是针对野生检测中的那种文本进行训练的 (python example)
标签: python opencv image-processing computer-vision polygon