Collector Edition

In the world of computer vision often we come across the need to recognize an object, therefor libraries like opencv comes with a set of already trained files to handle many of the face recognition methods, if you’ll browse through your opencv data directory, you’ll see some of cascade files I’m talking about,  for example the ‘haarcascade_frontalface_alt_tree.xml’ is a CascadeClassifier xml file to handle face detection, if you’ll look inside the file you’ll see that it contain nodes like the following:

what the tree items in a cascade classifier file represent is the result of an images training, one that could be applied to any object (not just faces) or specific type of faces, for example you may want to build a classifier file to find a bottle of water in a picture or to recognize if there is a cat, just like I wanted to add to my custom cat feeder, so it would open only when my cat is around

in order to do that you’ll need to train a classifier with a set of images to know which one contain your object and which one doesn’t. one of the main challenges of the training process it to get relevant images to portray your object, there are two main common ways to handle that.

  1. 1. Take a few videos of your object in different lights and angles and sample the images from the video
  2. 2. Build a photo library of your object and use it for training.

I find the first approach to work great when you want to address a specific object, for example in the cat dish I show above I only needed to sample a few videos of the cat around his feeding area during the day and night, since this is where the dish will be positioned and the light will be more or less similar to what the video shows.

The issue with the first approach is that sometimes you may not have access to the object you want to detect, or you’ll like to have much more of a variety of that same object, like in the example of recognizing a cat in a picture, you may want to have it recognize many different types of cats. 

Build your own image scraper

as I learn more about computer vision and want to play around with training – detecting different objects, I found that this became somewhat of an issue,  so I decided to give the google custom search api a try in order to address it. and I must say that I am quite happy with the results, you get a 100 free calls a day, each that will return 10 images, so you get a 1,00 free images per day, lets say you need 2,000 – 3,000 images for a good training it may take 3 days, or you can pay extra $5 and get it within the same hour which is fair enough.

here is a simple python script which will handle the build of the collector edition library, you can take the full source strait  from the git page –

first you’ll need to setup a custom search api key and a custom search engine (make sure you enable the images search or you might spend some time debugging this).

the script simply convert your query into a url like the following

The query will return a json style object with either an error or your search results,we use simple json to check the results, I recommand going through the REST documentation and customize it for your own need .

a typical result item will look like this.


and will be converted to using simplejson

 Then we run a loop based on the number of call specified and add the ‘start’ index value in increments of 10 (you get 10 results each time)

 so to get started with your first 1000 cat images you’ll run the following

Originally I wanted to post about how to train your own cascade classifier and detect custom objects, then I realized that I’ll need to test my experiments on more then a few objects which lead me the the problem above, well hopefully the following condition is true: problem – solved.  so expect a post about custom object training soon.


if you have your training set ready, check out my personal trainer post to see how to use them in opencv and train your own cascade classifier