Update: BananaRecognition source code at GitHub
Make Banana Recognition Great Again
This post is about going from an idea to its implementation. The idea was to create an application for mobile phone that can detects cars. Now let’s see how it started and where I stand today. I’ll provide a brief description of the steps taken to this very day.
Step 1. Google is Your Friend or Search and You’ll Find It
The journey to banana Haar Feature-based Cascade Classifier started from searching for videos, articles and blogs on how to make object detection and tracking with a mobile phone. In particular Android platform was of interest to me since I participated in development of a few android applications beforehand. Below follow various kinds of resources that were found and how they provided me with a direction for further search.
Going in a wrong direction
First search results were actually disappointing. There were a bunch of recognition APIs and recognition products for static object recognition and classification of video for captions generation. To name a few
- Image Recognition on Android with Google Cloud Vision API
Those are good for static images but I was looking for something else i.e. dynamic treatment.
YouTube provides hope for feasibility
Looking for a possible implementation for my idea I started to search further with a little help from Google and found a number of items on youtube and in blogs that were encouraging.
Advanced object detection take one
The video below appeared to be exactly what I imagined in my mind. It is ViNotion object detection from moving vehicle (car detection)
But as I found very fast this company from Netherlands used very capable HW and proprietary SW to accomplish this feat.
So I needed to find something else.
Advanced object detection take two
Next thing I found was this system that was able not only to recognise moving cars but also was able to classify them and provide their speed.
Once again it turned out to be this monstrous HW thing with thermal sensor, laser range finder you name it.
The power of academic research
The search continued and bingo! This was it. What I’ve found was an article with exactly what I wanted. Android phone detecting and tracking cars on the road.
In short they used Android phone powered by Haar-like Feature Detector with additional filters and were able to detect and track cars from the back. But the key elements I learned from this article were
- It is possible and was done with mobile phone
- Haar-like Feature Detector with AdaBoost algorithm is a candidate for usage
Step 2. OpenCV and Roman Hošek to the Rescue
It was only a small step to type in Google Search OpenCV on Android to find about the power of Open Source Computer Vision library known as OpenCV to get even closer to my goal. Looking into OpenCV tutorials I understood that it would take me much more time than I wanted to invest to understand how to set it up on Android and how to start development fast. So I continued searching and found a detailed two parts blog post of Roman Hošek describing exactly how to implement Android application for face recognition using OpenCV library.
Not only he described how to implement this application he also provided a link to his GitHub repository with a working Android application that easily may be imported and build and run in Android Studio.
Step 3. Download. Build. Find Banana Model
I played with Roman’s application and was able to understand exactly what I needed to do to swap face classifier model to another model. Be it bananas or whatever. Bananas are more easy to classify for the newbies. Looking for bananas classifiers was also not so hard. Moreover there are a bunch of blogs in the wild providing a wealth of information on how to scientifically classify bananas and other fruits with Node.js.
Train your own Cascade Classifier
As I found Cascade classifier algorithm is pretty universal in the sense that it can recognise not only faces but other objects as you wish. But it means there is a need for custom training.
It happened that Thorsten Ball provided a GitHub repository that described how to train a custom classifier on… bananas. What was so special about this repository was the file banana_classifier.xml which was the last element in solving the puzzle of bananas, sorry car’s recognition.
Know How To Place A Right File Into A Right Place
Having Roman’s app for face recognition and a model for banana recognition in my hands I was able to tweak the Roman’s app to bananas recognition. The comparison of before/ after functionality is provided below.
App with face recognition model
App with banana recognition model
Step 4. Find a car model or train one yourself. Get rid of bananas
Next step is to train or find a car model and voila the idea is 100% implemented as envisioned.
One thought on “Banana Classifier with OpenCV on Android”