opencv学习手稿(01开篇-显示一张图片)(原创)

使用python36

源码:

 1 #-*- coding:utf-8 -*-
 2 import cv2   
 3 from PIL import Image, ImageTk
 4 import numpy as np
 5 
 6 # img = cv2.imread("F:\\作业\\机器视觉\\2017202120089-周健康-机器视觉编程作业03\\test.jpg")
 7 # print(img)    
 8 #这里的返回值竟然是None,无法使用
 9 #会出现error:
10 '''
11 
12 <PIL.BmpImagePlugin.BmpImageFile image mode=L size=768x575 at 0x25E609C76D8>
13 OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file D:\Build\OpenCV\opencv-3.4.0\modules\highgui\src\window.cpp, line 339
14 Traceback (most recent call last):
15   File "F:\作业\机器视觉\机器视觉编程作业03\opencv学习001.py", line 25, in <module>
16     cv2.imshow("Image", img)
17 cv2.error: D:\Build\OpenCV\opencv-3.4.0\modules\highgui\src\window.cpp:339: error: (-215) size.width>0 && size.height>0 in function cv::imshow
18 
19 '''
20 
21 
22 #使用PIL的图片处理库解决问题
23 image = Image.open('F:\作业\\机器视觉\\2017202120089-周健康-机器视觉编程作业02\\test001.bmp')
24 # print(image)
25 data = np.array(image)        #
26 # print(data)
27 # d_array = [0]*256
28 
29 cv2.namedWindow("Hello Mufasa")
30 cv2.imshow("Hello Mufasa", data)
31 cv2.waitKey (0)  
32 cv2.destroyAllWindows()

显示效果:

 

链接:https://pan.baidu.com/s/1boSWaGf 密码:25ks

posted on 2017-12-25 20:13  周健康  阅读(635)  评论(0编辑  收藏  举报

导航