我按照本页的教程进行操作,但cv2.drawContours(im,contours,-1,(0,255,0),3)
执行该行时似乎没有任何结果.我希望看到带有绿色轮廓的star.jpg,如教程中所示.这是我的代码:
import numpy as np
import cv2
im = cv2.imread('C:\Temp\ip\star.jpg')
print im.shape #check if the image is loaded correctly
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(im,contours,-1,(0,255,0),3)
pass
Run Code Online (Sandbox Code Playgroud)
没有错误消息.star.jpg是上述网页中的明星.我使用的是opencv 2.4.8和Python 2.7.
drawContours应该在我的屏幕上显示图像吗?如果是这样,我做错了什么?如果没有,我该如何显示图像?
谢谢
编辑:
添加以下行将显示图像:
cv2.imshow("window title", im)
cv2.waitKey()
Run Code Online (Sandbox Code Playgroud)
需要waitKey(),否则窗口将显示灰色背景.根据这篇文章,这是因为waitKey()告诉它开始处理WM_PAINT事件.
你必须做一些事情的效果:
cv2.drawContours(im,contours,-1,(255,255,0),3)
cv2.imshow("Keypoints", im)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
29636 次 |
最近记录: |