This is a HAAR Cascade Classifier training GUI application for Linux. This application makes it really easy to train classifiers for object detection and tracking using opencv by providing a Graphical user interface to set parameters and perform necessary steps.
This script has some minimum system requirements to run. They are listed as follows:
Linux based system/terminal
This application runs shell scripts with Linux specific commands. So, you would need a linux based system to perform tasks with the application.
Python 3.6.9 (tested)
Python should come pre-installed on your linux system. You can still check for the version of it with the command:
If for any reason python is missing or is of oler version, use the following command to install python3 on your system.
Anaconda
The latest versions of OpenCV do not support cascade trainer. Thus, downloading older versions of opencv
is necessary to use this program. To avoid conflicts between package versions, it is recommended to create a separate environment that contains opencv3
. Using Anaconda for this purpose is recommended, and the steps for the same are described in the following section.
The script can run with these minimum requirements and can install other packages automatically. However, it is recommended that you install the following packages before running the application:
Git
Git should be pre-installed on your linux system but for any reason if it's not, you can run the following command to install it:
Tkinter
This library is present by default in python3. But if still missing you can install it by using the following command provided:
OpenCV
Create a new conda environment with a desired name, such as opencv_legacy
using the command:
Install OpenCV 3 from Anaconda repository using the following command:
It is necessary to keep the environment activated when using this program so that python can detect the appropriate version of OpenCV. Once you are done using the program, you can deactivate this environment using the command:
LibOpenCV
This library would not be install by default, you can install openCV with the following commands:
This application is super easy to use! Here are all the step from downloading the application till testing your classifier:
-
You need to first clone all the files from the github repository. Visit the repositiry and download it as a zip file or just open the terminal and type the following command:
-
Once downloaded open the terminal in the downloaded directory to make it the present working directory.
-
Once changed the pwd, you need to make all the file in the
./app
directory executable, use the following command to change the permission of the files: -
Change you pwd to the app and execute the
main.py
with python using the following command: -
This will launch the application interface with which you can train your HAAR Cascade classifier with your dataset.
Now, you have the application ready and running to train you classifier. The steps below tell you how you can train the classifier using actual dataset.
-
To train a HAAR Cascade Classifier you will have to create two directories with positive and negative images i.e. images with the target object and the images without the target object accordingly. Provide the location of the directories of the positive dataset and negative dataset as per asked in the application.
-
Then you need to select an output directory to tell the application where to store the
classifier.xml
file. Its recommended although not necessage to keep both the directories in the same directory and use that directory as the output directory. -
Now provide the width and height of the traget object which is by default set to 24x24.
-
Now provide the percent of positive sample you want to use for the training of the classifier.
-
Set the number of stages of training of your classifier which by default is set to 10.
-
Press the start button to start training!
-
When the training is done, you can file your
classifier.xml
file in the output directory as./classifier/classifier.xml
This application doesn't cleans the data and the vectors are generate automatically on the positive dataset so its highly recommended that your positive images are well cropped and only contain the target object. I will be adding a cropper, an image labeler, seperate vector file providing and positive dataset generation using single image features in the coming versions. Till then just manage with this small drawback.
If you like my work, a bit of contribution would motivate me a lot for more open source contributions.
Please support the work: