본문 바로가기
프로그래밍/오류

[python opencv] Src_depth! = CV_32S in function 'convertToShow' 오류 해결방법

by 조이써니 2021. 6. 27.
반응형

오류 내용

OpenCV(4.5.2) C:/Users/runneradmin/AppData/Local/Temp/pip-req-build-t9hleyt8/opencv/modules/highgui/src/precomp.hpp:140: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'

 

 

오류 코드

import cv2
import pandas as pd
import numpy as np

data = pd.read_csv('test.csv') # data shape = (1, 150528)
img = data.to_numpy().reshape(224,224,3)

cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

 

발생 원인

opencv에서 이미지를 띄우기 위해서는 uint8 데이터 타입이 필요하다. numpy array를 uint8 데이터 타입으로 변환시켜주면 된다.

 

해결 방법

import cv2
import pandas as pd
import numpy as np

data = pd.read_csv('test.csv') # data shape = (1, 150528)
# data2 = np.loadtxt('test.csv', dtype=np.uint8, delimiter=",") // np.loadtxt를 사용해도 된다
img = data.to_numpy().reshape(224,224,3)
img = np.array(img, dtype=np.uint8) # 여기서 변환

cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
반응형

댓글