Fast and Accurate Document Detection for Scanning
blogs.dropbox.com
blogs.dropbox.com
Document identification like this is unfortunately the "easy" (and it's not particularly easy to do real time) part. The next two steps involve 3D de-deformation since unlike a flatbed scanner you cannot assume the paper is actually completely flat -- imagine a previously folded page, etc.
I love this stuff as it is at a crossroads of a half dozen different disciplines. Lots of money to be had if this can be done is a really robust manner.
Edit:
A couple examples of why this gets really hairy really fast:
* You'll notice that all the documents are shown on a high contrast background (dark wood grain) without a lot of stark lighting. One of your first steps in edge detection and line identification is image segmentation to remove background from foreground and then start removing noise. If you have a white piece of paper on a white table, or a large lighting contrast (say from an open window casting daylight on half the page) it really wreaks havoc with the algorithms.
* Imagine you're trying to recognize a page from a text book in the middle of the book. The way the page lies you end up with non-rectangular pages (they curve due to the spine) which kills the hough line transformation (there are also hough circle algorithms, but you get the point) and the rectangle selection.
In the contrast problem you mention there, I found (in a few samples that I tested with) that adaptive thresholding seem to be sufficiently good [0].
[0] I am using ``skimage.filters.threshold_adaptive`` for this.
On 3D deformation, you're officially in academic research land. Nearly all algorithms require you to have a solid guess as to what the aspect ratio of the target object is. Other algorithms use heuristics based upon what you expect to find on a page. One particularly fun algorithm used the baseline of text (I believe for that paper it was Arabic) and fit a high-order curve to it which was then reversed. Unfortunately I haven't seen a truly generic approach that doesn't require a implementation-specific input.
[1] Frankly my feeling is that RGB to grayscale is a mistake and holding back many of these algorithms
Agree with that 3D deformation is a difficult open problem, and we haven't gotten into that yet. Currently we assumed the document is a flat rectangle, which maps to a quadrilateral in image space. A homography is then applied to rectify it, and it seems to work quite well if the paper is slightly curved or folded.
Great work, and I look forward to seeing future posts on the solutions you've been able to come up with!
Well, I couldn't control the autofocus very well, going from a $500 DSLR to a $1200 DSLR made HUGE gains since it'd have far, far more autofocus points.
I was really interested in the text output of the OCR that I later did (which was a treat in itself since mail has so many different fonts, even on the same item!). I learned a lot about a lot of things too.
Thanks for this additional information, much appreciated!
http://docs.opencv.org/2.4/doc/tutorials/features2d/feature_...
Hope you enjoy this post, and keep tuned as we have other posts to be published in coming weeks about other part of our scanning feature.
> We decided to develop a customized computer vision algorithm that relies on a series of well-studied fundamental components, rather than the “black box” of machine learning algorithms such as DNNs.
To:
> To overcome these shortcomings, we used a modern machine learning-based algorithm. The algorithm is trained on images where humans annotate the most significant edges and object boundaries. Given this labeled dataset, a machine learning model is trained to predict the probability of each pixel in an image belonging to an object boundary.
This seems like a crucial step in the algorithm and sounds exactly like a black box DNN...
Great work. Laurent
As the sibling says, this sounds like a good random forest problem, so you just pass in a load of patches that have been labelled with ground truth and let the classifier give you a probability for each pixel?
Does anyone know which "modern machine-learning algorithm" they are referring to here? Is there something like this available in OpenCV?
EDIT: Adding more details.
If you are looking for similar ideas, you should read papers in the area of object-class segmentation / classification[0][1][2], and generic supervised learning.
[0] https://arxiv.org/abs/1510.03727
[1] https://www.microsoft.com/en-us/research/publication/object-...
[2] https://www.ais.uni-bonn.de/papers/DAGM_NC2_2011_Schulz.pdf
I tried a little while ago. Memory is kind of hazy, but depending on how well you do the image transformation (automatically[ish] skew to rectangle, etc), image quality might get poor. Then you have to do the actual OCR. Now the only complete OSS solution is Tesseract and it's not a state-of-the-art one. There's also ocrpy, but it's more of a toolkit and it's model needs to be trained (one single-line text when I last checked). So yeah, it's fairly hard to do.
I wonder if anyone from Dropbox could go into more detail about the technical aspects? This sounds like the perfect thing to build as a C/Rust/whatever embedded library so you can share it with an Android app later on, is that what happened here or is this all in Swift/Obj-C?
Yeah, Hough transform is definitely a time-tested algorithm that embodies both elegance and efficacy. I truly love that.
On the technical side, we wrote the detection library in C++, so that it can be easily ported cross-platformly. For iOS integration, we simply integrated with Obj-C++.
[0] https://blogs.dropbox.com/tech/2016/08/fast-and-accurate-doc...
If we were to use y=mx+b, then the hough transform image would look like many straight lines intercepting at a few points, which makes most intuitive sense. The issue with this form is it gets ill-formed when the line becomes near vertical (m goes to infinity).
The polar parametrization r=x·sinθ+y·cosθ solves this problem, and in the hough space, the axes will be r and θ. A point in image space maps to a sinusoid in hough space, which is why the transformed image looks like that.
[0]: http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/ho...
-- did Dropbox use Turk for this?
Further segmentation could be done by having the user "tap" to select the document.
The actual OCR and data extraction likely occurs on the server side, but the document recognition on device is a much better user experience.
[1] USAA and Mitek were suing each other over the patents from 2012-2014.