Android Core

Banana Classifier with OpenCV on Android

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.

banana

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

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)

vinotion

ViNotion Car Detection

But as I found very fast this company from Netherlands used very capable HW and proprietary SW to accomplish this feat.

detection_vinotion

HW and SW they use

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.

car2

Vehicle Classification On Highway

Once again it turned out to be this monstrous HW thing with thermal sensor, laser distance sensor you name it.

sensors_2

HW used for case above

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.

article1

PDF file

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.

roman_blog

Roman’s blog

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

whatsapp-image-2016-11-12-at-17-40-47

App with banana recognition model

whatsapp-image-2016-11-14-at-22-18-41

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.

Reference: Banana Classifier with OpenCV on Android from our JCG partner Andrei Cheremskoy at the GetToCode.com blog.

Andrei Cheremskoy

Andrei is a Java Developer interested in Deep Learning. He hopes to help developers with just-in-time advice from the programming universe. Particularly, coming from Open Source and Java worlds related to Deep Learning such as Deeplearning4j library.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
william
william
7 years ago

How you adapted the code to banana? Can you release the source code?

Andrey Cheremskuy
7 years ago
Reply to  william

The code is here.
https://github.com/AndrewCh/BananaDetection

I refactored it a little bit and swapped xml file that had face classifier for a xml for bananas.

Malik
Malik
7 years ago

What a great way to explain an idea !
thank you very much

ANDREY CHEREMSKUY
7 years ago
Reply to  Malik

Thank you. Actually now it is possible to use deep learning libraries such as Keras to achieve the same faster and easier.
https://deeplearningsandbox.com/how-to-build-an-image-recognition-system-using-keras-and-tensorflow-for-a-1000-everyday-object-559856e04699

Alexiz
Alexiz
7 years ago

What is the recreate button for?

Andrey Cheremskuy
7 years ago
Reply to  Alexiz

This button has no meaning in this application. It is a leftover from the original app I refactored.

Back to top button