Apply Canny Edge detection
Mat srcMat = new Mat(height, width, CvType.CV_8UC3);
Utils.bitmapToMat(sourceBitmap, srcMat);
Mat imgSource = new Mat(srcMat.size(), CvType.CV_8UC1);
Imgproc.cvtColor(srcMat, imgSource, Imgproc.COLOR_RGB2GRAY, 4);
Imgproc.GaussianBlur(imgSource, imgSource, new org.opencv.core.Size(5, 5), 5);
Imgproc.Canny(imgSource, imgSource, 50, 50);
//find the contours
List contours = new ArrayList<>();
Imgproc.findContours(imgSource, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
double maxArea = -1;
int maxAreaIdx = -1;
Log.d("size", Integer.toString(contours.size()));
MatOfPoint temp_contour = contours.get(0); //the largest is at the index 0 for starting point
MatOfPoint2f approxCurve = new MatOfPoint2f();
MatOfPoint largest_contour =