Mobile devices have improved significantly over the past years. They are now capable of running intensive CPU tasks like image processing and object detection algorithms, perform mathematic calculations and even handle a large amount of data efficiently.
In this project I’m going explain how to use the OpenCV library in your android app, and implement a real time text detection algorithm using the rear phone camera. I will use the OpenCV MSER algorithm which is used to detect points of interest inside an image.
OpenCV for Android
For installing OpenCV in your android app please refer to my previous article
MSER
MSER, Maximally Stable Extremal Regions, is an algorithm used for blob detection inside an image. MSER is based on the idea of taking regions which stay nearly the same through a wide range of thresholds. This algorithm is considered to be one of the fastest region detectors which makes it a good choice for mobile devices.
Why is it Good For Text Detection?
- MSER tends to detect many small regions
- MSER performs best (among other detectors) in light changed scene
- MSER gives good results when we scale the image (moving closer to the subject)
The Layout
I start by setting a JavaCameraView object instance inside my layout file
The Fragment
Since I use a fragment, my fragment Class implements the Camera View Listener as follows, I also bind the instance and the listener inside the OnCreateView Method
Text Detection Implementation
MSER algorithm runs on a grayscale image, so I create a grayscale image from my original image and apply the FeatureDetector.MSER in order to find all the keypoints inside the image. I loop this process on each frame that I get from the video stream and then draw a red rectangle around each key point.
Conclusion
This example can be the basic for many other projects using android text detection. On older devices I found it to be working not as smooth as I expected. OpenCV 3.0 brings us a new dedicated Algorithm Class-specific Extremal Regions used for text detection.
You can find the full source code here
Cheers