我需要找到棕色区域的轮廓。但在此之前,我尝试绘制所有轮廓。但我看不到任何轮廓
我尝试过这个:
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)
关于python - cv2.findContours 找不到轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59572449/