# How to find the external points of a square/rectangle contour?

**URL:** <https://forum.opencv.org/t/how-to-find-the-external-points-of-a-square-rectangle-contour/2512>\
**Category:** C++\
**Tags:** imgproc\
**Created:** [March 31, 2021, 2:40pm UTC](https://forum.opencv.org/t/how-to-find-the-external-points-of-a-square-rectangle-contour/2512 "2021-03-31T14:40:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamzaabd](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@hamzaabd](https://forum.opencv.org/u/hamzaabd)\
**Post date:** [March 31, 2021, 2:40pm UTC](https://forum.opencv.org/t/how-to-find-the-external-points-of-a-square-rectangle-contour/2512/1 "2021-03-31T14:40:05Z")

</div>

I have found some contours. Then by using approxPolyDP i found the contours with four conoturs. I know want to find the four points on that square and make a bounding box on those points so I can make perspective transformation on separate image. I cannot find the four points. I have tried to find max and min of contours[j][k].x to find max value and min value. I have also tried to use a bounding box but that just makes a square around the contour and I lose the edges. I hope someone can help.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 31, 2021, 2:53pm UTC](https://forum.opencv.org/t/how-to-find-the-external-points-of-a-square-rectangle-contour/2512/2 "2021-03-31T14:53:28Z")

</div>

welcome.

use a debugger. perhaps use gdb, or use visual studio. look at all the variables in your program, as it runs.

---

<div class="post-metadata">

**Author:** ![hamzaabd](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@hamzaabd](https://forum.opencv.org/u/hamzaabd)\
**Post date:** [March 31, 2021, 2:55pm UTC](https://forum.opencv.org/t/how-to-find-the-external-points-of-a-square-rectangle-contour/2512/3 "2021-03-31T14:55:26Z")

</div>

So you are telling me that looping through the contours to find the max/min points are the correct method of finding the coordinate points making up of the contours?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 31, 2021, 3:39pm UTC](https://forum.opencv.org/t/how-to-find-the-external-points-of-a-square-rectangle-contour/2512/4 "2021-03-31T15:39:45Z")

</div>

you ran approxPolyDP. how many points are in the resulting contour?

---

<div class="post-metadata">

**Author:** ![hamzaabd](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@hamzaabd](https://forum.opencv.org/u/hamzaabd)\
**Post date:** [March 31, 2021, 3:58pm UTC](https://forum.opencv.org/t/how-to-find-the-external-points-of-a-square-rectangle-contour/2512/5 "2021-03-31T15:58:44Z")

</div>

I was working within contours. I should have worked within approxpolydp vector. Thanks for the clarification.
