1

I use OpenCV 2.4.0 on Android and try to find contours in a binary imgage.

List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat mIntermediateMat = new Mat();
Imgproc.Canny(img, mIntermediateMat, 50, 100);
Imgproc.findContours(mIntermediateMat, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

But the function throws a "Unrecognized or unsupported array type in function CvMat..." exception.

Also i try this Mat as input:

Mat mIntermediateMat = new Mat(height, width, CvType.CV_8UC1, new Scalar(0));

But i get the same exception.

1
  • I think i found the problem. The size of the input Mat ist to large. Commented Sep 20, 2012 at 15:08

2 Answers 2

1

Try this function to find contours :

public static ArrayList<Rect> detection_contours(Mat outmat) {
    Mat v = new Mat();
    Mat vv = outmat.clone();
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(vv, contours, v, Imgproc.RETR_LIST,
            Imgproc.CHAIN_APPROX_SIMPLE);

    double maxArea = 100;
    int maxAreaIdx = -1;
    Rect r = null;
    ArrayList<Rect> rect_array = new ArrayList<Rect>();

    for (int idx = 0; idx < contours.size(); idx++) {
        Mat contour = contours.get(idx);
        double contourarea = Imgproc.contourArea(contour);
        if (contourarea > maxArea) {
            // maxArea = contourarea;
            maxAreaIdx = idx;
            r = Imgproc.boundingRect(contours.get(maxAreaIdx));
            rect_array.add(r);
          //  Imgproc.drawContours(imag, contours, maxAreaIdx, new Scalar(0,0, 255));
        }

    }

    v.release();

    return rect_array;

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

Comments

0

Make sure that after the Canny() call, your mIntermediateMat is of type CvType.CV_8*

3 Comments

But the Mat mIntermediateMat = new Mat(height, width, CvType.CV_8UC1, new Scalar(0)); should work?
It should if it is after canny. Please post the complete error message if you still have problems.
After the Canny the image type is CV_8UC1. And Mat mIntermediateMat = new Mat(height, width, CvType.CV_8UC1, new Scalar(0)); replaced the canny. The complete error message is: "CvException [org.opencv.core.CvException: ../modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function CvMat* cvGetMat(const CvArr*, CvMat*, int*, int)"

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.