Find only internal contours in JavaCV/OpenCV
I am having a struggle with finding out only internal contours of the provided image. Finding an external contour is easy, however I have no clue how to find internal contours with JavaCV as documentation lacks.
My code so far is:
for (Mat mat : mats) {
Mat newMat = mat.clone();
opencv_imgproc.Canny(mat, newMat, 50.0, 100.0);
opencv_imgproc.blur(newMat, newMat, new Size(2, 2));
opencv_core.MatVector contours = new opencv_core.MatVector();
opencv_core.Mat hierarchy = new opencv_core.Mat();
//Mat hierarchy = new Mat(new double[]{255, 255, 255, 0});
opencv_imgproc.findContours(newMat, contours, hierarchy, opencv_imgproc.CV_RETR_TREE, opencv_imgproc.CHAIN_APPROX_SIMPLE, new opencv_core.Point(0, 0));
List<opencv_core.Rect> rectangles = new ArrayList<>();
for (Mat matContour : contours.get()) {
//clueless how to find internal contours here
}
it's also a different wrapper from opencv, different api, and not supported here
It's not a problem, if someone knows solution for opencv it would be fine too. It would be easily converted to javacv, as it is, I am clueless how to achieve this scenario, so I would be grateful if anyone shows the way out. @berak
One way out would be to strip first contour in contours.get(), but I am looking for more clearer approach.