OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 02 Apr 2020 12:02:21 -0500Is the output of approxPolyDP(c) a subset of the input contour c?http://answers.opencv.org/question/228419/is-the-output-of-approxpolydpc-a-subset-of-the-input-contour-c/I'm determining corner points using an approximated version of contour **c**, then try to find the index of the found corner in the original contour using **numpy.where()**.
But for some points no index can be found, meaning the point seems not to be in the original contour.
As I understand the underlying DP-algorithm, no new points are added, is that correct?
Cheers!Thu, 02 Apr 2020 10:57:38 -0500http://answers.opencv.org/question/228419/is-the-output-of-approxpolydpc-a-subset-of-the-input-contour-c/Answer by crackwitz for <p>I'm determining corner points using an approximated version of contour <strong>c</strong>, then try to find the index of the found corner in the original contour using <strong>numpy.where()</strong>.
But for some points no index can be found, meaning the point seems not to be in the original contour.</p>
<p>As I understand the underlying DP-algorithm, no new points are added, is that correct?</p>
<p>Cheers!</p>
http://answers.opencv.org/question/228419/is-the-output-of-approxpolydpc-a-subset-of-the-input-contour-c/?answer=228421#post-id-228421yes. approxPolyDP only removes points.
a consequence of this is that, if you have a rectangle with rounded/imperfect corners, you can't "recover" the true corners. whatever points remain after approxPolyDP will be points on the rounded corner.
a severe example with epsilon=5 and epsilon=10:
![image description](/upfiles/15858471291631657.png)
![image description](/upfiles/1585847140940739.png)
![image description](/upfiles/15858471481515875.png)Thu, 02 Apr 2020 11:53:56 -0500http://answers.opencv.org/question/228419/is-the-output-of-approxpolydpc-a-subset-of-the-input-contour-c/?answer=228421#post-id-228421Comment by TheCakeLover for <p>yes. approxPolyDP only removes points.</p>
<p>a consequence of this is that, if you have a rectangle with rounded/imperfect corners, you can't "recover" the true corners. whatever points remain after approxPolyDP will be points on the rounded corner.</p>
<p>a severe example with epsilon=5 and epsilon=10:</p>
<p><img alt="image description" src="/upfiles/15858471291631657.png">
<img alt="image description" src="/upfiles/1585847140940739.png">
<img alt="image description" src="/upfiles/15858471481515875.png"></p>
http://answers.opencv.org/question/228419/is-the-output-of-approxpolydpc-a-subset-of-the-input-contour-c/?comment=228422#post-id-228422Thank you very much! May I follow up with a slightly unrelated question? As I have feared, my code has to be wrong at some other point...how would you recommend to get the index of a determined point in the original contour?
EDIT: found a solution to the problem :)Thu, 02 Apr 2020 12:02:21 -0500http://answers.opencv.org/question/228419/is-the-output-of-approxpolydpc-a-subset-of-the-input-contour-c/?comment=228422#post-id-228422