파이썬 opencv imshow 에러 error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'

InAnarchy·2023년 4월 22일
0

파이썬 에러 모음

목록 보기
2/3
post-thumbnail

1줄요약: dtype을 np.uint8로 변경할 것

import numpy as np, cv2 

image = np.full((300,500),255)

cv2.imshow('title',image)
cv2.waitKey(0)

라고 했을 때, cv2.imshow('title',image)에서

cv2.error: OpenCV(4.7.0) /Users/xperience/GHA-OCV-Python/_work/opencv-python/opencv-python/opencv/modules/highgui/src/precomp.hpp:155: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'

라는 에러 메시지가 뜬다.

공식 문서 설명

결론적으론
uint8은 그대로 표시되고
uint16은 픽셀값이 256으로 나누어져 표시되고
32,64 float인 경우 픽셀값에 255이 곱해지고
32 int의 경우 처리되지 않으므로 unsigned 8비트로 변환하라고 한다.

image = np.full((300,500),255)
print(image.dtype) #int64

위 문서에서 int64에 대한 특별한 설명은 없지만
그냥 uint8로 바꿔주자..

import numpy as np, cv2 

image = np.full((300,500),255,np.uint8)
print(image.dtype)
cv2.imshow('title',image)
cv2.waitKey(0)

으로 하니 가로 500, 세로 300의 흰 화면이 잘 나온다.

업로드중..

굿굿

profile
github blog 쓰다가 관리하기 귀찮아서 돌아왔다

0개의 댓글

Powered by GraphCDN, the GraphQL CDN