\section { Object Detection}
\cvclass { gpu::HOGDescriptor}
Histogram of Oriented Gradients \cite { dalal_ hog} descriptor and detector.
\begin { lstlisting}
struct CV_ EXPORTS HOGDescriptor
{
enum { DEFAULT_ WIN_ SIGMA = -1 } ;
enum { DEFAULT_ NLEVELS = 64 } ;
enum { DESCR_ FORMAT_ ROW_ BY_ ROW, DESCR_ FORMAT_ COL_ BY_ COL } ;
HOGDescriptor(Size win_ size=Size(64, 128), Size block_ size=Size(16, 16),
Size block_ stride=Size(8, 8), Size cell_ size=Size(8, 8),
int nbins=9, double win_ sigma=DEFAULT_ WIN_ SIGMA,
double threshold_ L2hys=0.2, bool gamma_ correction=true,
int nlevels=DEFAULT_ NLEVELS);
size_ t getDescriptorSize() const;
size_ t getBlockHistogramSize() const;
void setSVMDetector(const vector<float>& detector);
static vector<float> getDefaultPeopleDetector();
static vector<float> getPeopleDetector48x96();
static vector<float> getPeopleDetector64x128();
void detect(const GpuMat& img, vector<Point>& found_ locations,
double hit_ threshold=0, Size win_ stride=Size(),
Size padding=Size());
void detectMultiScale(const GpuMat& img, vector<Rect>& found_ locations,
double hit_ threshold=0, Size win_ stride=Size(),
Size padding=Size(), double scale0=1.05,
int group_ threshold=2);
void getDescriptors(const GpuMat& img, Size win_ stride,
GpuMat& descriptors,
int descr_ format=DESCR_ FORMAT_ COL_ BY_ COL);
Size win_ size;
Size block_ size;
Size block_ stride;
Size cell_ size;
int nbins;
double win_ sigma;
double threshold_ L2hys;
bool gamma_ correction;
int nlevels;
private:
// Hidden
}
\end { lstlisting}
Interfaces of all methods are kept similar to CPU HOG descriptor and detector analogues as much as possible.
\cvCppFunc { gpu::HOGDescriptor::HOGDescriptor}
Creates HOG descriptor and detector.
\cvdefCpp { HOGDescriptor::HOGDescriptor(Size win\_ size=Size(64, 128),\par
Size block\_ size=Size(16, 16), Size block\_ stride=Size(8, 8),\par
Size cell\_ size=Size(8, 8), int nbins=9,\par
double win\_ sigma=DEFAULT\_ WIN\_ SIGMA,\par
double threshold\_ L2hys=0.2, bool gamma\_ correction=true,\par
int nlevels=DEFAULT\_ NLEVELS);}
\begin { description}
\cvarg { win\_ size} { Detection window size. Must be aligned to block size and block stride.}
\cvarg { block\_ size} { Block size in pixels. Must be aligned to cell size. Only (16,16) is supported for now.}
\cvarg { block\_ stride} { Block stride. Must be a multiple of cell size.}
\cvarg { cell\_ size} { Cell size. Only (8, 8) is supported for now.}
\cvarg { nbins} { Number of bins. Only 9 bins per cell is supported for now.}
\cvarg { win\_ sigma} { Gaussian smoothing window parameter.}
\cvarg { threshold\_ L2Hys} { L2-Hys normalization method shrinkage.}
\cvarg { gamma\_ correction} { Do gamma correction preprocessing or not.}
\cvarg { nlevels} { Maximum number of detection window increases.}
\end { description}
\cvCppFunc { gpu::HOGDescriptor::getDescriptorSize}
Returns number of coefficients required for the classification.
\cvdefCpp { size\_ t HOGDescriptor::getDescriptorSize() const;}
\cvCppFunc { gpu::HOGDescriptor::getBlockHistogramSize}
Returns block histogram size.
\cvdefCpp { size\_ t HOGDescriptor::getBlockHistogramSize() const;}
\cvCppFunc { gpu::HOGDescriptor::setSVMDetector}
Sets coefficients for the linear SVM classifier.
\cvdefCpp { void HOGDescriptor::setSVMDetector(const vector<float>\& detector);}
\cvCppFunc { gpu::HOGDescriptor::getDefaultPeopleDetector}
Returns coefficients of the classifier trained for people detection (for default window size).
\cvdefCpp { static vector<float> HOGDescriptor::getDefaultPeopleDetector();}
\cvCppFunc { gpu::HOGDescriptor::getPeopleDetector48x96}
Returns coefficients of the classifier trained for people detection (for 48x96 windows).
\cvdefCpp { static vector<float> HOGDescriptor::getPeopleDetector48x96();}
\cvCppFunc { gpu::HOGDescriptor::getPeopleDetector64x128}
Returns coefficients of the classifier trained for people detection (for 64x128 windows).
\cvdefCpp { static vector<float> HOGDescriptor::getPeopleDetector64x128();}
\cvCppFunc { gpu::HOGDescriptor::detect}
Perfroms object detection without multiscale window.
\cvdefCpp { void HOGDescriptor::detect(const GpuMat\& img,\par
vector<Point>\& found\_ locations, double hit\_ threshold=0,\par
Size win\_ stride=Size(), Size padding=Size());}
\begin { description}
\cvarg { img} { Source image. \texttt { CV\_ 8UC1} and \texttt { CV\_ 8UC4} types are supported for now.}
\cvarg { found\_ locations} { Will contain left-top corner points of detected objects boundaries.}
\cvarg { hit\_ threshold} { Threshold for the distance between features and SVM classifying plane. Usually it's 0 and should be specfied in the detector coefficients (as the last free coefficient), but if the free coefficient is omitted (it's allowed) you can specify it manually here.}
\cvarg { win\_ stride} { Window stride. Must be a multiple of block stride.}
\cvarg { padding} { Mock parameter to keep CPU interface compatibility. Must be (0,0).}
\end { description}
\cvCppFunc { gpu::HOGDescriptor::detectMultiScale}
Perfroms object detection with multiscale window.
\cvdefCpp { void HOGDescriptor::detectMultiScale(const GpuMat\& img,\par
vector<Rect>\& found\_ locations, double hit\_ threshold=0,\par
Size win\_ stride=Size(), Size padding=Size(),\par
double scale0=1.05, int group\_ threshold=2);}
\begin { description}
\cvarg { img} { Source image. See \cvCppCross { gpu::HOGDescriptor::detect} for type limitations.}
\cvarg { found\_ locations} { Will contain detected objects boundaries.}
\cvarg { hit\_ threshold} { The threshold for the distance between features and SVM classifying plane. See \cvCppCross { gpu::HOGDescriptor::detect} for details.}
\cvarg { win\_ stride} { Window stride. Must be a multiple of block stride.}
\cvarg { padding} { Mock parameter to keep CPU interface compatibility. Must be (0,0).}
\cvarg { scale0} { Coefficient of the detection window increase.}
\cvarg { group\_ threshold} { After detection some objects could be covered by many rectangles. This coefficient regulates similarity threshold. 0 means don't perform grouping.\newline
See \cvCppCross { groupRectangles} .}
\end { description}
\cvCppFunc { gpu::HOGDescriptor::getDescriptors}
Returns block descriptors computed for the whole image. It's mainly used for classifier learning purposes.
\cvdefCpp { void HOGDescriptor::getDescriptors(const GpuMat\& img,\par
Size win\_ stride, GpuMat\& descriptors,\par
int descr\_ format=DESCR\_ FORMAT\_ COL\_ BY\_ COL);}
\begin { description}
\cvarg { img} { Source image. See \cvCppCross { gpu::HOGDescriptor::detect} for type limitations.}
\cvarg { win\_ stride} { Window stride. Must be a multiple of block stride.}
\cvarg { descriptors} { 2D array of descriptors.}
\cvarg { descr\_ format} { Descriptor storage format:
\begin { description}
\cvarg { DESCR\_ FORMAT\_ ROW\_ BY\_ ROW} { Row-major order.}
\cvarg { DESCR\_ FORMAT\_ COL\_ BY\_ COL} { Column-major order.}
\end { description} }
\end { description}
\cvclass { gpu::CascadeClassifier\_ GPU}
The cascade classifier class for object detection.
\begin { lstlisting}
class CV_ EXPORTS CascadeClassifier_ GPU
{
public:
CascadeClassifier_ GPU();
CascadeClassifier_ GPU(const string& filename);
~CascadeClassifier_ GPU();
bool empty() const;
bool load(const string& filename);
void release();
/* returns number of detected objects */
int detectMultiScale( const GpuMat& image, GpuMat& objectsBuf, double scaleFactor=1.2, int minNeighbors=4, Size minSize=Size());
/* Finds only the largest object. Special mode for need to training*/
bool findLargestObject;
/* Draws rectangles in input image */
bool visualizeInPlace;
Size getClassifierSize() const;
} ;
\end { lstlisting}
\cvfunc { cv::gpu::CascadeClassifier\_ GPU::CascadeClassifier\_ GPU} \par
Loads the classifier from file.
\cvdefCpp { cv::CascadeClassifier\_ GPU(const string\& filename);}
\begin { description}
\cvarg { filename} { Name of file from which classifier will be load. Only old haar classifier (trained by haartraining application) and NVidia's nvbin are supported.}
\end { description}
\cvfunc { cv::gpu::CascadeClassifier\_ GPU::empty}
Checks if the classifier has been loaded or not.
\cvdefCpp { bool CascadeClassifier\_ GPU::empty() const;}
\cvfunc { cv::gpu::CascadeClassifier\_ GPU::load}
Loads the classifier from file. The previous content is destroyed.
\cvdefCpp { bool CascadeClassifier\_ GPU::load(const string\& filename);}
\begin { description}
\cvarg { filename} { Name of file from which classifier will be load. Only old haar classifier (trained by haartraining application) and NVidia's nvbin are supported.}
\end { description}
\cvfunc { cv::gpu::CascadeClassifier\_ GPU::release}
Destroys loaded classifier.
\cvdefCpp { void CascadeClassifier\_ GPU::release()}
\cvfunc { cv::gpu::CascadeClassifier\_ GPU::detectMultiScale}
Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles.
\cvdefCpp { int CascadeClassifier\_ GPU::detectMultiScale(const GpuMat\& image, GpuMat\& objectsBuf, double scaleFactor=1.2, int minNeighbors=4, Size minSize=Size());}
\begin { description}
\cvarg { image} { Matrix of type \texttt { CV\_ 8U} containing the image in which to detect objects.}
\cvarg { objects} { Buffer to store detected objects (rectangles). If it is empty, it will be allocated with default size. If not empty, function will search not more than N objects, where N = sizeof(objectsBufer's data)/sizeof(cv::Rect).}
\cvarg { scaleFactor} { Specifies how much the image size is reduced at each image scale.}
\cvarg { minNeighbors} { Specifies how many neighbors should each candidate rectangle have to retain it.}
\cvarg { minSize} { The minimum possible object size. Objects smaller than that are ignored.}
\end { description}
The function returns number of detected objects, so you can retrieve them as in following example:
\begin { lstlisting}
cv::gpu::CascadeClassifier_ GPU cascade_ gpu(...);
Mat image_ cpu = imread(...)
GpuMat image_ gpu(image_ cpu);
GpuMat objbuf;
int detections_ number = cascade_ gpu.detectMultiScale( image_ gpu,
objbuf, 1.2, minNeighbors);
Mat obj_ host;
// download only detected number of rectangles
objbuf.colRange(0, detections_ number).download(obj_ host);
Rect* faces = obj_ host.ptr<Rect>();
for(int i = 0; i < detections_ num; ++i)
cv::rectangle(image_ cpu, faces[i], Scalar(255));
imshow("Faces", image_ cpu);
\end { lstlisting}
See also: \cvCppCross { CascadeClassifier::detectMultiScale} .