我正在研究在 opencv python 中查找和绘制轮廓的示例。但是当我运行代码时,我只看到一个没有绘制轮廓的深色窗口。我不知道我哪里错了。代码是:
import numpy as np
import cv2
im = cv2.imread('test.png')
imgray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
img=cv2.drawContours(image,contours,0,(0,255,0),3)
cv2.imshow('draw contours',img)
cv2.waitKey(0)
test.png
只是黑色背景中的白色矩形。
任何帮助,将不胜感激。
编辑:我正在使用 Opencv 3.0.0 和 Python 2.7