I need to find a good way to locate objects in the game, later I will find the coordinates of the object and send it to the Arduino controlling the stepper motors.

Step one is to install OpenCV on my Macbook. The best tutorial you will find on PyImageSearch.

First thing I tried was OpenCV with template matching. This is a method for searching and finding the location of a template image in a larger image. It simply slides the template image over the input image and compares the template and patch of input image under the template image. The method worked fairly OK, but it seemed like the method world be best on actual screengrabs, not motion video which can have a skew angle and differ in level of zoom. The template and object you want to find should be the same size.

This is when I discovered Haar Feature-based Cascade Classifier for Object Detection. This seems like the best algorithm to use for my case.

I have cloned a  good tutorial for learn how to train your own OpenCV Haar classifier, which I used in combination with this tutorial. All of the classifiers I have trained, will be uploaded here.

Pyton code for realtime testing of multiple classifiers:

EDIT: I discovered a fault that sent me on an hour detour around Google. At the step:

I only get the error:

I tried different things, like changing location of positive, negative and samples folder, adding the whole file location for  /usr/local/Cellar/opencv/2.4.12/bin/opencv_createsamples and messing around with the opencv_createsamples parameters. Nothing helped.

At some comment field I found the solution. I had only used one positive file when using the command:

This resulted in a positives.txt file having only one line of text. The createtrainsamples.pl ignores the last entry and throws an exception.

Just adding an empty line fixed the problem, and the script finally works!


Facebook Comments