활연개랑

[OpenCV] findcontours 오류 [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl' 본문

Python

[OpenCV] findcontours 오류 [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'

승해tmdhey 2022. 4. 11. 13:28
반응형
_, bi_binary  = cv2.threshold(roi_1, 0, 255, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(bi_binary, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)

findcontours를 하기 위해 위 코드를 실행하는 과정에서 다음과 같은 오류가 발생하였습니다.

cv2.error: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/contours.cpp:195: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'

이 오류가 나는 이유는 여러가지가 있지만, 구글링에서 잘 나오지 않는 오류 이유는 dtype이 unit8이어야 한다는 점입니다.

findcontour를 할 때 array의 dtype이 unit8이어야 코드가 돌아가므로 일단 unit8로 맞춰두신 후에도 오류가 난다면 또 다른 구글링을 해보시기 바랍니다..