10 .. ocv:struct:: gpu::HOGDescriptor
12 The class implements Histogram of Oriented Gradients ([Dalal2005]_) object detector. ::
14 struct CV_EXPORTS HOGDescriptor
16 enum { DEFAULT_WIN_SIGMA = -1 };
17 enum { DEFAULT_NLEVELS = 64 };
18 enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
20 HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16),
21 Size block_stride=Size(8, 8), Size cell_size=Size(8, 8),
22 int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA,
23 double threshold_L2hys=0.2, bool gamma_correction=true,
24 int nlevels=DEFAULT_NLEVELS);
26 size_t getDescriptorSize() const;
27 size_t getBlockHistogramSize() const;
29 void setSVMDetector(const vector<float>& detector);
31 static vector<float> getDefaultPeopleDetector();
32 static vector<float> getPeopleDetector48x96();
33 static vector<float> getPeopleDetector64x128();
35 void detect(const GpuMat& img, vector<Point>& found_locations,
36 double hit_threshold=0, Size win_stride=Size(),
39 void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
40 double hit_threshold=0, Size win_stride=Size(),
41 Size padding=Size(), double scale0=1.05,
42 int group_threshold=2);
44 void getDescriptors(const GpuMat& img, Size win_stride,
46 int descr_format=DESCR_FORMAT_COL_BY_COL);
54 double threshold_L2hys;
55 bool gamma_correction;
63 Interfaces of all methods are kept similar to the ``CPU HOG`` descriptor and detector analogues as much as possible.
67 gpu::HOGDescriptor::HOGDescriptor
68 -------------------------------------
69 Creates the ``HOG`` descriptor and detector.
71 .. ocv:function:: gpu::HOGDescriptor::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)
73 :param win_size: Detection window size. Align to block size and block stride.
75 :param block_size: Block size in pixels. Align to cell size. Only (16,16) is supported for now.
77 :param block_stride: Block stride. It must be a multiple of cell size.
79 :param cell_size: Cell size. Only (8, 8) is supported for now.
81 :param nbins: Number of bins. Only 9 bins per cell are supported for now.
83 :param win_sigma: Gaussian smoothing window parameter.
85 :param threshold_L2hys: L2-Hys normalization method shrinkage.
87 :param gamma_correction: Flag to specify whether the gamma correction preprocessing is required or not.
89 :param nlevels: Maximum number of detection window increases.
93 gpu::HOGDescriptor::getDescriptorSize
94 -----------------------------------------
95 Returns the number of coefficients required for the classification.
97 .. ocv:function:: size_t gpu::HOGDescriptor::getDescriptorSize() const
101 gpu::HOGDescriptor::getBlockHistogramSize
102 ---------------------------------------------
103 Returns the block histogram size.
105 .. ocv:function:: size_t gpu::HOGDescriptor::getBlockHistogramSize() const
109 gpu::HOGDescriptor::setSVMDetector
110 --------------------------------------
111 Sets coefficients for the linear SVM classifier.
113 .. ocv:function:: void gpu::HOGDescriptor::setSVMDetector(const vector<float>& detector)
117 gpu::HOGDescriptor::getDefaultPeopleDetector
118 ------------------------------------------------
119 Returns coefficients of the classifier trained for people detection (for default window size).
121 .. ocv:function:: static vector<float> gpu::HOGDescriptor::getDefaultPeopleDetector()
125 gpu::HOGDescriptor::getPeopleDetector48x96
126 ----------------------------------------------
127 Returns coefficients of the classifier trained for people detection (for 48x96 windows).
129 .. ocv:function:: static vector<float> gpu::HOGDescriptor::getPeopleDetector48x96()
133 gpu::HOGDescriptor::getPeopleDetector64x128
134 -----------------------------------------------
135 Returns coefficients of the classifier trained for people detection (for 64x128 windows).
137 .. ocv:function:: static vector<float> gpu::HOGDescriptor::getPeopleDetector64x128()
141 gpu::HOGDescriptor::detect
142 ------------------------------
143 Performs object detection without a multi-scale window.
145 .. ocv:function:: void gpu::HOGDescriptor::detect(const GpuMat& img, vector<Point>& found_locations, double hit_threshold=0, Size win_stride=Size(), Size padding=Size())
147 :param img: Source image. ``CV_8UC1`` and ``CV_8UC4`` types are supported for now.
149 :param found_locations: Left-top corner points of detected objects boundaries.
151 :param hit_threshold: Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specfied 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.
153 :param win_stride: Window stride. It must be a multiple of block stride.
155 :param padding: Mock parameter to keep the CPU interface compatibility. It must be (0,0).
159 gpu::HOGDescriptor::detectMultiScale
160 ----------------------------------------
161 Performs object detection with a multi-scale window.
163 .. ocv:function:: void gpu::HOGDescriptor::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)
165 :param img: Source image. See :ocv:func:`gpu::HOGDescriptor::detect` for type limitations.
167 :param found_locations: Detected objects boundaries.
169 :param hit_threshold: Threshold for the distance between features and SVM classifying plane. See :ocv:func:`gpu::HOGDescriptor::detect` for details.
171 :param win_stride: Window stride. It must be a multiple of block stride.
173 :param padding: Mock parameter to keep the CPU interface compatibility. It must be (0,0).
175 :param scale0: Coefficient of the detection window increase.
177 :param group_threshold: Coefficient to regulate the similarity threshold. When detected, some objects can be covered by many rectangles. 0 means not to perform grouping. See :ocv:func:`groupRectangles` .
181 gpu::HOGDescriptor::getDescriptors
182 --------------------------------------
183 Returns block descriptors computed for the whole image.
185 .. ocv:function:: void gpu::HOGDescriptor::getDescriptors(const GpuMat& img, Size win_stride, GpuMat& descriptors, int descr_format=DESCR_FORMAT_COL_BY_COL)
187 :param img: Source image. See :ocv:func:`gpu::HOGDescriptor::detect` for type limitations.
189 :param win_stride: Window stride. It must be a multiple of block stride.
191 :param descriptors: 2D array of descriptors.
193 :param descr_format: Descriptor storage format:
195 * **DESCR_FORMAT_ROW_BY_ROW** - Row-major order.
197 * **DESCR_FORMAT_COL_BY_COL** - Column-major order.
199 The function is mainly used to learn the classifier.
203 gpu::CascadeClassifier_GPU
204 --------------------------
205 .. ocv:class:: gpu::CascadeClassifier_GPU
207 Cascade classifier class used for object detection. Supports HAAR and LBP cascades. ::
209 class CV_EXPORTS CascadeClassifier_GPU
212 CascadeClassifier_GPU();
213 CascadeClassifier_GPU(const string& filename);
214 ~CascadeClassifier_GPU();
217 bool load(const string& filename);
220 /* Returns number of detected objects */
221 int detectMultiScale( const GpuMat& image, GpuMat& objectsBuf, double scaleFactor=1.2, int minNeighbors=4, Size minSize=Size());
222 int detectMultiScale( const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4);
224 /* Finds only the largest object. Special mode if training is required.*/
225 bool findLargestObject;
227 /* Draws rectangles in input image */
228 bool visualizeInPlace;
230 Size getClassifierSize() const;
235 gpu::CascadeClassifier_GPU::CascadeClassifier_GPU
236 -----------------------------------------------------
237 Loads the classifier from a file. Cascade type is detected automatically by constructor parameter.
239 .. ocv:function:: gpu::CascadeClassifier_GPU::CascadeClassifier_GPU(const string& filename)
241 :param filename: Name of the file from which the classifier is loaded. Only the old ``haar`` classifier (trained by the ``haar`` training application) and NVIDIA's ``nvbin`` are supported for HAAR and only new type of OpenCV XML cascade supported for LBP.
245 gpu::CascadeClassifier_GPU::empty
246 -------------------------------------
247 Checks whether the classifier is loaded or not.
249 .. ocv:function:: bool gpu::CascadeClassifier_GPU::empty() const
253 gpu::CascadeClassifier_GPU::load
254 ------------------------------------
255 Loads the classifier from a file. The previous content is destroyed.
257 .. ocv:function:: bool gpu::CascadeClassifier_GPU::load(const string& filename)
259 :param filename: Name of the file from which the classifier is loaded. Only the old ``haar`` classifier (trained by the ``haar`` training application) and NVIDIA's ``nvbin`` are supported for HAAR and only new type of OpenCV XML cascade supported for LBP.
262 gpu::CascadeClassifier_GPU::release
263 ---------------------------------------
264 Destroys the loaded classifier.
266 .. ocv:function:: void gpu::CascadeClassifier_GPU::release()
270 gpu::CascadeClassifier_GPU::detectMultiScale
271 ------------------------------------------------
272 Detects objects of different sizes in the input image.
274 .. ocv:function:: int gpu::CascadeClassifier_GPU::detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor=1.2, int minNeighbors=4, Size minSize=Size())
276 .. ocv:function:: int gpu::CascadeClassifier_GPU::detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4)
278 :param image: Matrix of type ``CV_8U`` containing an image where objects should be detected.
280 :param objectsBuf: Buffer to store detected objects (rectangles). If it is empty, it is allocated with the default size. If not empty, the function searches not more than N objects, where ``N = sizeof(objectsBufer's data)/sizeof(cv::Rect)``.
282 :param maxObjectSize: Maximum possible object size. Objects larger than that are ignored. Used for second signature and supported only for LBP cascades.
284 :param scaleFactor: Parameter specifying how much the image size is reduced at each image scale.
286 :param minNeighbors: Parameter specifying how many neighbors each candidate rectangle should have to retain it.
288 :param minSize: Minimum possible object size. Objects smaller than that are ignored.
290 The detected objects are returned as a list of rectangles.
292 The function returns the number of detected objects, so you can retrieve them as in the following example: ::
294 gpu::CascadeClassifier_GPU cascade_gpu(...);
296 Mat image_cpu = imread(...)
297 GpuMat image_gpu(image_cpu);
300 int detections_number = cascade_gpu.detectMultiScale( image_gpu,
301 objbuf, 1.2, minNeighbors);
304 // download only detected number of rectangles
305 objbuf.colRange(0, detections_number).download(obj_host);
307 Rect* faces = obj_host.ptr<Rect>();
308 for(int i = 0; i < detections_num; ++i)
309 cv::rectangle(image_cpu, faces[i], Scalar(255));
311 imshow("Faces", image_cpu);
314 .. seealso:: :ocv:func:`CascadeClassifier::detectMultiScale`
318 .. [Dalal2005] Navneet Dalal and Bill Triggs. *Histogram of oriented gradients for human detection*. 2005.