안드로이드 OpenCV의 findContours 사용중 다음과 같은 오류가 발생했을 때 해결하는 방법입니다.

오류 :

Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.3) /build/3_4_pack-android/opencv/modules/imgproc/src/contours.cpp:199: 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 '_CvContourScanner* cvStartFindContours_Impl(void*, CvMemStorage*, int, int, int, CvPoint, int)'


오류가 나는 이유는 findContours의 입력 값과 출력 값의 데이터 옵션 값이 다르기 때문입니다.


해결 방법 : 

Imgproc.findContours를 호출하기 전

기존의 Mat result 객체를 다음과 같이 처리해줍니다.

Imgproc.cvtColor(src, result, Imgproc.COLOR_BGR2GRAY, 1);


오류해결!


* 참고

문자인식 중 findContours가 이진화(threshold) 된 이미지의 개체들의 blob을 찾지 못할 때 : 이진화 된 이미지의 픽셀 값(색상)을 모두 반전 시켜줍니다.

코드 : 

for(int x=0; x<roi.getWidth(); x++) {

    for(int y=0; y<roi.getHeight(); y++) {

        if(roi.getPixel(x, y) == -1) {

            roi.setPixel(x, y, 0);

        }

        else {

            roi.setPixel(x, y, -1);

        }

    }

}





정보가 유익하셨다면 아래 공감버튼 눌러주시면 감사하겠습니다.

질문사항은 댓글로 달아주시면 성의껏 답변해드리겠습니다.



to Top