Traceback (most recent call last): File "D:/Python/測試專用文件夾/opencv測試.py", line 17, in <module> cv2.imshow('saf', img) cv2.error: OpenCV(4.1.0) C:/projects/opencv-python/opencv/modules/highgui/src/precomp.hpp:131: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'
import cv2 import numpy as np from scipy import ndimage import time l=10 a=[] for i in range(10): a.append([250, 10, 50]) b=[] for i in range(10): b.append(a) print(b) img = np.array(b) img *= 250 cv2.imshow('saf', img) cv2.waitKey(0)
cv2.error: OpenCV(4.1.0) C:/projects/opencv-python/opencv/modules/highgui/src/precomp.hpp:131: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'python
次像素的數據格式有要求,能夠指定dtype=np.uint8或者dtype=np.float32app
import cv2 import numpy as np l = 10 a = [] for i in range(500): a.append([120, 10, 50]) b = [] for i in range(500): b.append(a) print(b) img = np.array(b, dtype=np.uint8) cv2.imshow('saf', img) cv2.waitKey(0)