Ask Your Question
0

Unsupported format or combination of formats while contours

asked 2016-10-30 22:24:04 -0600

Karanbeer Kaur gravatar image

I am trying below code to get contours of images.

 // Load images to compare
    Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.CV_LOAD_IMAGE_COLOR);
    Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.CV_LOAD_IMAGE_COLOR);
    System.out.println(img1);

    ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(img1, contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
    Imgproc.findContours(img2, contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);

    System.out.println("contours=="+contours.size());

But getting below error:-

OpenCV Error: 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 cvStartFindContours, file /tmp/opencv3-20161019-20369-7r0q5p/modules/imgproc/src/contours.cpp, line 219
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: /tmp/opencv3-20161019-20369-7r0q5p/modules/imgproc/src/contours.cpp:219: error: (-210) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function cvStartFindContours
]
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-10-30 23:09:47 -0600

berak gravatar image

you need a binary image to use findContours(), not a color (bgr) one, use cvtColor() to get a grayscale image, then threshold() (or Sobel() or Canny() or inRange()) to achieve that.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-10-30 22:24:04 -0600

Seen: 36,123 times

Last updated: Oct 30 '16