有人可以帮我找出代码中的问题吗,我试图在图像中找到所有轮廓,然后在其上涂灰边,但似乎只涂了一些轮廓。
'''
image_find_goal = "/absolutePathWays.img"
kernel = np.ones((5,5),np.uint8)
#findGoal(image_find_goal)
img1 = cv.imread(image_find_goal,cv.IMREAD_GRAYSCALE)
ret,mask = cv.threshold(img1, 125, 255, cv.THRESH_BINARY_INV)
contours, hierarchy = cv.findContours(mask,cv.RETR_TREE,cv.CHAIN_APPROX_NONE)
for cnt in contours:
approx = cv.approxPolyDP(cnt,0.01*cv.arcLength(cnt,True),True)
if len(approx) == 4:
cv.drawContours(mask,cnt,-1,(119,256,51),5)
mask3 = cv.resize(mask,(640,640))
cv.imshow('IMAGE', mask3)
cv.waitKey(0)
cv.destroyWindow(mask3)
'''
最佳答案
if len(approx) == 4:
至if len(approx) >= 4:
Resulting image关于python - 使用opencv查找图像中的所有轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64144150/