Sie sind auf Seite 1von 8

Lecture outline, algorithms and

VIDEO DETECTION WITH OPENCV steps for object detection in


video files using python &
opencv
LECTURE OUTLINE
Introduction & Overview of the environment 30 min
 Introduction
 Python version, pip
 OpenCV, Numpy and other dependencies (Anaconda)
 Matplotlib (optional)
Video detection basics – example detection of familiar objects 45 mins
 The process of video detection
 Opencv coding for video detection – example car, face, etc.
Video detection of special objects – example motorbike
 The process of training and creating filter 15 mins
 Gathering inputs for filter creation 30 mins
 Environment setup for filter creation 15-30 mins
 Training and creating filter 30 mins
 Applying filter for detecting special object 15 mins
ENVIRONMENT SETUP
Pre-requisites:
1. Anaconda from https://www.continuum.io/anaconda-overview
2. Python version 3.5+, pip recommended

Setting up environment
1. create environment using anaconda navigator (Environments tab). Better to use python 3.5
2. conda install -c conda-forge opencv (numpy pulled in as dependency)
3. conda install -c conda-forge matplotlib

Verify by running python and importing cv2, numpy and matplotlib


>>> import cv2, numpy as np, matplotlib
DETECTING FAMILIAR OBJECTS
Detection Code Video with
Video Input (OpenCV, Python) annotations
Video detection code uses filter to detect objects
in video input.
In opencv, below are the steps
1. cv2.VideoCapture to open a video feed.
2. cv2.CascadeClassiffier to create a classifier based on a
filter Filter (xml)
3. cv2.imread to read image file or cap.read to read
frame from capture
4. cv2.detectMultiScale to detect objects.
5. cv2 drawing functions (e.g., rectangle) to annotate.
6. cv2.imshow to show a frame on the screen

Demonstrating object detection for familiar objects References:


Cars.xml – https://github.com/shaanhk/New-GithubTest/blob/master/cars.xml
Face/eyes – https://github.com/opencv/opencv/tree/master/data/haarcascades
DETECTING CUSTOM OBJECTS
Detection Code Video with
Video Input (OpenCV, Python) annotations
Video detection code uses filter to detect objects
in video input.
Training used to create a new filter
Making your own cascade
1. Collect “Negative” or “Background” images – 1000s Filter (xml)
2. Collect or create “positive” images
3. Create a positive vector file by stitching together all
positive images (using an opencv command)
4. Train cascade using an opencv command

Positives Training Code Negatives


References:
(OpenCV)
https://www.youtube.com/watch?v=jG3bu0tjFbk&list=PLQVvvaa0QuDdttJXlLtAJxJetJ
cqmqlQq&index=17
DETECTING CUSTOM OBJECTS
Pre-requisites
 Need “positive” image of the object to detect
 Background images or “negative” images
 Opencv source distribution & familiarity with command-line.

Actual complexity depends on accuracy.


 Easy to detect location of 1 object instance at 20x20px => 4h of preparation & 4h of training on a
standard laptop
 Very hard to detect location of n instances at any size and any variation => 4-5h of preparation and
40-100 h of training on large server.

Demonstrating making custom cascade


16
Jul
TRAIN YOUR OWN OPENCV HAAR 2017

CLASSIFIER
Custom object – specific object vs object class
 E.g., detecting my pen vs detecting any pen in the image

Good training requires a lot of positive and negative samples


 Custom object => 40+ positive samples, 500-600 negative samples
 Object class => Thousands (Depends on the class) E.g,. Face training with 2000+ positive samples converted into
5000-7000 patterns.

Utilities / Dependencies:
 https://github.com/mrnugget/opencv-haar-classifier-training
 http://www.mediafire.com/file/1aq02tpidk105fv/dasar_haartrain.rar (for objectmarker)
 https://github.com/opencv/opencv/releases/tag/2.4.13 - opencv-2.4.13.exe (for createsamples, traincascade)

Detailed procedure + Tutorial:


 Custom object detection training: 1, 2
 Custom object class: http://note.sonots.com/SciSoftware/haartraining.html

Training is typically iterative with each iteration taking a few hours to days.

Das könnte Ihnen auch gefallen