我正在使用Python 2.7和OpenCV 3.0。我正在做一个项目到检测车牌。Opencv在Python中检测四边形
我现在检查轮廓的顶点数。如果有4个顶点(大约元素数),那么它更可能是一个矩形/平行四边形/四边形。
(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts=sorted(cnts, key = cv2.contourArea, reverse = True)[:10]
# loop over our contours
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
if len(approx) == 4 and ratio(approx):
cv2.drawContours(image, [approx], -1, (0,255,0), 3)
而我有两个四边形与数组。
但是,你可以看到,有一个不规则多边形。这是数组:
[[[209 198]]
[[466 94]]
[[259 153]]
[[247 1]]]
对我怎么能省略了不规则四边形我问。谢谢
从我的头顶开始:计算[Convex hull](http://docs.opencv.org/3.1.0/d3/dc0/group__imgproc__shape.html#ga014b28e56cb8854c0de4a211cb2be656&gsc.tab=0)并比较原始多边形到它的凸包。如果它们不相似,那可能不是车牌。 – user1337