cv2.findContours 找不到轮廓

cv2.findContours doesn't find contours

我需要找到棕色区域的轮廓。但在那之前,我试着画出所有的轮廓。但我在

上看不到任何轮廓

我试过这个:

contours, hierarchy = cv2.findContours(thresh_dummy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) 
cv2.drawContours(thresh_dummy, contours, -1, (0, 255, 0), 3) 

我认为您在输出图像中看不到轮廓的原因是因为您正在使用 (0, 255, 0) 绘制轮廓,这在灰度图像上是不可见的(thresh_dummy 恰好是灰度图像)。你可以做的是在绘制轮廓之前将 thresh_dummy 转换为 RGB,或者你可以只使用随机颜色,如 (128, 255, 128),这将在你的特定示例中可见。

contours, hierarchy = cv2.findContours(thresh_dummy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) 
thresh_color = cv2.cvtColor(thresh_dummy, cv2.COLOR_GRAY2RGB)
cv2.drawContours(thresh_color, contours, -1, (0, 255, 0), 3)
cv2.imwrite("thresh_color.jpg", thresh_color)