【发布时间】:2015-02-03 17:22:48
【问题描述】:
当我运行这个应该在黑色表面上画一条线的代码时,我没有收到任何错误消息,但也没有显示任何内容。怎么了?
import numpy as np
import cv2
class DessinerLigne:
def dessinerLigne(self):
# Create a black image
self.img=np.zeros((512,512,3),np.uint8)
# Draw a diagonal blue line with thickness of 5 px
self.img=cv2.line(self.img,(0,0),(511,511),(255,0,0),5)
# If q is pressed then exit program
self.k=cv2.waitKey(0)
if self.k==ord('q'):
cv2.destroyAllWindows()
if __name__=="__main__":
DL=DessinerLigne()
DL.dessinerLigne()
【问题讨论】:
-
如何在python中显示图像?我猜在
waitKey之前缺少cv2.imshow("windowname", self.img)或类似的东西? -
以上代码仅适用于 opencv3.0,2.4 版本不会从 cv2.line() 返回图像 [对,缺少 imshow() 你什么都看不到]
-
@berak 我可以在 Python 2.7.9 中使用 OpenCV3.0 吗?
标签: python-2.7 opencv drawing line