Question

How to make findContours robust to make it work even the the contour might not be closed due to noisy data and/or week edges/gradients in the image?

For the first case (not closed) I'm running into the following problem: The algorithm runs quite well when using it on a thresholded picture like this:

enter image description here

But when I take a closer picture, then there is no closed contour, see here:

enter image description here

How to make it work for this case also? I thought of maybe always drawing a horizontal line at the top and at the bottom of my picture which will then always "cross" the papernote (when the note is captured from too close) making it a full contour. But this wouldn't probably work too well when the note is a bit rotated as I would then NOT get the correct contour, do I!? Do you have any better ideas? Thanks a lot in advance!

Was it helpful?

Solution

This is a simple solution which might just work.

If you know which contour points are the openings to the gap (pseudo-code ahead):

Point pointGAP1;
Point pointGAP2;

if (pointGAP1.coordinate == iamgeBorder || pointGAP2.coordinate == iamgeBorder) {
    // add line from pointGAP1 to pointGAP2
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top