card.io-iOS-source icon indicating copy to clipboard operation
card.io-iOS-source copied to clipboard

Edge detection struggles on non-credit cards objects when preset resolution is higher than 640x480

Open irvingruan opened this issue 10 years ago • 6 comments
trafficstars

I am attempting to repurpose card.io to be able to perform some basic edge and corner detection on paper documents. By setting detectionMode to CardIODetectionModeCardImageOnly, I'm able to successfully capture the edges and corners of paper documents by yoking the UIImage out from the CardIOCreditCardInfo object.

That being said, the output quality is low, and I gather from @dgoldman-ebay's comment https://github.com/card-io/card.io-iOS-source/issues/16#issuecomment-77111035 that this is expected. I upped the resolution to AVCaptureSessionPreset1920x1080 and it fails to detect the borders and edges of paper documents in the green enclosure.

Is this due to the nature of the edge detection pipeline? How feasible is it to implement scanning paper documents at high preset resolutions without losing its border/edge detection prowess that's available at lower preset resolutions?

irvingruan avatar Jun 18 '15 20:06 irvingruan

I haven't thought hard about this in a long time. That said, I strongly suspect that what is going on is that there are a bunch of magic constants in the edge and line detection code that are tuned for the number of pixels found in 640x480 images. There was a lot of fine-tuning that went into getting the existing system to be highly responsive. The relevant numbers were determined experimentally, not mathematically, so if my suspicion is correct, the next step here would be to run similar experiments using higher resolution. If you're interested in tackling this, off the top of my head, I'd say the numbers to investigate are mainly the various canny and hough thresholds.

josharian avatar Jun 18 '15 20:06 josharian

I worked on higher resolutions at one point, and IIRC these days we can indeed detect a card-shaped rectangle at any camera resolution.

You can increase the camera resolution inside CardIOVideoStream.mm - there's commented-out code in there about this.

However, eventually you'll probably run into preset expectations about the width/height ratio of the desired rectangle, as @josharian indicates. If your paper documents have a predictable shape, you might be able to adjust those expectations accordingly. Or remove them, perhaps.

dgoldman-pdx avatar Jun 18 '15 21:06 dgoldman-pdx

@irvingruan, did you find a possible solution for this ? I am running into similar issues with card scanning of non-payment cards. Any help is appreciated.

biksappdev avatar Jul 27 '15 20:07 biksappdev

@biksappdev: I did, but it was in another SDK that I found. Given the complexity of modifying card.io's library for arbitrary polygons, I decided to not use it.

FWIW, the wonderful folks at Scanbot (https://scanbot.io/) have a packaged SDK that does precisely what I originally wanted. It's closed source and costs money, though.

irvingruan avatar Jul 27 '15 20:07 irvingruan

@irvingruan , thanks a lot for the reply. I dropped a mail to you regarding some queries, could you please respond when you have appropriate time for it, Thanks.

biksappdev avatar Jul 27 '15 21:07 biksappdev

Hi all I'm trying to reuse this source code to scan and crop another card type (warranty card). I'm trying to increase camera resolution for better result. But i got stuck on it. So could you please help me to increase camera resolution to higher! Or please told me what have i do to change it. thanks you very much :)

I tried to change camera preset to 1280.720 (ratio to 16/9) and increase card size 1.5 time for each size. So i got this crash:

http://imageshack.com/a/img921/2770/jwOEe0.png

truongluu10ha7 avatar Mar 14 '17 03:03 truongluu10ha7