src_depth != CV_32S in function 'convertToShow'

Traceback (most recent call last):
  File "D:/Python/测试专用文件夹/opencv测试.py", line 17, in 
    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'

错误原因

次像素的数据格式有要求,可以指定dtype=np.uint8或者dtype=np.float32

完整代码

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)

src_depth != CV_32S in function 'convertToShow'_第1张图片

你可能感兴趣的:(opencv2,python)