python - cv2.findContours 找不到轮廓

标签 python opencv image-processing contour

我需要找到棕色区域的轮廓。但在此之前,我尝试绘制所有轮廓。但我看不到任何轮廓

我尝试过这个:

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)

enter image description here

关于python - cv2.findContours 找不到轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59572449/

相关文章:

python - 如何使用 Python 将非常大的图像(tif)文件转换为数组

c++ - "MATLAB style"计算机视觉\图像处理可视化\调试工具

javascript - 用 PHP 检测白色图像背景?

Python模型继承和模型声明的顺序

python - Windows 的 Python 服务有几个问题

python - 如何根据 pandas 列注释散点图中的点

c++ - OpenCV : Training SVM Error - Assertion failed

python - 替换OpenCV中多个RGB值的所有像素

c++ - 在 Visual Studio 之外运行的程​​序的行为有所不同

python - 连接由主键链接的 2 个 JSON 输入