Number of result of findContours strangely vary

Hello :wave: opencv community, I hope you all doing well.

I have a pretty strange behaviour using the 4.5.5 version on Android, let me explain.

My goal is to create a document scanner, therefor I am doing :

Mat src = Imgcodecs.imread(uri);
Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2GRAY, DST_CN);
Imgproc.GaussianBlur(dst, dst, BLUR_SIZE, BLUR_SIGMA_X);
Imgproc.Canny(dst, dstCanned, MIN_THRESH, MAX_THRESH);
ArrayList<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(dstCanned, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
logger.info(contours.size()); // 4319

But if I do this

String uri = "myUri";
String dstUri = "myDstUri";
Mat src = Imgcodecs.imread(uri);
Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2GRAY, DST_CN);
Imgproc.GaussianBlur(dst, dst, BLUR_SIZE, BLUR_SIGMA_X);
Imgproc.Canny(dst, dstCanned, MIN_THRESH, MAX_THRESH);

// save canny
Imgcodecs.imwrite(dstUri, dstCanned);
dstCanned.release();
dstCanned = Imgcodecs.imread(dstUri, CvType.CV_8UC1);

ArrayList<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(dstCanned, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
logger.info(contours.size()); // 74421

Of course it’s the same image. It’s pretty strange, I must save the canny image before the findContour to have a better detection. I implemented this algo in c++ and objective-c and everything goes well :thinking:

And btw in ios for the same image it take .600s to process and in android 6s :thinking:

Any advise will be very appreciated, thank’s to everyone for your time :pray:

:wave: Hello everyone, little up on this pls :pray: :pray: :pray: :pray: