# Number of result of findContours strangely vary

**URL:** <https://forum.opencv.org/t/number-of-result-of-findcontours-strangely-vary/8570>\
**Category:** Android/Java\
**Tags:** imgproc\
**Created:** [April 28, 2022, 8:55am UTC](https://forum.opencv.org/t/number-of-result-of-findcontours-strangely-vary/8570 "2022-04-28T08:55:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmonnera](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@cmonnera](https://forum.opencv.org/u/cmonnera)\
**Post date:** [April 28, 2022, 8:55am UTC](https://forum.opencv.org/t/number-of-result-of-findcontours-strangely-vary/8570/1 "2022-04-28T08:55:50Z")

</div>

Hello 👋 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 :

```java
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

```java
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 🤔

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

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

---

<div class="post-metadata">

**Author:** ![cmonnera](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@cmonnera](https://forum.opencv.org/u/cmonnera)\
**Post date:** [May 4, 2022, 1:31pm UTC](https://forum.opencv.org/t/number-of-result-of-findcontours-strangely-vary/8570/2 "2022-05-04T13:31:51Z")

</div>

👋 Hello everyone, little up on this pls 🙏 🙏 🙏 🙏
