Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub | SourceForge

The Detection structure provides object detection with using of HAAR and LBP cascade classifiers. More...

Data Structures

struct  Object
 The Object structure describes detected object. More...
 

Public Types

typedef A< uint8_t > Allocator
 
typedef Simd::View< A > View
 
typedef Simd::Point< ptrdiff_t > Size
 
typedef std::vector< SizeSizes
 
typedef Simd::Rectangle< ptrdiff_t > Rect
 
typedef std::vector< RectRects
 
typedef int Tag
 
typedef std::vector< ObjectObjects
 

Public Member Functions

 Detection ()
 
 ~Detection ()
 
bool Load (const std::string &path, Tag tag=UNDEFINED_OBJECT_TAG)
 
bool Init (const Size &imageSize, double scaleFactor=1.1, const Size &sizeMin=Size(0, 0), const Size &sizeMax=Size(INT_MAX, INT_MAX), const View &roi=View(), ptrdiff_t threadNumber=-1)
 
bool Detect (const View &src, Objects &objects, int groupSizeMin=3, double sizeDifferenceMax=0.2, bool motionMask=false, const Rects &motionRegions=Rects())
 

Static Public Attributes

static const Tag UNDEFINED_OBJECT_TAG = -1
 

Detailed Description

template<template< class > class A>
struct Simd::Detection< A >

The Detection structure provides object detection with using of HAAR and LBP cascade classifiers.

Using example (face detection in the image):

#include "Simd/SimdDetection.hpp"
#include "Simd/SimdDrawing.hpp"
int main()
{
image.Load("../../data/image/face/lena.pgm");
Detection detection;
detection.Load("../../data/cascade/haar_face_0.xml");
detection.Init(image.Size());
detection.Detect(image, objects);
for (size_t i = 0; i < objects.size(); ++i)
Simd::DrawRectangle(image, objects[i].rect, uint8_t(255));
image.Save("result.pgm");
return 0;
}

Using example (face detection in the video captured by OpenCV):

#include <iostream>
#include <string>
#include "opencv2/opencv.hpp"
#ifndef SIMD_OPENCV_ENABLE
#define SIMD_OPENCV_ENABLE
#endif
#include "Simd/SimdDetection.hpp"
#include "Simd/SimdDrawing.hpp"
int main(int argc, char * argv[])
{
if (argc < 2)
{
std::cout << "You have to set video source! It can be 0 for camera or video file name." << std::endl;
return 1;
}
std::string source = argv[1];
cv::VideoCapture capture;
if (source == "0")
capture.open(0);
else
capture.open(source);
if (!capture.isOpened())
{
std::cout << "Can't capture '" << source << "' !" << std::endl;
return 1;
}
Detection detection;
detection.Load("../../data/cascade/haar_face_0.xml");
bool inited = false;
const char * WINDOW_NAME = "FaceDetection";
cv::namedWindow(WINDOW_NAME, 1);
for (;;)
{
cv::Mat frame;
capture >> frame;
Detection::View image = frame;
if (!inited)
{
detection.Init(image.Size(), 1.2, image.Size() / 20);
inited = true;
}
detection.Detect(image, objects);
for (size_t i = 0; i < objects.size(); ++i)
Simd::DrawRectangle(image, objects[i].rect, Simd::Pixel::Bgr24(0, 255, 255));
cv::imshow(WINDOW_NAME, frame);
if (cvWaitKey(1) == 27)// "press 'Esc' to break video";
break;
}
return 0;
}
Note
This is wrapper around low-level Object Detection API.

Member Typedef Documentation

◆ Allocator

typedef A<uint8_t> Allocator

Allocator type definition.

◆ View

typedef Simd::View<A> View

An image type definition.

◆ Size

typedef Simd::Point<ptrdiff_t> Size

An image size type definition.

◆ Sizes

typedef std::vector<Size> Sizes

A vector of image sizes type definition.

◆ Rect

typedef Simd::Rectangle<ptrdiff_t> Rect

A rectangle type definition.

◆ Rects

typedef std::vector<Rect> Rects

A vector of rectangles type definition.

◆ Tag

typedef int Tag

A tag type definition.

◆ Objects

typedef std::vector<Object> Objects

A vector of objects type defenition.

Constructor & Destructor Documentation

◆ Detection()

Detection ( )

Creates a new empty Detection structure.

◆ ~Detection()

~Detection ( )

A Detection destructor.

Member Function Documentation

◆ Load()

bool Load ( const std::string &  path,
Tag  tag = UNDEFINED_OBJECT_TAG 
)

Loads from file classifier cascade. Supports OpenCV HAAR and LBP cascades type. You can call this function more than once if you want to use several object detectors at the same time.

Note
Tree based cascades and old cascade formats are not supported!
Parameters
[in]path- a path to cascade.
[in]tag- an user defined tag. This tag will be inserted in output Object structure.
Returns
a result of this operation.

◆ Init()

bool Init ( const Size imageSize,
double  scaleFactor = 1.1,
const Size sizeMin = Size(0, 0),
const Size sizeMax = Size(INT_MAX, INT_MAX),
const View roi = View(),
ptrdiff_t  threadNumber = -1 
)

Prepares Detection structure to work with image of given size.

Parameters
[in]imageSize- a size of input image.
[in]scaleFactor- a scale factor. To detect objects of different sizes the algorithm uses many scaled image. This parameter defines size difference between neighboring images. This parameter strongly affects to performance.
[in]sizeMin- a minimal size of detected objects. This parameter strongly affects to performance.
[in]sizeMax- a maximal size of detected objects.
[in]roi- a 8-bit image mask which defines Region Of Interest. User can restricts detection region with using this mask. The mask affects to the center of detected object.
[in]threadNumber- a number of work threads. It useful for multi core CPU. Use value -1 to auto choose of thread number.
Returns
a result of this operation.

◆ Detect()

bool Detect ( const View src,
Objects objects,
int  groupSizeMin = 3,
double  sizeDifferenceMax = 0.2,
bool  motionMask = false,
const Rects motionRegions = Rects() 
)

Detects objects at given image.

Parameters
[in]src- a input image.
[out]objects- detected objects.
[in]groupSizeMin- a minimal weight (number of elementary detections) of detected image.
[in]sizeDifferenceMax- a parameter to group elementary detections.
[in]motionMask- an using of motion detection flag. Useful for dynamical restriction of detection region to addition to ROI.
[in]motionRegions- a set of rectangles (motion regions) to restrict detection region to addition to ROI. The regions affect to the center of detected object.
Returns
a result of this operation.

Field Documentation

◆ UNDEFINED_OBJECT_TAG

const Tag UNDEFINED_OBJECT_TAG = -1
static

The undefined object tag.