
使用了opencv輪廓發現和繪制去識別圖中的矩形,findContours的引數設為cv.RETR_EXTERNAL,但是依舊繪制了一些輪廓內的內容,不知道什么情況,各位大佬有什么解決的思路或者方法嗎,下面是我的代碼,是我前面的圖片處理出問題了嗎?或者各位還有什么檢測這種矩形的思路嗎?
#圖片處理
def edge_demo(image):
blurred = cv.GaussianBlur(image, (3, 3), 0) #高斯模糊
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY) #灰度處理
# xgrad = cv.Sobel(gray, cv.CV_8U, 1, 0)
# ygrad = cv.Sobel(gray, cv.CV_8U, 0, 1)
edge_output = cv.Canny(gray, 50, 150)
dst = cv.bitwise_and(image, image, mask=edge_output)
return edge_output
#繪制矩形
def contours_demo(image):
binary = edge_demo(image)
contours,_ = cv.findContours(binary,cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
for c in contours[1:]:
cv.drawContours(image,[c],0,(0,0,255),2)
cv.imshow("detect comtour", image)
cv.imwrite(r"C:\Users\SongJian\Desktop\picpro\canny2332.jpg", image)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/95003.html
標籤:OpenCV
上一篇:混合蟻群路徑規劃思路解惑
下一篇:書香
