Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force approxPolyDP() to return only the best 4 corners? - Opencv 2.4.2

well the question says it all

I have some contour and I want to get the best quadrangular out of it

like image 943
Zaher Joukhadar Avatar asked Jan 16 '23 06:01

Zaher Joukhadar


1 Answers

I had a problem with cards with rounded corners where even if I got approxPolyDP() to return only 4 points/edges it was never the best because the "corners" were frequently picked to be closer to these rounded edges. My solution involved increasing the number of points returned to follow the corners and then my problem allowed me to relatively safely assume that the four longest edges found represented the sides. Take these four longest edges in order and find where each pair intersects and you have the points of the quad.

As a bonus you already have the lengths so you can feed the points to your perspective transform in the right order so it doesn't get squashed and stretched the wrong way.

like image 134
Tekgno Avatar answered Jan 31 '23 02:01

Tekgno