brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.18k stars 268 forks source link

Finding contour #111

Closed yathit closed 4 years ago

yathit commented 5 years ago

For business card scanner application, I would like to find quadrilateral contour of the scanned image. Following Scanning Documents from Photos Using OpenCV, the following steps are required.

Resize and convert to grayscale

img = cv2.cvtColor(resize(image), cv2.COLOR_BGR2GRAY)

Bilateral filter preserv edges

img = cv2.bilateralFilter(img, 9, 75, 75)

Create black and white image based on adaptive threshold

img = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 115, 4)    

Median filter clears small details

img = cv2.medianBlur(img, 11)

Add black border in case that page is touching an image border

img = cv2.copyMakeBorder(img, 5, 5, 5, 5, cv2.BORDER_CONSTANT, value=[0, 0, 0])
brendan-duncan commented 5 years ago

I'm happy to take pull requests for desired features, but I don't have a lot of bandwidth to implement these.

yathit commented 5 years ago

Sure. There are quite a lot of steps in that canonical approach.

Since business card recognition is pretty simple, I am thinking to use simpler optimization process, or even tensorflow lit, since already available in Flutter.

If the image is equally divided into four pieces, all these four pieces are pretty similar and just need to find the corner. I guess Tensorflow's object detection can find the corner object.

brendan-duncan commented 5 years ago

One thing you should take into account before you get too far down this road: this Image library has been performing excruciatingly slow on mobile devices with Flutter, taking several minutes to decode an image in some cases. It's an ongoing issue that I have no idea how to resolve on my side.