1

I am trying to write an android app that allows for realtime processing of camera feed from a device to detect contours. Despite following many examples online, when I run the following code, an exception is thrown (also shown below).

Code:

Bitmap image = mTextureView.getBitmap();
Mat mat = new Mat();
Mat matConverted = new Mat();
Utils.bitmapToMat(image, mat);
mat.convertTo(matConverted, CvType.CV_32SC1);
List<MatOfPoint> contours = new ArrayList<>();
Imgproc.findContours(matConverted, contours, new Mat(), Imgproc.RETR_FLOODFILL, 
    Imgproc.CHAIN_APPROX_SIMPLE);

Exception:

CvException [org.opencv.core.CvException: cv::Exception:
/Volumes/Linux/builds/master_pack-android/opencv/modules/imgproc/src/contours.cpp:198:
error: (-210) [Start]FindContours supports only CV_8UC1 images when mode !=
CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function _CvContourScanner* 
cvStartFindContours(void*, CvMemStorage*, int, int, int, CvPoint)

Am I missing something obvious here?

1
  • The error message says it all. The image supplied to findContours must be 1-channel 8-bit image. Yours is 32-bit. Commented Jan 5, 2017 at 2:19

1 Answer 1

1

Try

Mat matConverted = new Mat(mat.size(), CvType.CV_8UC1);

In my case, it worked

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.