gpu.hpp 9.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
A
Andrey Kamaev 已提交
25
//     and/or other materials provided with the distribution.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef __OPENCV_GPU_HPP__
#define __OPENCV_GPU_HPP__

46 47
#ifndef __cplusplus
#  error gpu.hpp header must be compiled as C++
V
Vladislav Vinogradov 已提交
48 49
#endif

50
#include "opencv2/core/gpu.hpp"
V
Vladislav Vinogradov 已提交
51

52 53
#if !defined(__OPENCV_BUILD) && !defined(OPENCV_GPU_SKIP_INCLUDE)
    #include "opencv2/opencv_modules.hpp"
54

55 56 57
    #ifdef HAVE_OPENCV_GPUARITHM
        #include "opencv2/gpuarithm.hpp"
    #endif
58

59 60 61
    #ifdef HAVE_OPENCV_GPUWARPING
        #include "opencv2/gpuwarping.hpp"
    #endif
62

63 64 65
    #ifdef HAVE_OPENCV_GPUFILTERS
        #include "opencv2/gpufilters.hpp"
    #endif
66

67 68 69
    #ifdef HAVE_OPENCV_GPUIMGPROC
        #include "opencv2/gpuimgproc.hpp"
    #endif
70

71 72 73
    #ifdef HAVE_OPENCV_GPUFEATURES2D
        #include "opencv2/gpufeatures2d.hpp"
    #endif
74

75 76 77
    #ifdef HAVE_OPENCV_GPUOPTFLOW
        #include "opencv2/gpuoptflow.hpp"
    #endif
78

79 80 81
    #ifdef HAVE_OPENCV_GPUBGSEGM
        #include "opencv2/gpubgsegm.hpp"
    #endif
82

83 84 85
    #ifdef HAVE_OPENCV_GPUSTEREO
        #include "opencv2/gpustereo.hpp"
    #endif
86

87 88 89 90
    #ifdef HAVE_OPENCV_GPUCODEC
        #include "opencv2/gpucodec.hpp"
    #endif
#endif
91

92
namespace cv { namespace gpu {
93

94
//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
95

96
struct CV_EXPORTS HOGConfidence
97
{
98 99 100 101
   double scale;
   std::vector<Point> locations;
   std::vector<double> confidences;
   std::vector<double> part_scores[4];
102 103
};

104
struct CV_EXPORTS HOGDescriptor
105
{
106 107 108
    enum { DEFAULT_WIN_SIGMA = -1 };
    enum { DEFAULT_NLEVELS = 64 };
    enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
109

110 111 112 113 114
    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);
115

116 117
    size_t getDescriptorSize() const;
    size_t getBlockHistogramSize() const;
118

119
    void setSVMDetector(const std::vector<float>& detector);
120

121 122 123
    static std::vector<float> getDefaultPeopleDetector();
    static std::vector<float> getPeopleDetector48x96();
    static std::vector<float> getPeopleDetector64x128();
124

125 126 127
    void detect(const GpuMat& img, std::vector<Point>& found_locations,
                double hit_threshold=0, Size win_stride=Size(),
                Size padding=Size());
128

129 130 131 132
    void detectMultiScale(const GpuMat& img, std::vector<Rect>& found_locations,
                          double hit_threshold=0, Size win_stride=Size(),
                          Size padding=Size(), double scale0=1.05,
                          int group_threshold=2);
133

134 135
    void computeConfidence(const GpuMat& img, std::vector<Point>& hits, double hit_threshold,
                                                Size win_stride, Size padding, std::vector<Point>& locations, std::vector<double>& confidences);
136

137 138 139
    void computeConfidenceMultiScale(const GpuMat& img, std::vector<Rect>& found_locations,
                                                                    double hit_threshold, Size win_stride, Size padding,
                                                                    std::vector<HOGConfidence> &conf_out, int group_threshold);
140

141 142 143
    void getDescriptors(const GpuMat& img, Size win_stride,
                        GpuMat& descriptors,
                        int descr_format=DESCR_FORMAT_COL_BY_COL);
144

145 146 147 148 149 150 151 152 153
    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;
V
Vladislav Vinogradov 已提交
154

155 156 157
protected:
    void computeBlockHistograms(const GpuMat& img);
    void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle);
158

159 160
    double getWinSigma() const;
    bool checkDetectorSize() const;
161

162 163
    static int numPartsWithin(int size, int part_size, int stride);
    static Size numPartsWithin(Size size, Size part_size, Size stride);
164

165 166 167
    // Coefficients of the separating plane
    float free_coef;
    GpuMat detector;
168

169 170 171
    // Results of the last classification step
    GpuMat labels, labels_buf;
    Mat labels_host;
V
Vladislav Vinogradov 已提交
172

173 174
    // Results of the last histogram evaluation step
    GpuMat block_hists, block_hists_buf;
175

176 177
    // Gradients conputation results
    GpuMat grad, qangle, grad_buf, qangle_buf;
178

179 180 181
    // returns subbuffer with required size, reallocates buffer if nessesary.
    static GpuMat getBuffer(const Size& sz, int type, GpuMat& buf);
    static GpuMat getBuffer(int rows, int cols, int type, GpuMat& buf);
182

183
    std::vector<GpuMat> image_scales;
184 185
};

186
//////////////////////////// CascadeClassifier ////////////////////////////
187

188 189
// The cascade classifier class for object detection: supports old haar and new lbp xlm formats and nvbin for haar cascades olny.
class CV_EXPORTS CascadeClassifier_GPU
190 191
{
public:
192 193 194
    CascadeClassifier_GPU();
    CascadeClassifier_GPU(const String& filename);
    ~CascadeClassifier_GPU();
195

196 197
    bool empty() const;
    bool load(const String& filename);
198 199
    void release();

200 201 202
    /* returns number of detected objects */
    int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor = 1.2, int minNeighbors = 4, Size minSize = Size());
    int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4);
203

204 205
    bool findLargestObject;
    bool visualizeInPlace;
206

207
    Size getClassifierSize() const;
208 209

private:
210 211 212 213 214
    struct CascadeClassifierImpl;
    CascadeClassifierImpl* impl;
    struct HaarCascade;
    struct LbpCascade;
    friend class CascadeClassifier_GPU_LBP;
215 216
};

217
//////////////////////////// Labeling ////////////////////////////
218

219 220 221
//!performs labeling via graph cuts of a 2D regular 4-connected graph.
CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels,
                         GpuMat& buf, Stream& stream = Stream::Null());
222

223 224 225 226 227
//!performs labeling via graph cuts of a 2D regular 8-connected graph.
CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& topLeft, GpuMat& topRight,
                         GpuMat& bottom, GpuMat& bottomLeft, GpuMat& bottomRight,
                         GpuMat& labels,
                         GpuMat& buf, Stream& stream = Stream::Null());
228

229 230
//! compute mask for Generalized Flood fill componetns labeling.
CV_EXPORTS void connectivityMask(const GpuMat& image, GpuMat& mask, const cv::Scalar& lo, const cv::Scalar& hi, Stream& stream = Stream::Null());
231

232 233
//! performs connected componnents labeling.
CV_EXPORTS void labelComponents(const GpuMat& mask, GpuMat& components, int flags = 0, Stream& stream = Stream::Null());
234

235
//////////////////////////// Calib3d ////////////////////////////
236

237 238
CV_EXPORTS void transformPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
                                GpuMat& dst, Stream& stream = Stream::Null());
239

240 241 242
CV_EXPORTS void projectPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
                              const Mat& camera_mat, const Mat& dist_coef, GpuMat& dst,
                              Stream& stream = Stream::Null());
243

244 245 246 247
CV_EXPORTS void solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat,
                               const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess=false,
                               int num_iters=100, float max_dist=8.0, int min_inlier_count=100,
                               std::vector<int>* inliers=NULL);
248

249
//////////////////////////// VStab ////////////////////////////
V
Vladislav Vinogradov 已提交
250

251 252 253 254 255 256 257
//! removes points (CV_32FC2, single row matrix) with zero mask value
CV_EXPORTS void compactPoints(GpuMat &points0, GpuMat &points1, const GpuMat &mask);

CV_EXPORTS void calcWobbleSuppressionMaps(
        int left, int idx, int right, Size size, const Mat &ml, const Mat &mr,
        GpuMat &mapx, GpuMat &mapy);

258
}} // namespace cv { namespace gpu {
259 260

#endif /* __OPENCV_GPU_HPP__ */