Hi everyone! I'm trying to get the outermost contour of an object after detecting it using findContours, I've tried using Imgproc.RETR_EXTERNAL as the method but it still includes the contours inside it.
This is my reference photo
This is the contours that I get after applying a greyscale, threshold and canny edge. As you can see, there are still remaining contours inside the biggest circle.
And this is the output that I need to achieve
Please note that the reference image is subjected to change, as the app gives the user a shape that he will look for in the real world and capture it using the camera. That captured photo will be used then for checking if it is indeed the same as the given shape.
If I've done something wrong with my approach, please feel free to correct me. I'm hoping for a quick response, thanks!
EDIT:
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.qwe);
//Utils.matToBitmap(m, bm);
//convert to mat:
int iCannyLowerThreshold = 60, iCannyUpperThreshold = 100;
Mat m = new Mat(bm.getWidth(), bm.getHeight(), CvType.CV_8UC1);
Utils.bitmapToMat(bm, m);
Mat thr = new Mat(m.rows(),m.cols(),CvType.CV_8UC1);
Mat dst = new Mat(m.rows(), m.cols(), CvType.CV_8UC1, Scalar.all(0));
Imgproc.cvtColor(m, thr, Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(thr, thr, 100, 255, Imgproc.THRESH_BINARY);
Imgproc.Canny(thr, thr, iCannyLowerThreshold, iCannyUpperThreshold);
//Imgproc.findContours(m, contours, new Mat(), 0, 1);
Imgproc.findContours( thr, contours, new Mat(),Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0,0) );
Scalar color = new Scalar( 255,255,255);
Imgproc.drawContours(dst, contours, -1, color, 3);
//Core.rectangle(m, bounding_rect.br(), bounding_rect.tl(), new Scalar(0,255,0));
Utils.matToBitmap(dst,bm);