opencv學習手稿(01開篇-顯示一張圖片)
阿新 • • 發佈:2017-12-25
med 使用 fas destroy color 鏈接 all 健康 _array
使用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
opencv學習手稿(01開篇-顯示一張圖片)