我试图在这张图片上画一个不同颜色的轮廓(https://docs.opencv.org/3.4.0/d4/d73/tutorial_py_contours_begin.html),但是轮廓总是白色的。下面是代码
import cv2
import numpy as np
img = cv2.imread(r'C:\Users\Ron Shporer\Desktop\TESTSAVES\TESTLines.png',0)
ret,thresh = cv2.threshold(img,127,255,0)
im2,contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
cv2.drawContours(img, contours, -1, (255,0,0), 5)
cv2.namedWindow('img', cv2.WINDOW_NORMAL)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()`
下图:
试试这个
解决办法很简单。您可以将输入图像转换为三通道图像,然后在转换后的彩色图像上绘制轮廓。在
代码应该是这样的:
相关问题 更多 >
编程相关推荐