OpenCV Error in findContours()
I'm trying to find the contours of an image. Though I tried in different ways, same error (that is "Unsupported format or combination of formats ([Start] FindContours support only 8uC1 and 32sC1 images) in cvStartFindContours") is given. This is my source code. How can I fix this problem. Thank you.
public class ContourDetection {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat image = Highgui.imread("D:\\Region.bmp");
if (image.empty() == true) {
System.out.println("Error: no image found!");
} else {
List<MatOfPoint> contours = new ArrayList<>();
Mat image_2 = new Mat(image.size(), image.depth());
//image.convertTo(image_2, CvType.CV_32SC1);
Imgproc.cvtColor(image, image_2, CvType.CV_8UC1);
Imgproc.threshold(image_2, image_2, 150, 255, CV_THRESH_BINARY);
//System.out.println(image_2.channels() + " " + image_2.depth() + CvType.CV_8U+image_2.type());
findContours(image_2, contours, new Mat(), Imgproc.RETR_FLOODFILL, Imgproc.CHAIN_APPROX_SIMPLE);
// Draw all the contours such that they are filled in.
Mat contourImg = new Mat(image.size(), image.type());
for (int i = 0; i < contours.size(); i++) {
Imgproc.drawContours(contourImg, contours, i, new Scalar(255, 255, 255), -1);
}
Highgui.imwrite("D:\\debug_image.bmp", contourImg);
}
}
}