Giter Site home page Giter Site logo

cigarette-detection-with-haar-cascade-classifier's Introduction

Cigarette Detection

Building on Linux

We are going to follow the instructions given here:

To build you need CMake and OpenCV on your system.

$ git clone https://github.com/Itseez/opencv.git

Compiler:

sudo apt-get install build-essential

Required Libraries:

$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

Python bindings and such:

$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

OpenCV development library:

sudo apt-get install libopencv-dev

Dataset

As positive image, I tried both training the haar cascade with a cigarette image (cigar100x75.jpg) and a hand image holding a cigarette (cigar100x84.jpg). As negative image, I took a sample of 5394 images from a face dataset.

Preparation

We need to create files which contains information about our dataset.

Run create_neg() and create_pos() functions in the sample_creator.ipynb notebook to create those files named as "bg.txt" which contains the paths of negative images and "info.dat" which contains the coordinates of the cigarette object in our positive image.

After that, run the following commands in terminal to create positive samples:

opencv_createsamples -img cigar100x84.jpg -bg bg.txt -info positive_images/info.lst -pngout positive_images -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 1950

Once the positive samples have been created, we need a new file which contains information stating that where the cigarette is in our recently created positive images, just like "info.dat". We will call it as "info.lst"

opencv_createsamples -info positive_images/info.lst -num 1950 -w 50 -h 40 -vec positives.vec

Training

Now, it's time to train a haar cascade to detect cigarettes in images and hopefully in videos.

opencv_traincascade -data data -vec positives.vec -bg bg.txt -numPos 1900 -numNeg 950 -numStages 6 -w 50 -h 40 

Done!

Results

Now we can try our cascade using the codes in the detect_my_cigar.ipynb notebook.

Markdown Monster icon Markdown Monster icon Markdown Monster icon

cigarette-detection-with-haar-cascade-classifier's People

Contributors

paradiddle131 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jinteacher

cigarette-detection-with-haar-cascade-classifier's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.