我需要找到棕色区域的轮廓。但前提是我尝试绘制所有轮廓。但我看不到任何轮廓
我尝试过:
contours, hierarchy = cv2.findContours(thresh_dummy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(thresh_dummy, contours, -1, (0, 255, 0), 3)
答案 0 :(得分:2)
我认为在输出图像中看不到轮廓的原因是因为您正在使用(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)