1
image with rectangles掃描圖像上的Python,OpenCV和矩形
您好!掌握OpenCV,我遇到了一個問題:我找不到任何這些盒子然後切割。請告訴我,使用哪些過濾器和邏輯?
#!/usr/bin/env python
import cv2
import os
img_path = os.path.join('img', '1.jpg')
image = cv2.imread(img_path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
edged = cv2.Canny(gray, 30, 200)
cv2.imshow('gray', gray)
cv2.waitKey(0)
cv2.imshow('edged', edged)
cv2.waitKey(0)
(_, cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
if len(approx) == 4:
cv2.drawContours(image, [approx], -1, (0, 255, 0), 3)
cv2.imshow('result', image)
cv2.waitKey(0)
本示例查找大量的垃圾,和所有的矩形(未僅那些與背景)
編輯: OpenСV重複矩形輪廓。我怎樣才能切斷重複?
到目前爲止,您嘗試了什麼? – asongtoruin
我剛開始學習opencv。有一項緊迫的任務。我試圖使用canny過濾器,然後findContours – ilya
發佈您的代碼(編輯它到您的文章) - 告訴我們它出錯的地方。 – asongtoruin