我正在使用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