NAME

PDL::OpenCV::Objdetect - PDL bindings for OpenCV BaseCascadeClassifier, CascadeClassifier, HOGDescriptor, QRCodeDetector

SYNOPSIS

use PDL::OpenCV::Objdetect;

FUNCTIONS

groupRectangles

Signature: (indx [io,phys] rectList(n1=4,n1d0); int [o,phys] weights(n2d0); int [phys] groupThreshold(); double [phys] eps())
NO BROADCASTING.
$weights = groupRectangles($rectList,$groupThreshold); # with defaults
$weights = groupRectangles($rectList,$groupThreshold,$eps);

@overload

groupRectangles ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

METHODS for PDL::OpenCV::BaseCascadeClassifier

Subclass of PDL::OpenCV::Algorithm

METHODS for PDL::OpenCV::CascadeClassifier

Cascade classifier class for object detection.

new

$obj = PDL::OpenCV::CascadeClassifier->new;

new2

Loads a classifier from a file.

$obj = PDL::OpenCV::CascadeClassifier->new2($filename);

Parameters:

filename

Name of the file from which the classifier is loaded.

empty

Checks whether the classifier has been loaded.

$res = $obj->empty;

load

Loads a classifier from a file.

$res = $obj->load($filename);

Parameters:

filename

Name of the file from which the classifier is loaded. The file may contain an old HAAR classifier trained by the haartraining application or a new cascade classifier trained by the traincascade application.

read

Reads a classifier from a FileStorage node.

$res = $obj->read($node);

@note The file may contain a new cascade classifier (trained traincascade application) only.

CascadeClassifier_detectMultiScale

Signature: ([phys] image(l2,c2,r2); indx [o,phys] objects(n3=4,n3d0); double [phys] scaleFactor(); int [phys] minNeighbors(); int [phys] flags(); indx [phys] minSize(n7); indx [phys] maxSize(n8); CascadeClassifierWrapper * self)

Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles. NO BROADCASTING.

$objects = $obj->detectMultiScale($image); # with defaults
$objects = $obj->detectMultiScale($image,$scaleFactor,$minNeighbors,$flags,$minSize,$maxSize);

The function is parallelized with the TBB library. @note - (Python) A face detection example using cascade classifiers can be found at opencv_source_code/samples/python/facedetect.py

Parameters:

image

Matrix of the type CV_8U containing an image where objects are detected.

objects

Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.

scaleFactor

Parameter specifying how much the image size is reduced at each image scale.

minNeighbors

Parameter specifying how many neighbors each candidate rectangle should have to retain it.

flags

Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.

minSize

Minimum possible object size. Objects smaller than that are ignored.

maxSize

Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.

CascadeClassifier_detectMultiScale ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

CascadeClassifier_detectMultiScale2

Signature: ([phys] image(l2,c2,r2); indx [o,phys] objects(n3=4,n3d0); int [o,phys] numDetections(n4d0); double [phys] scaleFactor(); int [phys] minNeighbors(); int [phys] flags(); indx [phys] minSize(n8); indx [phys] maxSize(n9); CascadeClassifierWrapper * self)
NO BROADCASTING.
($objects,$numDetections) = $obj->detectMultiScale2($image); # with defaults
($objects,$numDetections) = $obj->detectMultiScale2($image,$scaleFactor,$minNeighbors,$flags,$minSize,$maxSize);

@overload

Parameters:

image

Matrix of the type CV_8U containing an image where objects are detected.

objects

Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.

numDetections

Vector of detection numbers for the corresponding objects. An object's number of detections is the number of neighboring positively classified rectangles that were joined together to form the object.

scaleFactor

Parameter specifying how much the image size is reduced at each image scale.

minNeighbors

Parameter specifying how many neighbors each candidate rectangle should have to retain it.

flags

Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.

minSize

Minimum possible object size. Objects smaller than that are ignored.

maxSize

Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.

CascadeClassifier_detectMultiScale2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

CascadeClassifier_detectMultiScale3

Signature: ([phys] image(l2,c2,r2); indx [o,phys] objects(n3=4,n3d0); int [o,phys] rejectLevels(n4d0); double [o,phys] levelWeights(n5d0); double [phys] scaleFactor(); int [phys] minNeighbors(); int [phys] flags(); indx [phys] minSize(n9); indx [phys] maxSize(n10); byte [phys] outputRejectLevels(); CascadeClassifierWrapper * self)
NO BROADCASTING.
($objects,$rejectLevels,$levelWeights) = $obj->detectMultiScale3($image); # with defaults
($objects,$rejectLevels,$levelWeights) = $obj->detectMultiScale3($image,$scaleFactor,$minNeighbors,$flags,$minSize,$maxSize,$outputRejectLevels);

@overload This function allows you to retrieve the final stage decision certainty of classification. For this, one needs to set `outputRejectLevels` on true and provide the `rejectLevels` and `levelWeights` parameter. For each resulting detection, `levelWeights` will then contain the certainty of classification at the final stage. This value can then be used to separate strong from weaker classifications. A code sample on how to use it efficiently can be found below:

Mat img;
vector<double> weights;
vector<int> levels;
vector<Rect> detections;
CascadeClassifier model("/path/to/your/model.xml");
model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl;

CascadeClassifier_detectMultiScale3 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

isOldFormatCascade

$res = $obj->isOldFormatCascade;

CascadeClassifier_getOriginalWindowSize

Signature: (indx [o,phys] res(n2=2); CascadeClassifierWrapper * self)
$res = $obj->getOriginalWindowSize;

CascadeClassifier_getOriginalWindowSize ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

getFeatureType

$res = $obj->getFeatureType;

convert

$res = PDL::OpenCV::CascadeClassifier::convert($oldcascade,$newcascade);

METHODS for PDL::OpenCV::HOGDescriptor

Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector.

the HOG descriptor algorithm introduced by Navneet Dalal and Bill Triggs @cite Dalal2005 . useful links: https://hal.inria.fr/inria-00548512/document/ https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients https://software.intel.com/en-us/ipp-dev-reference-histogram-of-oriented-gradients-hog-descriptor http://www.learnopencv.com/histogram-of-oriented-gradients http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial

new

Creates the HOG descriptor and detector with default params.

$obj = PDL::OpenCV::HOGDescriptor->new;

aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9 )

HOGDescriptor_new2

Signature: (indx [phys] _winSize(n2=2); indx [phys] _blockSize(n3=2); indx [phys] _blockStride(n4=2); indx [phys] _cellSize(n5=2); int [phys] _nbins(); int [phys] _derivAperture(); double [phys] _winSigma(); int [phys] _histogramNormType(); double [phys] _L2HysThreshold(); byte [phys] _gammaCorrection(); int [phys] _nlevels(); byte [phys] _signedGradient(); char * klass; [o] HOGDescriptorWrapper * res)
$obj = PDL::OpenCV::HOGDescriptor->new2($_winSize,$_blockSize,$_blockStride,$_cellSize,$_nbins); # with defaults
$obj = PDL::OpenCV::HOGDescriptor->new2($_winSize,$_blockSize,$_blockStride,$_cellSize,$_nbins,$_derivAperture,$_winSigma,$_histogramNormType,$_L2HysThreshold,$_gammaCorrection,$_nlevels,$_signedGradient);

@overload

Parameters:

_winSize

sets winSize with given value.

_blockSize

sets blockSize with given value.

_blockStride

sets blockStride with given value.

_cellSize

sets cellSize with given value.

_nbins

sets nbins with given value.

_derivAperture

sets derivAperture with given value.

_winSigma

sets winSigma with given value.

_histogramNormType

sets histogramNormType with given value.

_L2HysThreshold

sets L2HysThreshold with given value.

_gammaCorrection

sets gammaCorrection with given value.

_nlevels

sets nlevels with given value.

_signedGradient

sets signedGradient with given value.

HOGDescriptor_new2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

new3

$obj = PDL::OpenCV::HOGDescriptor->new3($filename);

@overload

Parameters:

filename

The file name containing HOGDescriptor properties and coefficients for the linear SVM classifier.

getDescriptorSize

Returns the number of coefficients required for the classification.

$res = $obj->getDescriptorSize;

checkDetectorSize

Checks if detector size equal to descriptor size.

$res = $obj->checkDetectorSize;

getWinSigma

Returns winSigma value

$res = $obj->getWinSigma;

HOGDescriptor_setSVMDetector

Signature: ([phys] svmdetector(l2,c2,r2); HOGDescriptorWrapper * self)

Sets coefficients for the linear SVM classifier.

$obj->setSVMDetector($svmdetector);

Parameters:

svmdetector

coefficients for the linear SVM classifier.

HOGDescriptor_setSVMDetector ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

load

loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file.

$res = $obj->load($filename); # with defaults
$res = $obj->load($filename,$objname);

Parameters:

filename

Path of the file to read.

objname

The optional name of the node to read (if empty, the first top-level node will be used).

save

saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file

$obj->save($filename); # with defaults
$obj->save($filename,$objname);

Parameters:

filename

File name

objname

Object name

HOGDescriptor_compute

Signature: ([phys] img(l2,c2,r2); float [o,phys] descriptors(n3d0); indx [phys] winStride(n4); indx [phys] padding(n5); indx [phys] locations(n6,n6d0); HOGDescriptorWrapper * self)

Computes HOG descriptors of given image. NO BROADCASTING.

$descriptors = $obj->compute($img); # with defaults
$descriptors = $obj->compute($img,$winStride,$padding,$locations);

Parameters:

img

Matrix of the type CV_8U containing an image where HOG features will be calculated.

descriptors

Matrix of the type CV_32F

winStride

Window stride. It must be a multiple of block stride.

padding

Padding

locations

Vector of Point

HOGDescriptor_compute ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

HOGDescriptor_detect

Signature: ([phys] img(l2,c2,r2); indx [o,phys] foundLocations(n3=2,n3d0); double [o,phys] weights(n4d0); double [phys] hitThreshold(); indx [phys] winStride(n6); indx [phys] padding(n7); indx [phys] searchLocations(n8,n8d0); HOGDescriptorWrapper * self)

Performs object detection without a multi-scale window. NO BROADCASTING.

($foundLocations,$weights) = $obj->detect($img); # with defaults
($foundLocations,$weights) = $obj->detect($img,$hitThreshold,$winStride,$padding,$searchLocations);

Parameters:

img

Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

foundLocations

Vector of point where each point contains left-top corner point of detected object boundaries.

weights

Vector that will contain confidence values for each detected object.

hitThreshold

Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). But if the free coefficient is omitted (which is allowed), you can specify it manually here.

winStride

Window stride. It must be a multiple of block stride.

padding

Padding

searchLocations

Vector of Point includes set of requested locations to be evaluated.

HOGDescriptor_detect ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

HOGDescriptor_detectMultiScale

Signature: ([phys] img(l2,c2,r2); indx [o,phys] foundLocations(n3=4,n3d0); double [o,phys] foundWeights(n4d0); double [phys] hitThreshold(); indx [phys] winStride(n6); indx [phys] padding(n7); double [phys] scale(); double [phys] finalThreshold(); byte [phys] useMeanshiftGrouping(); HOGDescriptorWrapper * self)

Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles. NO BROADCASTING.

($foundLocations,$foundWeights) = $obj->detectMultiScale($img); # with defaults
($foundLocations,$foundWeights) = $obj->detectMultiScale($img,$hitThreshold,$winStride,$padding,$scale,$finalThreshold,$useMeanshiftGrouping);

Parameters:

img

Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected.

foundLocations

Vector of rectangles where each rectangle contains the detected object.

foundWeights

Vector that will contain confidence values for each detected object.

hitThreshold

Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). But if the free coefficient is omitted (which is allowed), you can specify it manually here.

winStride

Window stride. It must be a multiple of block stride.

padding

Padding

scale

Coefficient of the detection window increase.

finalThreshold

Final threshold

useMeanshiftGrouping

indicates grouping algorithm

HOGDescriptor_detectMultiScale ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

HOGDescriptor_computeGradient

Signature: ([phys] img(l2,c2,r2); [io,phys] grad(l3,c3,r3); [io,phys] angleOfs(l4,c4,r4); indx [phys] paddingTL(n5); indx [phys] paddingBR(n6); HOGDescriptorWrapper * self)

Computes gradients and quantized gradient orientations.

$obj->computeGradient($img,$grad,$angleOfs); # with defaults
$obj->computeGradient($img,$grad,$angleOfs,$paddingTL,$paddingBR);

Parameters:

img

Matrix contains the image to be computed

grad

Matrix of type CV_32FC2 contains computed gradients

angleOfs

Matrix of type CV_8UC2 contains quantized gradient orientations

paddingTL

Padding from top-left

paddingBR

Padding from bottom-right

HOGDescriptor_computeGradient ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

HOGDescriptor_getDefaultPeopleDetector

Signature: (float [o,phys] res(n1d0))

Returns coefficients of the classifier trained for people detection (for 64x128 windows). NO BROADCASTING.

$res = PDL::OpenCV::HOGDescriptor::getDefaultPeopleDetector;

HOGDescriptor_getDefaultPeopleDetector ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

HOGDescriptor_getDaimlerPeopleDetector

Signature: (float [o,phys] res(n1d0))

Returns coefficients of the classifier trained for people detection (for 48x96 windows). NO BROADCASTING.

$res = PDL::OpenCV::HOGDescriptor::getDaimlerPeopleDetector;

HOGDescriptor_getDaimlerPeopleDetector ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

METHODS for PDL::OpenCV::QRCodeDetector

Groups the object candidate rectangles.

Parameters:

rectList

Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.)

weights

Input/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.)

groupThreshold

Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.

eps

Relative difference between sides of the rectangles to merge them into a group.

new

$obj = PDL::OpenCV::QRCodeDetector->new;

setEpsX

sets the epsilon used during the horizontal scan of QR code stop marker detection.

$obj->setEpsX($epsX);

Parameters:

epsX

Epsilon neighborhood, which allows you to determine the horizontal pattern of the scheme 1:1:3:1:1 according to QR code standard.

setEpsY

sets the epsilon used during the vertical scan of QR code stop marker detection.

$obj->setEpsY($epsY);

Parameters:

epsY

Epsilon neighborhood, which allows you to determine the vertical pattern of the scheme 1:1:3:1:1 according to QR code standard.

QRCodeDetector_detect

Signature: ([phys] img(l2,c2,r2); [o,phys] points(l3,c3,r3); byte [o,phys] res(); QRCodeDetectorWrapper * self)

Detects QR code in image and returns the quadrangle containing the code. NO BROADCASTING.

($points,$res) = $obj->detect($img);

Parameters:

img

grayscale or color (BGR) image containing (or not) QR code.

points

Output vector of vertices of the minimum-area quadrangle containing the code.

QRCodeDetector_detect ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

QRCodeDetector_decode

Signature: ([phys] img(l2,c2,r2); [phys] points(l3,c3,r3); [o,phys] straight_qrcode(l4,c4,r4); QRCodeDetectorWrapper * self; [o] StringWrapper* res)

Decodes QR code in image once it's found by the detect() method. NO BROADCASTING.

($straight_qrcode,$res) = $obj->decode($img,$points);

Returns UTF8-encoded output string or empty string if the code cannot be decoded.

Parameters:

img

grayscale or color (BGR) image containing QR code.

points

Quadrangle vertices found by detect() method (or some other algorithm).

straight_qrcode

The optional output image containing rectified and binarized QR code

QRCodeDetector_decode ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

QRCodeDetector_decodeCurved

Signature: ([phys] img(l2,c2,r2); [phys] points(l3,c3,r3); [o,phys] straight_qrcode(l4,c4,r4); QRCodeDetectorWrapper * self; [o] StringWrapper* res)

Decodes QR code on a curved surface in image once it's found by the detect() method. NO BROADCASTING.

($straight_qrcode,$res) = $obj->decodeCurved($img,$points);

Returns UTF8-encoded output string or empty string if the code cannot be decoded.

Parameters:

img

grayscale or color (BGR) image containing QR code.

points

Quadrangle vertices found by detect() method (or some other algorithm).

straight_qrcode

The optional output image containing rectified and binarized QR code

QRCodeDetector_decodeCurved ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

QRCodeDetector_detectAndDecode

Signature: ([phys] img(l2,c2,r2); [o,phys] points(l3,c3,r3); [o,phys] straight_qrcode(l4,c4,r4); QRCodeDetectorWrapper * self; [o] StringWrapper* res)

Both detects and decodes QR code NO BROADCASTING.

($points,$straight_qrcode,$res) = $obj->detectAndDecode($img);

Parameters:

img

grayscale or color (BGR) image containing QR code.

points

optional output array of vertices of the found QR code quadrangle. Will be empty if not found.

straight_qrcode

The optional output image containing rectified and binarized QR code

QRCodeDetector_detectAndDecode ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

QRCodeDetector_detectAndDecodeCurved

Signature: ([phys] img(l2,c2,r2); [o,phys] points(l3,c3,r3); [o,phys] straight_qrcode(l4,c4,r4); QRCodeDetectorWrapper * self; [o] StringWrapper* res)

Both detects and decodes QR code on a curved surface NO BROADCASTING.

($points,$straight_qrcode,$res) = $obj->detectAndDecodeCurved($img);

Parameters:

img

grayscale or color (BGR) image containing QR code.

points

optional output array of vertices of the found QR code quadrangle. Will be empty if not found.

straight_qrcode

The optional output image containing rectified and binarized QR code

QRCodeDetector_detectAndDecodeCurved ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

QRCodeDetector_detectMulti

Signature: ([phys] img(l2,c2,r2); [o,phys] points(l3,c3,r3); byte [o,phys] res(); QRCodeDetectorWrapper * self)

Detects QR codes in image and returns the vector of the quadrangles containing the codes. NO BROADCASTING.

($points,$res) = $obj->detectMulti($img);

Parameters:

img

grayscale or color (BGR) image containing (or not) QR codes.

points

Output vector of vector of vertices of the minimum-area quadrangle containing the codes.

QRCodeDetector_detectMulti ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

QRCodeDetector_decodeMulti

Signature: ([phys] img(l2,c2,r2); [phys] points(l3,c3,r3); byte [o,phys] res(); QRCodeDetectorWrapper * self; [o] vector_StringWrapper * decoded_info; [o] vector_MatWrapper * straight_qrcode)

Decodes QR codes in image once it's found by the detect() method.

($decoded_info,$straight_qrcode,$res) = $obj->decodeMulti($img,$points);

Parameters:

img

grayscale or color (BGR) image containing QR codes.

decoded_info

UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.

points

vector of Quadrangle vertices found by detect() method (or some other algorithm).

straight_qrcode

The optional output vector of images containing rectified and binarized QR codes

QRCodeDetector_decodeMulti ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

QRCodeDetector_detectAndDecodeMulti

Signature: ([phys] img(l2,c2,r2); [o,phys] points(l4,c4,r4); byte [o,phys] res(); QRCodeDetectorWrapper * self; [o] vector_StringWrapper * decoded_info; [o] vector_MatWrapper * straight_qrcode)

Both detects and decodes QR codes NO BROADCASTING.

($decoded_info,$points,$straight_qrcode,$res) = $obj->detectAndDecodeMulti($img);

Parameters:

img

grayscale or color (BGR) image containing QR codes.

decoded_info

UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.

points

optional output vector of vertices of the found QR code quadrangles. Will be empty if not found.

straight_qrcode

The optional output vector of images containing rectified and binarized QR codes

QRCodeDetector_detectAndDecodeMulti ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.

CONSTANTS

PDL::OpenCV::Objdetect::CASCADE_DO_CANNY_PRUNING()
PDL::OpenCV::Objdetect::CASCADE_SCALE_IMAGE()
PDL::OpenCV::Objdetect::CASCADE_FIND_BIGGEST_OBJECT()
PDL::OpenCV::Objdetect::CASCADE_DO_ROUGH_SEARCH()
PDL::OpenCV::Objdetect::HOGDescriptor::L2Hys()
PDL::OpenCV::Objdetect::HOGDescriptor::DEFAULT_NLEVELS()
PDL::OpenCV::Objdetect::HOGDescriptor::DESCR_FORMAT_COL_BY_COL()
PDL::OpenCV::Objdetect::HOGDescriptor::DESCR_FORMAT_ROW_BY_ROW()