1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef OPENCV_CUDAIMGPROC_HPP
44 #define OPENCV_CUDAIMGPROC_HPP
45 
46 #ifndef __cplusplus
47 #  error cudaimgproc.hpp header must be compiled as C++
48 #endif
49 
50 #include "opencv2/core/cuda.hpp"
51 #include "opencv2/imgproc.hpp"
52 
53 /**
54   @addtogroup cuda
55   @{
56     @defgroup cudaimgproc Image Processing
57     @{
58       @defgroup cudaimgproc_color Color space processing
59       @defgroup cudaimgproc_hist Histogram Calculation
60       @defgroup cudaimgproc_hough Hough Transform
61       @defgroup cudaimgproc_feature Feature Detection
62     @}
63   @}
64 */
65 
66 namespace cv { namespace cuda {
67 
68 //! @addtogroup cudaimgproc
69 //! @{
70 
71 /////////////////////////// Color Processing ///////////////////////////
72 
73 //! @addtogroup cudaimgproc_color
74 //! @{
75 
76 /** @brief Converts an image from one color space to another.
77 
78 @param src Source image with CV_8U , CV_16U , or CV_32F depth and 1, 3, or 4 channels.
79 @param dst Destination image.
80 @param code Color space conversion code. For details, see cvtColor .
81 @param dcn Number of channels in the destination image. If the parameter is 0, the number of the
82 channels is derived automatically from src and the code .
83 @param stream Stream for the asynchronous version.
84 
85 3-channel color spaces (like HSV, XYZ, and so on) can be stored in a 4-channel image for better
86 performance.
87 
88 @sa cvtColor
89  */
90 CV_EXPORTS_W void cvtColor(InputArray src, OutputArray dst, int code, int dcn = 0, Stream& stream = Stream::Null());
91 
92 enum DemosaicTypes
93 {
94     //! Bayer Demosaicing (Malvar, He, and Cutler)
95     COLOR_BayerBG2BGR_MHT = 256,
96     COLOR_BayerGB2BGR_MHT = 257,
97     COLOR_BayerRG2BGR_MHT = 258,
98     COLOR_BayerGR2BGR_MHT = 259,
99 
100     COLOR_BayerBG2RGB_MHT = COLOR_BayerRG2BGR_MHT,
101     COLOR_BayerGB2RGB_MHT = COLOR_BayerGR2BGR_MHT,
102     COLOR_BayerRG2RGB_MHT = COLOR_BayerBG2BGR_MHT,
103     COLOR_BayerGR2RGB_MHT = COLOR_BayerGB2BGR_MHT,
104 
105     COLOR_BayerBG2GRAY_MHT = 260,
106     COLOR_BayerGB2GRAY_MHT = 261,
107     COLOR_BayerRG2GRAY_MHT = 262,
108     COLOR_BayerGR2GRAY_MHT = 263
109 };
110 
111 /** @brief Converts an image from Bayer pattern to RGB or grayscale.
112 
113 @param src Source image (8-bit or 16-bit single channel).
114 @param dst Destination image.
115 @param code Color space conversion code (see the description below).
116 @param dcn Number of channels in the destination image. If the parameter is 0, the number of the
117 channels is derived automatically from src and the code .
118 @param stream Stream for the asynchronous version.
119 
120 The function can do the following transformations:
121 
122 -   Demosaicing using bilinear interpolation
123 
124     > -   COLOR_BayerBG2GRAY , COLOR_BayerGB2GRAY , COLOR_BayerRG2GRAY , COLOR_BayerGR2GRAY
125     > -   COLOR_BayerBG2BGR , COLOR_BayerGB2BGR , COLOR_BayerRG2BGR , COLOR_BayerGR2BGR
126 
127 -   Demosaicing using Malvar-He-Cutler algorithm (@cite MHT2011)
128 
129     > -   COLOR_BayerBG2GRAY_MHT , COLOR_BayerGB2GRAY_MHT , COLOR_BayerRG2GRAY_MHT ,
130     >     COLOR_BayerGR2GRAY_MHT
131     > -   COLOR_BayerBG2BGR_MHT , COLOR_BayerGB2BGR_MHT , COLOR_BayerRG2BGR_MHT ,
132     >     COLOR_BayerGR2BGR_MHT
133 
134 @sa cvtColor
135  */
136 CV_EXPORTS_W void demosaicing(InputArray src, OutputArray dst, int code, int dcn = -1, Stream& stream = Stream::Null());
137 
138 /** @brief Exchanges the color channels of an image in-place.
139 
140 @param image Source image. Supports only CV_8UC4 type.
141 @param dstOrder Integer array describing how channel values are permutated. The n-th entry of the
142 array contains the number of the channel that is stored in the n-th channel of the output image.
143 E.g. Given an RGBA image, aDstOrder = [3,2,1,0] converts this to ABGR channel order.
144 @param stream Stream for the asynchronous version.
145 
146 The methods support arbitrary permutations of the original channels, including replication.
147  */
148 CV_EXPORTS void swapChannels(InputOutputArray image, const int dstOrder[4], Stream& stream = Stream::Null());
149 
150 /** @brief Routines for correcting image color gamma.
151 
152 @param src Source image (3- or 4-channel 8 bit).
153 @param dst Destination image.
154 @param forward true for forward gamma correction or false for inverse gamma correction.
155 @param stream Stream for the asynchronous version.
156  */
157 CV_EXPORTS_W void gammaCorrection(InputArray src, OutputArray dst, bool forward = true, Stream& stream = Stream::Null());
158 
159 enum AlphaCompTypes { ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_PLUS, ALPHA_OVER_PREMUL, ALPHA_IN_PREMUL, ALPHA_OUT_PREMUL,
160        ALPHA_ATOP_PREMUL, ALPHA_XOR_PREMUL, ALPHA_PLUS_PREMUL, ALPHA_PREMUL};
161 
162 /** @brief Composites two images using alpha opacity values contained in each image.
163 
164 @param img1 First image. Supports CV_8UC4 , CV_16UC4 , CV_32SC4 and CV_32FC4 types.
165 @param img2 Second image. Must have the same size and the same type as img1 .
166 @param dst Destination image.
167 @param alpha_op Flag specifying the alpha-blending operation:
168 -   **ALPHA_OVER**
169 -   **ALPHA_IN**
170 -   **ALPHA_OUT**
171 -   **ALPHA_ATOP**
172 -   **ALPHA_XOR**
173 -   **ALPHA_PLUS**
174 -   **ALPHA_OVER_PREMUL**
175 -   **ALPHA_IN_PREMUL**
176 -   **ALPHA_OUT_PREMUL**
177 -   **ALPHA_ATOP_PREMUL**
178 -   **ALPHA_XOR_PREMUL**
179 -   **ALPHA_PLUS_PREMUL**
180 -   **ALPHA_PREMUL**
181 @param stream Stream for the asynchronous version.
182 
183 @note
184    -   An example demonstrating the use of alphaComp can be found at
185         opencv_source_code/samples/gpu/alpha_comp.cpp
186  */
187 CV_EXPORTS_W void alphaComp(InputArray img1, InputArray img2, OutputArray dst, int alpha_op, Stream& stream = Stream::Null());
188 
189 //! @} cudaimgproc_color
190 
191 ////////////////////////////// Histogram ///////////////////////////////
192 
193 //! @addtogroup cudaimgproc_hist
194 //! @{
195 
196 /** @brief Calculates histogram for one channel 8-bit image.
197 
198 @param src Source image with CV_8UC1 type.
199 @param hist Destination histogram with one row, 256 columns, and the CV_32SC1 type.
200 @param stream Stream for the asynchronous version.
201  */
202 CV_EXPORTS_W void calcHist(InputArray src, OutputArray hist, Stream& stream = Stream::Null());
203 
204 /** @brief Calculates histogram for one channel 8-bit image confined in given mask.
205 
206 @param src Source image with CV_8UC1 type.
207 @param hist Destination histogram with one row, 256 columns, and the CV_32SC1 type.
208 @param mask A mask image same size as src and of type CV_8UC1.
209 @param stream Stream for the asynchronous version.
210  */
211 CV_EXPORTS_W void calcHist(InputArray src, InputArray mask, OutputArray hist, Stream& stream = Stream::Null());
212 
213 /** @brief Equalizes the histogram of a grayscale image.
214 
215 @param src Source image with CV_8UC1 type.
216 @param dst Destination image.
217 @param stream Stream for the asynchronous version.
218 
219 @sa equalizeHist
220  */
221 CV_EXPORTS_W void equalizeHist(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
222 
223 /** @brief Base class for Contrast Limited Adaptive Histogram Equalization. :
224  */
225 class CV_EXPORTS_W CLAHE : public cv::CLAHE
226 {
227 public:
228     using cv::CLAHE::apply;
229     /** @brief Equalizes the histogram of a grayscale image using Contrast Limited Adaptive Histogram Equalization.
230 
231     @param src Source image with CV_8UC1 type.
232     @param dst Destination image.
233     @param stream Stream for the asynchronous version.
234      */
235     CV_WRAP virtual void apply(InputArray src, OutputArray dst, Stream& stream) = 0;
236 };
237 
238 /** @brief Creates implementation for cuda::CLAHE .
239 
240 @param clipLimit Threshold for contrast limiting.
241 @param tileGridSize Size of grid for histogram equalization. Input image will be divided into
242 equally sized rectangular tiles. tileGridSize defines the number of tiles in row and column.
243  */
244 CV_EXPORTS_W Ptr<cuda::CLAHE> createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8));
245 
246 /** @brief Computes levels with even distribution.
247 
248 @param levels Destination array. levels has 1 row, nLevels columns, and the CV_32SC1 type.
249 @param nLevels Number of computed levels. nLevels must be at least 2.
250 @param lowerLevel Lower boundary value of the lowest level.
251 @param upperLevel Upper boundary value of the greatest level.
252 @param stream Stream for the asynchronous version.
253  */
254 CV_EXPORTS_W void evenLevels(OutputArray levels, int nLevels, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
255 
256 /** @brief Calculates a histogram with evenly distributed bins.
257 
258 @param src Source image. CV_8U, CV_16U, or CV_16S depth and 1 or 4 channels are supported. For
259 a four-channel image, all channels are processed separately.
260 @param hist Destination histogram with one row, histSize columns, and the CV_32S type.
261 @param histSize Size of the histogram.
262 @param lowerLevel Lower boundary of lowest-level bin.
263 @param upperLevel Upper boundary of highest-level bin.
264 @param stream Stream for the asynchronous version.
265  */
266 CV_EXPORTS_W void histEven(InputArray src, OutputArray hist, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
267 /** @overload */
268 CV_EXPORTS_W void histEven(InputArray src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream = Stream::Null());
269 
270 /** @brief Calculates a histogram with bins determined by the levels array.
271 
272 @param src Source image. CV_8U , CV_16U , or CV_16S depth and 1 or 4 channels are supported.
273 For a four-channel image, all channels are processed separately.
274 @param hist Destination histogram with one row, (levels.cols-1) columns, and the CV_32SC1 type.
275 @param levels Number of levels in the histogram.
276 @param stream Stream for the asynchronous version.
277  */
278 CV_EXPORTS_W void histRange(InputArray src, OutputArray hist, InputArray levels, Stream& stream = Stream::Null());
279 /** @overload */
280 CV_EXPORTS_W void histRange(InputArray src, GpuMat hist[4], const GpuMat levels[4], Stream& stream = Stream::Null());
281 
282 //! @} cudaimgproc_hist
283 
284 //////////////////////////////// Canny ////////////////////////////////
285 
286 /** @brief Base class for Canny Edge Detector. :
287  */
288 class CV_EXPORTS_W CannyEdgeDetector : public Algorithm
289 {
290 public:
291     /** @brief Finds edges in an image using the @cite Canny86 algorithm.
292 
293     @param image Single-channel 8-bit input image.
294     @param edges Output edge map. It has the same size and type as image.
295     @param stream Stream for the asynchronous version.
296      */
297     CV_WRAP virtual void detect(InputArray image, OutputArray edges, Stream& stream = Stream::Null()) = 0;
298     /** @overload
299     @param dx First derivative of image in the vertical direction. Support only CV_32S type.
300     @param dy First derivative of image in the horizontal direction. Support only CV_32S type.
301     @param edges Output edge map. It has the same size and type as image.
302     @param stream Stream for the asynchronous version.
303     */
304     CV_WRAP virtual void detect(InputArray dx, InputArray dy, OutputArray edges, Stream& stream = Stream::Null()) = 0;
305 
306     CV_WRAP virtual void setLowThreshold(double low_thresh) = 0;
307     CV_WRAP virtual double getLowThreshold() const = 0;
308 
309     CV_WRAP virtual void setHighThreshold(double high_thresh) = 0;
310     CV_WRAP virtual double getHighThreshold() const = 0;
311 
312     CV_WRAP virtual void setAppertureSize(int apperture_size) = 0;
313     CV_WRAP virtual int getAppertureSize() const = 0;
314 
315     CV_WRAP virtual void setL2Gradient(bool L2gradient) = 0;
316     CV_WRAP virtual bool getL2Gradient() const = 0;
317 };
318 
319 /** @brief Creates implementation for cuda::CannyEdgeDetector .
320 
321 @param low_thresh First threshold for the hysteresis procedure.
322 @param high_thresh Second threshold for the hysteresis procedure.
323 @param apperture_size Aperture size for the Sobel operator.
324 @param L2gradient Flag indicating whether a more accurate \f$L_2\f$ norm
325 \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to compute the image gradient magnitude (
326 L2gradient=true ), or a faster default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( L2gradient=false
327 ).
328  */
329 CV_EXPORTS_W Ptr<CannyEdgeDetector> createCannyEdgeDetector(double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
330 
331 /////////////////////////// Hough Transform ////////////////////////////
332 
333 //////////////////////////////////////
334 // HoughLines
335 
336 //! @addtogroup cudaimgproc_hough
337 //! @{
338 
339 /** @brief Base class for lines detector algorithm. :
340  */
341 class CV_EXPORTS_W HoughLinesDetector : public Algorithm
342 {
343 public:
344     /** @brief Finds lines in a binary image using the classical Hough transform.
345 
346     @param src 8-bit, single-channel binary source image.
347     @param lines Output vector of lines. Each line is represented by a two-element vector
348     \f$(\rho, \theta)\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of
349     the image). \f$\theta\f$ is the line rotation angle in radians (
350     \f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ).
351     @param stream Stream for the asynchronous version.
352 
353     @sa HoughLines
354      */
355     CV_WRAP virtual void detect(InputArray src, OutputArray lines, Stream& stream = Stream::Null()) = 0;
356 
357     /** @brief Downloads results from cuda::HoughLinesDetector::detect to host memory.
358 
359     @param d_lines Result of cuda::HoughLinesDetector::detect .
360     @param h_lines Output host array.
361     @param h_votes Optional output array for line's votes.
362     @param stream Stream for the asynchronous version.
363      */
364     CV_WRAP virtual void downloadResults(InputArray d_lines, OutputArray h_lines, OutputArray h_votes = noArray(), Stream& stream = Stream::Null()) = 0;
365 
366     CV_WRAP virtual void setRho(float rho) = 0;
367     CV_WRAP virtual float getRho() const = 0;
368 
369     CV_WRAP virtual void setTheta(float theta) = 0;
370     CV_WRAP virtual float getTheta() const = 0;
371 
372     CV_WRAP virtual void setThreshold(int threshold) = 0;
373     CV_WRAP virtual int getThreshold() const = 0;
374 
375     CV_WRAP virtual void setDoSort(bool doSort) = 0;
376     CV_WRAP virtual bool getDoSort() const = 0;
377 
378     CV_WRAP virtual void setMaxLines(int maxLines) = 0;
379     CV_WRAP virtual int getMaxLines() const = 0;
380 };
381 
382 /** @brief Creates implementation for cuda::HoughLinesDetector .
383 
384 @param rho Distance resolution of the accumulator in pixels.
385 @param theta Angle resolution of the accumulator in radians.
386 @param threshold Accumulator threshold parameter. Only those lines are returned that get enough
387 votes ( \f$>\texttt{threshold}\f$ ).
388 @param doSort Performs lines sort by votes.
389 @param maxLines Maximum number of output lines.
390  */
391 CV_EXPORTS_W Ptr<HoughLinesDetector> createHoughLinesDetector(float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
392 
393 
394 //////////////////////////////////////
395 // HoughLinesP
396 
397 /** @brief Base class for line segments detector algorithm. :
398  */
399 class CV_EXPORTS_W HoughSegmentDetector : public Algorithm
400 {
401 public:
402     /** @brief Finds line segments in a binary image using the probabilistic Hough transform.
403 
404     @param src 8-bit, single-channel binary source image.
405     @param lines Output vector of lines. Each line is represented by a 4-element vector
406     \f$(x_1, y_1, x_2, y_2)\f$ , where \f$(x_1,y_1)\f$ and \f$(x_2, y_2)\f$ are the ending points of each detected
407     line segment.
408     @param stream Stream for the asynchronous version.
409 
410     @sa HoughLinesP
411      */
412     CV_WRAP virtual void detect(InputArray src, OutputArray lines, Stream& stream = Stream::Null()) = 0;
413 
414     CV_WRAP virtual void setRho(float rho) = 0;
415     CV_WRAP virtual float getRho() const = 0;
416 
417     CV_WRAP virtual void setTheta(float theta) = 0;
418     CV_WRAP virtual float getTheta() const = 0;
419 
420     CV_WRAP virtual void setMinLineLength(int minLineLength) = 0;
421     CV_WRAP virtual int getMinLineLength() const = 0;
422 
423     CV_WRAP virtual void setMaxLineGap(int maxLineGap) = 0;
424     CV_WRAP virtual int getMaxLineGap() const = 0;
425 
426     CV_WRAP virtual void setMaxLines(int maxLines) = 0;
427     CV_WRAP virtual int getMaxLines() const = 0;
428 };
429 
430 /** @brief Creates implementation for cuda::HoughSegmentDetector .
431 
432 @param rho Distance resolution of the accumulator in pixels.
433 @param theta Angle resolution of the accumulator in radians.
434 @param minLineLength Minimum line length. Line segments shorter than that are rejected.
435 @param maxLineGap Maximum allowed gap between points on the same line to link them.
436 @param maxLines Maximum number of output lines.
437  */
438 CV_EXPORTS_W Ptr<HoughSegmentDetector> createHoughSegmentDetector(float rho, float theta, int minLineLength, int maxLineGap, int maxLines = 4096);
439 
440 //////////////////////////////////////
441 // HoughCircles
442 
443 /** @brief Base class for circles detector algorithm. :
444  */
445 class CV_EXPORTS_W HoughCirclesDetector : public Algorithm
446 {
447 public:
448     /** @brief Finds circles in a grayscale image using the Hough transform.
449 
450     @param src 8-bit, single-channel grayscale input image.
451     @param circles Output vector of found circles. Each vector is encoded as a 3-element
452     floating-point vector \f$(x, y, radius)\f$ .
453     @param stream Stream for the asynchronous version.
454 
455     @sa HoughCircles
456      */
457     CV_WRAP virtual void detect(InputArray src, OutputArray circles, Stream& stream = Stream::Null()) = 0;
458 
459     CV_WRAP virtual void setDp(float dp) = 0;
460     CV_WRAP virtual float getDp() const = 0;
461 
462     CV_WRAP virtual void setMinDist(float minDist) = 0;
463     CV_WRAP virtual float getMinDist() const = 0;
464 
465     CV_WRAP virtual void setCannyThreshold(int cannyThreshold) = 0;
466     CV_WRAP virtual int getCannyThreshold() const = 0;
467 
468     CV_WRAP virtual void setVotesThreshold(int votesThreshold) = 0;
469     CV_WRAP virtual int getVotesThreshold() const = 0;
470 
471     CV_WRAP virtual void setMinRadius(int minRadius) = 0;
472     CV_WRAP virtual int getMinRadius() const = 0;
473 
474     CV_WRAP virtual void setMaxRadius(int maxRadius) = 0;
475     CV_WRAP virtual int getMaxRadius() const = 0;
476 
477     CV_WRAP virtual void setMaxCircles(int maxCircles) = 0;
478     CV_WRAP virtual int getMaxCircles() const = 0;
479 };
480 
481 /** @brief Creates implementation for cuda::HoughCirclesDetector .
482 
483 @param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if
484 dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has
485 half as big width and height.
486 @param minDist Minimum distance between the centers of the detected circles. If the parameter is
487 too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is
488 too large, some circles may be missed.
489 @param cannyThreshold The higher threshold of the two passed to Canny edge detector (the lower one
490 is twice smaller).
491 @param votesThreshold The accumulator threshold for the circle centers at the detection stage. The
492 smaller it is, the more false circles may be detected.
493 @param minRadius Minimum circle radius.
494 @param maxRadius Maximum circle radius.
495 @param maxCircles Maximum number of output circles.
496  */
497 CV_EXPORTS_W Ptr<HoughCirclesDetector> createHoughCirclesDetector(float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096);
498 
499 //////////////////////////////////////
500 // GeneralizedHough
501 
502 /** @brief Creates implementation for generalized hough transform from @cite Ballard1981 .
503  */
504 CV_EXPORTS_W Ptr<GeneralizedHoughBallard> createGeneralizedHoughBallard();
505 
506 /** @brief Creates implementation for generalized hough transform from @cite Guil1999 .
507  */
508 CV_EXPORTS_W Ptr<GeneralizedHoughGuil> createGeneralizedHoughGuil();
509 
510 //! @} cudaimgproc_hough
511 
512 ////////////////////////// Corners Detection ///////////////////////////
513 
514 //! @addtogroup cudaimgproc_feature
515 //! @{
516 
517 /** @brief Base class for Cornerness Criteria computation. :
518  */
519 class CV_EXPORTS_W CornernessCriteria : public Algorithm
520 {
521 public:
522     /** @brief Computes the cornerness criteria at each image pixel.
523 
524     @param src Source image.
525     @param dst Destination image containing cornerness values. It will have the same size as src and
526     CV_32FC1 type.
527     @param stream Stream for the asynchronous version.
528      */
529     CV_WRAP virtual void compute(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) = 0;
530 };
531 
532 /** @brief Creates implementation for Harris cornerness criteria.
533 
534 @param srcType Input source type. Only CV_8UC1 and CV_32FC1 are supported for now.
535 @param blockSize Neighborhood size.
536 @param ksize Aperture parameter for the Sobel operator.
537 @param k Harris detector free parameter.
538 @param borderType Pixel extrapolation method. Only BORDER_REFLECT101 and BORDER_REPLICATE are
539 supported for now.
540 
541 @sa cornerHarris
542  */
543 CV_EXPORTS_W Ptr<CornernessCriteria> createHarrisCorner(int srcType, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
544 
545 /** @brief Creates implementation for the minimum eigen value of a 2x2 derivative covariation matrix (the
546 cornerness criteria).
547 
548 @param srcType Input source type. Only CV_8UC1 and CV_32FC1 are supported for now.
549 @param blockSize Neighborhood size.
550 @param ksize Aperture parameter for the Sobel operator.
551 @param borderType Pixel extrapolation method. Only BORDER_REFLECT101 and BORDER_REPLICATE are
552 supported for now.
553 
554 @sa cornerMinEigenVal
555  */
556 CV_EXPORTS_W Ptr<CornernessCriteria> createMinEigenValCorner(int srcType, int blockSize, int ksize, int borderType = BORDER_REFLECT101);
557 
558 ////////////////////////// Corners Detection ///////////////////////////
559 
560 /** @brief Base class for Corners Detector. :
561  */
562 class CV_EXPORTS_W CornersDetector : public Algorithm
563 {
564 public:
565     /** @brief Determines strong corners on an image.
566 
567     @param image Input 8-bit or floating-point 32-bit, single-channel image.
568     @param corners Output vector of detected corners (1-row matrix with CV_32FC2 type with corners
569     positions).
570     @param mask Optional region of interest. If the image is not empty (it needs to have the type
571     CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
572     @param stream Stream for the asynchronous version.
573      */
574     CV_WRAP virtual void detect(InputArray image, OutputArray corners, InputArray mask = noArray(), Stream& stream = Stream::Null()) = 0;
575 };
576 
577 /** @brief Creates implementation for cuda::CornersDetector .
578 
579 @param srcType Input source type. Only CV_8UC1 and CV_32FC1 are supported for now.
580 @param maxCorners Maximum number of corners to return. If there are more corners than are found,
581 the strongest of them is returned.
582 @param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
583 parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
584 (see cornerMinEigenVal ) or the Harris function response (see cornerHarris ). The corners with the
585 quality measure less than the product are rejected. For example, if the best corner has the
586 quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
587 less than 15 are rejected.
588 @param minDistance Minimum possible Euclidean distance between the returned corners.
589 @param blockSize Size of an average block for computing a derivative covariation matrix over each
590 pixel neighborhood. See cornerEigenValsAndVecs .
591 @param useHarrisDetector Parameter indicating whether to use a Harris detector (see cornerHarris)
592 or cornerMinEigenVal.
593 @param harrisK Free parameter of the Harris detector.
594  */
595 CV_EXPORTS_W Ptr<CornersDetector> createGoodFeaturesToTrackDetector(int srcType, int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0,
596                                                                   int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04);
597 
598 //! @} cudaimgproc_feature
599 
600 
601 ///////////////////////////// Mean Shift //////////////////////////////
602 
603 /** @brief Performs mean-shift filtering for each point of the source image.
604 
605 @param src Source image. Only CV_8UC4 images are supported for now.
606 @param dst Destination image containing the color of mapped points. It has the same size and type
607 as src .
608 @param sp Spatial window radius.
609 @param sr Color window radius.
610 @param criteria Termination criteria. See TermCriteria.
611 @param stream Stream for the asynchronous version.
612 
613 It maps each point of the source image into another point. As a result, you have a new color and new
614 position of each point.
615  */
616 CV_EXPORTS_W void meanShiftFiltering(InputArray src, OutputArray dst, int sp, int sr,
617                                    TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1),
618                                    Stream& stream = Stream::Null());
619 
620 /** @brief Performs a mean-shift procedure and stores information about processed points (their colors and
621 positions) in two images.
622 
623 @param src Source image. Only CV_8UC4 images are supported for now.
624 @param dstr Destination image containing the color of mapped points. The size and type is the same
625 as src .
626 @param dstsp Destination image containing the position of mapped points. The size is the same as
627 src size. The type is CV_16SC2 .
628 @param sp Spatial window radius.
629 @param sr Color window radius.
630 @param criteria Termination criteria. See TermCriteria.
631 @param stream Stream for the asynchronous version.
632 
633 @sa cuda::meanShiftFiltering
634  */
635 CV_EXPORTS_W void meanShiftProc(InputArray src, OutputArray dstr, OutputArray dstsp, int sp, int sr,
636                               TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1),
637                               Stream& stream = Stream::Null());
638 
639 /** @brief Performs a mean-shift segmentation of the source image and eliminates small segments.
640 
641 @param src Source image. Only CV_8UC4 images are supported for now.
642 @param dst Segmented image with the same size and type as src (host or gpu memory).
643 @param sp Spatial window radius.
644 @param sr Color window radius.
645 @param minsize Minimum segment size. Smaller segments are merged.
646 @param criteria Termination criteria. See TermCriteria.
647 @param stream Stream for the asynchronous version.
648  */
649 CV_EXPORTS_W void meanShiftSegmentation(InputArray src, OutputArray dst, int sp, int sr, int minsize,
650                                       TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1),
651                                       Stream& stream = Stream::Null());
652 
653 /////////////////////////// Match Template ////////////////////////////
654 
655 /** @brief Base class for Template Matching. :
656  */
657 class CV_EXPORTS_W TemplateMatching : public Algorithm
658 {
659 public:
660     /** @brief Computes a proximity map for a raster template and an image where the template is searched for.
661 
662     @param image Source image.
663     @param templ Template image with the size and type the same as image .
664     @param result Map containing comparison results ( CV_32FC1 ). If image is *W x H* and templ is *w
665     x h*, then result must be *W-w+1 x H-h+1*.
666     @param stream Stream for the asynchronous version.
667      */
668     CV_WRAP virtual void match(InputArray image, InputArray templ, OutputArray result, Stream& stream = Stream::Null()) = 0;
669 };
670 
671 /** @brief Creates implementation for cuda::TemplateMatching .
672 
673 @param srcType Input source type. CV_32F and CV_8U depth images (1..4 channels) are supported
674 for now.
675 @param method Specifies the way to compare the template with the image.
676 @param user_block_size You can use field user_block_size to set specific block size. If you
677 leave its default value Size(0,0) then automatic estimation of block size will be used (which is
678 optimized for speed). By varying user_block_size you can reduce memory requirements at the cost
679 of speed.
680 
681 The following methods are supported for the CV_8U depth images for now:
682 
683 -   CV_TM_SQDIFF
684 -   CV_TM_SQDIFF_NORMED
685 -   CV_TM_CCORR
686 -   CV_TM_CCORR_NORMED
687 -   CV_TM_CCOEFF
688 -   CV_TM_CCOEFF_NORMED
689 
690 The following methods are supported for the CV_32F images for now:
691 
692 -   CV_TM_SQDIFF
693 -   CV_TM_CCORR
694 
695 @sa matchTemplate
696  */
697 CV_EXPORTS_W Ptr<TemplateMatching> createTemplateMatching(int srcType, int method, Size user_block_size = Size());
698 
699 ////////////////////////// Bilateral Filter ///////////////////////////
700 
701 /** @brief Performs bilateral filtering of passed image
702 
703 @param src Source image. Supports only (channels != 2 && depth() != CV_8S && depth() != CV_32S
704 && depth() != CV_64F).
705 @param dst Destination imagwe.
706 @param kernel_size Kernel window size.
707 @param sigma_color Filter sigma in the color space.
708 @param sigma_spatial Filter sigma in the coordinate space.
709 @param borderMode Border type. See borderInterpolate for details. BORDER_REFLECT101 ,
710 BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.
711 @param stream Stream for the asynchronous version.
712 
713 @sa bilateralFilter
714  */
715 CV_EXPORTS_W void bilateralFilter(InputArray src, OutputArray dst, int kernel_size, float sigma_color, float sigma_spatial,
716                                 int borderMode = BORDER_DEFAULT, Stream& stream = Stream::Null());
717 
718 ///////////////////////////// Blending ////////////////////////////////
719 
720 /** @brief Performs linear blending of two images.
721 
722 @param img1 First image. Supports only CV_8U and CV_32F depth.
723 @param img2 Second image. Must have the same size and the same type as img1 .
724 @param weights1 Weights for first image. Must have tha same size as img1 . Supports only CV_32F
725 type.
726 @param weights2 Weights for second image. Must have tha same size as img2 . Supports only CV_32F
727 type.
728 @param result Destination image.
729 @param stream Stream for the asynchronous version.
730  */
731 CV_EXPORTS_W void blendLinear(InputArray img1, InputArray img2, InputArray weights1, InputArray weights2,
732                             OutputArray result, Stream& stream = Stream::Null());
733 
734 //! @}
735 
736 }} // namespace cv { namespace cuda {
737 
738 #endif /* OPENCV_CUDAIMGPROC_HPP */
739