简体   繁体   中英

OpenCV findContours: make it robust

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:

在此处输入图片说明

But when I take a closer picture, then there is no closed contour, see 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!

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM