Skip to content

get_threshold enhancement #2

@davide710

Description

@davide710

get_threshold() is the function that should find the optimal value for the subsequent use of cv2.threshold(). Currently it considers the lowest section of the document (since that part is usually white), and applies cv2.threshold() with descending values from 200, stopping as soon as the threshold is low enough that 99.9% of the pixels in the section are set to white. If the brightness of the picture is sufficiently uniform, the result is pretty good, otherwise some parts of the document become unreadable or completely black.
Also, if that lowest section isn't supposed to be white, the function can't work.
If you have any ideas, please write a comment or submit a pull request, and if you would like to contribute but you don't understand some parts of the code, don't hesitate to ask.

EDIT:

Right now I'm combinig my custom function get_threshold with OpenCV's cv2.adaptiveThreshold using a cv2.bitwise_or between the two, so that if a pixel is made white by either of the functions it will be white in the result. This improves performances significantly, but there are still problems with pictures that have non-uniform illumination.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions