使用python36
源码:
#-*- coding:utf-8 -*-
import cv2
from PIL import Image, ImageTk
import numpy as np # img = cv2.imread("F:\\作业\\机器视觉\\2017202120089-周健康-机器视觉编程作业03\\test.jpg")
# print(img)
#这里的返回值竟然是None,无法使用
#会出现error:
''' <PIL.BmpImagePlugin.BmpImageFile image mode=L size=768x575 at 0x25E609C76D8>
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
Traceback (most recent call last):
File "F:\作业\机器视觉\机器视觉编程作业03\opencv学习001.py", line 25, in <module>
cv2.imshow("Image", img)
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 ''' #使用PIL的图片处理库解决问题
image = Image.open('F:\作业\\机器视觉\\2017202120089-周健康-机器视觉编程作业02\\test001.bmp')
# print(image)
data = np.array(image) #
# print(data)
# d_array = [0]*256 cv2.namedWindow("Hello Mufasa")
cv2.imshow("Hello Mufasa", data)
cv2.waitKey (0)
cv2.destroyAllWindows()
显示效果:
链接:https://pan.baidu.com/s/1boSWaGf 密码:25ks