Search code examples
pythonopencvcontouredge-detectionpattern-recognition

Automatic ROI/rectangle recognition


I want to be able to pass on multiple images to python and detect the contour of the object in the picture. The pictures all represent money bills, hence the ROI is always going to be rectangular. Whatever ive tried, im not able to exactly detect the money bill.

I tried canny edge detection but the transparent regions on the money bill (canadian money)example of a canadian bill make it hard to detect the whole bill. Does anyone have any suggestions on how to automatically crop out just the money bill? Thanks in advance!


Solution

  • It is an easy matter to binarize the image, as the background is perfectly white. Use a threshold level as close as possible to white, to reduce the effect of the shadow, bottom right.

    Then after connected component labelling, the convex hull gives you a nice crop polygon.

    If you prefer a quadrilateral, you can pick the extreme vertices in the four cardinal directions.

    enter image description here