Search code examples
opencvcomputer-visiondetection

Opencv contours detected discontinue


I am detecting rectangle in an image using openCV. As in many examples, I use threshold+findContours+approxPolyDP.

As shown in image below, my problem is that the contours found by findContours don't continue, so after approxPolyDP, I can't get a rectangle...

So, do you have any idea how to solve this problem? Thank you. :)

Another question: why the contours are gray? After the thresholding, there should be only white and black, shouldn't there?

Contours

After approxPolyDP


Solution

  • C++: void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool closed)

    epsilon – Parameter specifying the approximation accuracy. This is the maximum distance between the original curve and its approximation.

    try increasing epsilon