为什么我的轮廓绘制函数绘制不出来啊,结果就是原图。
import cv2
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
def cv_show(img,name):
cv2.imshow(name,img)
cv2.waitKey()
cv2.destroyAllWindows()
img=cv2.imread('60.233_50.054.bmp')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,230,255,cv2.THRESH_BINARY)
cv2.namedWindow('thresh',cv2.WINDOW_NORMAL)
cv_show(thresh,'thresh')
contours,hierarchy= cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
draw_img=thresh.copy()
res = cv2.drawContours(thresh,contours,-1,(0,0,255),3)
cv2.namedWindow('res',cv2.WINDOW_NORMAL)
cv_show(res,'res')
你是想绘制这个图案的轮廓对吗
你的thresh是单通道的,原本就是绘制了,但是你黑白图像看不出来而已,如果仔细观察的话是可以看出来差距的,毕竟你的轮廓宽度为3个像素。你如果要绘制彩色图,应该在cv2.drawContours(thresh,contours,-1,(0,0,255),3)这里将thresh改成img,在三通道上面绘制就会出现红色轮廓了
res = cv2.drawContours(img,contours,-1,(0,0,255),3)