opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 16 //
joeverbout 0:ea44dc9ed014 17 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 18 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 19 //
joeverbout 0:ea44dc9ed014 20 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 21 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 22 //
joeverbout 0:ea44dc9ed014 23 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 24 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 25 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 26 //
joeverbout 0:ea44dc9ed014 27 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 28 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 29 //
joeverbout 0:ea44dc9ed014 30 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 31 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 33 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 34 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 35 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 36 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 37 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 38 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 39 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 40 //
joeverbout 0:ea44dc9ed014 41 //M*/
joeverbout 0:ea44dc9ed014 42
joeverbout 0:ea44dc9ed014 43 #ifndef __OPENCV_STITCHING_WARPERS_HPP__
joeverbout 0:ea44dc9ed014 44 #define __OPENCV_STITCHING_WARPERS_HPP__
joeverbout 0:ea44dc9ed014 45
joeverbout 0:ea44dc9ed014 46 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 47 #include "opencv2/core/cuda.hpp"
joeverbout 0:ea44dc9ed014 48 #include "opencv2/imgproc.hpp"
joeverbout 0:ea44dc9ed014 49 #include "opencv2/opencv_modules.hpp"
joeverbout 0:ea44dc9ed014 50
joeverbout 0:ea44dc9ed014 51 namespace cv {
joeverbout 0:ea44dc9ed014 52 namespace detail {
joeverbout 0:ea44dc9ed014 53
joeverbout 0:ea44dc9ed014 54 //! @addtogroup stitching_warp
joeverbout 0:ea44dc9ed014 55 //! @{
joeverbout 0:ea44dc9ed014 56
joeverbout 0:ea44dc9ed014 57 /** @brief Rotation-only model image warper interface.
joeverbout 0:ea44dc9ed014 58 */
joeverbout 0:ea44dc9ed014 59 class CV_EXPORTS RotationWarper
joeverbout 0:ea44dc9ed014 60 {
joeverbout 0:ea44dc9ed014 61 public:
joeverbout 0:ea44dc9ed014 62 virtual ~RotationWarper() {}
joeverbout 0:ea44dc9ed014 63
joeverbout 0:ea44dc9ed014 64 /** @brief Projects the image point.
joeverbout 0:ea44dc9ed014 65
joeverbout 0:ea44dc9ed014 66 @param pt Source point
joeverbout 0:ea44dc9ed014 67 @param K Camera intrinsic parameters
joeverbout 0:ea44dc9ed014 68 @param R Camera rotation matrix
joeverbout 0:ea44dc9ed014 69 @return Projected point
joeverbout 0:ea44dc9ed014 70 */
joeverbout 0:ea44dc9ed014 71 virtual Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R) = 0;
joeverbout 0:ea44dc9ed014 72
joeverbout 0:ea44dc9ed014 73 /** @brief Builds the projection maps according to the given camera data.
joeverbout 0:ea44dc9ed014 74
joeverbout 0:ea44dc9ed014 75 @param src_size Source image size
joeverbout 0:ea44dc9ed014 76 @param K Camera intrinsic parameters
joeverbout 0:ea44dc9ed014 77 @param R Camera rotation matrix
joeverbout 0:ea44dc9ed014 78 @param xmap Projection map for the x axis
joeverbout 0:ea44dc9ed014 79 @param ymap Projection map for the y axis
joeverbout 0:ea44dc9ed014 80 @return Projected image minimum bounding box
joeverbout 0:ea44dc9ed014 81 */
joeverbout 0:ea44dc9ed014 82 virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap) = 0;
joeverbout 0:ea44dc9ed014 83
joeverbout 0:ea44dc9ed014 84 /** @brief Projects the image.
joeverbout 0:ea44dc9ed014 85
joeverbout 0:ea44dc9ed014 86 @param src Source image
joeverbout 0:ea44dc9ed014 87 @param K Camera intrinsic parameters
joeverbout 0:ea44dc9ed014 88 @param R Camera rotation matrix
joeverbout 0:ea44dc9ed014 89 @param interp_mode Interpolation mode
joeverbout 0:ea44dc9ed014 90 @param border_mode Border extrapolation mode
joeverbout 0:ea44dc9ed014 91 @param dst Projected image
joeverbout 0:ea44dc9ed014 92 @return Project image top-left corner
joeverbout 0:ea44dc9ed014 93 */
joeverbout 0:ea44dc9ed014 94 virtual Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 95 OutputArray dst) = 0;
joeverbout 0:ea44dc9ed014 96
joeverbout 0:ea44dc9ed014 97 /** @brief Projects the image backward.
joeverbout 0:ea44dc9ed014 98
joeverbout 0:ea44dc9ed014 99 @param src Projected image
joeverbout 0:ea44dc9ed014 100 @param K Camera intrinsic parameters
joeverbout 0:ea44dc9ed014 101 @param R Camera rotation matrix
joeverbout 0:ea44dc9ed014 102 @param interp_mode Interpolation mode
joeverbout 0:ea44dc9ed014 103 @param border_mode Border extrapolation mode
joeverbout 0:ea44dc9ed014 104 @param dst_size Backward-projected image size
joeverbout 0:ea44dc9ed014 105 @param dst Backward-projected image
joeverbout 0:ea44dc9ed014 106 */
joeverbout 0:ea44dc9ed014 107 virtual void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 108 Size dst_size, OutputArray dst) = 0;
joeverbout 0:ea44dc9ed014 109
joeverbout 0:ea44dc9ed014 110 /**
joeverbout 0:ea44dc9ed014 111 @param src_size Source image bounding box
joeverbout 0:ea44dc9ed014 112 @param K Camera intrinsic parameters
joeverbout 0:ea44dc9ed014 113 @param R Camera rotation matrix
joeverbout 0:ea44dc9ed014 114 @return Projected image minimum bounding box
joeverbout 0:ea44dc9ed014 115 */
joeverbout 0:ea44dc9ed014 116 virtual Rect warpRoi(Size src_size, InputArray K, InputArray R) = 0;
joeverbout 0:ea44dc9ed014 117
joeverbout 0:ea44dc9ed014 118 virtual float getScale() const { return 1.f; }
joeverbout 0:ea44dc9ed014 119 virtual void setScale(float) {}
joeverbout 0:ea44dc9ed014 120 };
joeverbout 0:ea44dc9ed014 121
joeverbout 0:ea44dc9ed014 122 /** @brief Base class for warping logic implementation.
joeverbout 0:ea44dc9ed014 123 */
joeverbout 0:ea44dc9ed014 124 struct CV_EXPORTS ProjectorBase
joeverbout 0:ea44dc9ed014 125 {
joeverbout 0:ea44dc9ed014 126 void setCameraParams(InputArray K = Mat::eye(3, 3, CV_32F),
joeverbout 0:ea44dc9ed014 127 InputArray R = Mat::eye(3, 3, CV_32F),
joeverbout 0:ea44dc9ed014 128 InputArray T = Mat::zeros(3, 1, CV_32F));
joeverbout 0:ea44dc9ed014 129
joeverbout 0:ea44dc9ed014 130 float scale;
joeverbout 0:ea44dc9ed014 131 float k[9];
joeverbout 0:ea44dc9ed014 132 float rinv[9];
joeverbout 0:ea44dc9ed014 133 float r_kinv[9];
joeverbout 0:ea44dc9ed014 134 float k_rinv[9];
joeverbout 0:ea44dc9ed014 135 float t[3];
joeverbout 0:ea44dc9ed014 136 };
joeverbout 0:ea44dc9ed014 137
joeverbout 0:ea44dc9ed014 138 /** @brief Base class for rotation-based warper using a detail::ProjectorBase_ derived class.
joeverbout 0:ea44dc9ed014 139 */
joeverbout 0:ea44dc9ed014 140 template <class P>
joeverbout 0:ea44dc9ed014 141 class CV_EXPORTS RotationWarperBase : public RotationWarper
joeverbout 0:ea44dc9ed014 142 {
joeverbout 0:ea44dc9ed014 143 public:
joeverbout 0:ea44dc9ed014 144 Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
joeverbout 0:ea44dc9ed014 145
joeverbout 0:ea44dc9ed014 146 Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
joeverbout 0:ea44dc9ed014 147
joeverbout 0:ea44dc9ed014 148 Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 149 OutputArray dst);
joeverbout 0:ea44dc9ed014 150
joeverbout 0:ea44dc9ed014 151 void warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 152 Size dst_size, OutputArray dst);
joeverbout 0:ea44dc9ed014 153
joeverbout 0:ea44dc9ed014 154 Rect warpRoi(Size src_size, InputArray K, InputArray R);
joeverbout 0:ea44dc9ed014 155
joeverbout 0:ea44dc9ed014 156 float getScale() const { return projector_.scale; }
joeverbout 0:ea44dc9ed014 157 void setScale(float val) { projector_.scale = val; }
joeverbout 0:ea44dc9ed014 158
joeverbout 0:ea44dc9ed014 159 protected:
joeverbout 0:ea44dc9ed014 160
joeverbout 0:ea44dc9ed014 161 // Detects ROI of the destination image. It's correct for any projection.
joeverbout 0:ea44dc9ed014 162 virtual void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br);
joeverbout 0:ea44dc9ed014 163
joeverbout 0:ea44dc9ed014 164 // Detects ROI of the destination image by walking over image border.
joeverbout 0:ea44dc9ed014 165 // Correctness for any projection isn't guaranteed.
joeverbout 0:ea44dc9ed014 166 void detectResultRoiByBorder(Size src_size, Point &dst_tl, Point &dst_br);
joeverbout 0:ea44dc9ed014 167
joeverbout 0:ea44dc9ed014 168 P projector_;
joeverbout 0:ea44dc9ed014 169 };
joeverbout 0:ea44dc9ed014 170
joeverbout 0:ea44dc9ed014 171
joeverbout 0:ea44dc9ed014 172 struct CV_EXPORTS PlaneProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 173 {
joeverbout 0:ea44dc9ed014 174 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 175 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 176 };
joeverbout 0:ea44dc9ed014 177
joeverbout 0:ea44dc9ed014 178 /** @brief Warper that maps an image onto the z = 1 plane.
joeverbout 0:ea44dc9ed014 179 */
joeverbout 0:ea44dc9ed014 180 class CV_EXPORTS PlaneWarper : public RotationWarperBase<PlaneProjector>
joeverbout 0:ea44dc9ed014 181 {
joeverbout 0:ea44dc9ed014 182 public:
joeverbout 0:ea44dc9ed014 183 /** @brief Construct an instance of the plane warper class.
joeverbout 0:ea44dc9ed014 184
joeverbout 0:ea44dc9ed014 185 @param scale Projected image scale multiplier
joeverbout 0:ea44dc9ed014 186 */
joeverbout 0:ea44dc9ed014 187 PlaneWarper(float scale = 1.f) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 188
joeverbout 0:ea44dc9ed014 189 Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R);
joeverbout 0:ea44dc9ed014 190 Point2f warpPoint(const Point2f &pt, InputArray K, InputArray R, InputArray T);
joeverbout 0:ea44dc9ed014 191
joeverbout 0:ea44dc9ed014 192 virtual Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap);
joeverbout 0:ea44dc9ed014 193 Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
joeverbout 0:ea44dc9ed014 194
joeverbout 0:ea44dc9ed014 195 Point warp(InputArray src, InputArray K, InputArray R,
joeverbout 0:ea44dc9ed014 196 int interp_mode, int border_mode, OutputArray dst);
joeverbout 0:ea44dc9ed014 197 virtual Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 198 OutputArray dst);
joeverbout 0:ea44dc9ed014 199
joeverbout 0:ea44dc9ed014 200 Rect warpRoi(Size src_size, InputArray K, InputArray R);
joeverbout 0:ea44dc9ed014 201 Rect warpRoi(Size src_size, InputArray K, InputArray R, InputArray T);
joeverbout 0:ea44dc9ed014 202
joeverbout 0:ea44dc9ed014 203 protected:
joeverbout 0:ea44dc9ed014 204 void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br);
joeverbout 0:ea44dc9ed014 205 };
joeverbout 0:ea44dc9ed014 206
joeverbout 0:ea44dc9ed014 207
joeverbout 0:ea44dc9ed014 208 struct CV_EXPORTS SphericalProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 209 {
joeverbout 0:ea44dc9ed014 210 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 211 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 212 };
joeverbout 0:ea44dc9ed014 213
joeverbout 0:ea44dc9ed014 214
joeverbout 0:ea44dc9ed014 215 /** @brief Warper that maps an image onto the unit sphere located at the origin.
joeverbout 0:ea44dc9ed014 216
joeverbout 0:ea44dc9ed014 217 Projects image onto unit sphere with origin at (0, 0, 0).
joeverbout 0:ea44dc9ed014 218 Poles are located at (0, -1, 0) and (0, 1, 0) points.
joeverbout 0:ea44dc9ed014 219 */
joeverbout 0:ea44dc9ed014 220 class CV_EXPORTS SphericalWarper : public RotationWarperBase<SphericalProjector>
joeverbout 0:ea44dc9ed014 221 {
joeverbout 0:ea44dc9ed014 222 public:
joeverbout 0:ea44dc9ed014 223 /** @brief Construct an instance of the spherical warper class.
joeverbout 0:ea44dc9ed014 224
joeverbout 0:ea44dc9ed014 225 @param scale Projected image scale multiplier
joeverbout 0:ea44dc9ed014 226 */
joeverbout 0:ea44dc9ed014 227 SphericalWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 228
joeverbout 0:ea44dc9ed014 229 Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
joeverbout 0:ea44dc9ed014 230 Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst);
joeverbout 0:ea44dc9ed014 231 protected:
joeverbout 0:ea44dc9ed014 232 void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br);
joeverbout 0:ea44dc9ed014 233 };
joeverbout 0:ea44dc9ed014 234
joeverbout 0:ea44dc9ed014 235
joeverbout 0:ea44dc9ed014 236 struct CV_EXPORTS CylindricalProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 237 {
joeverbout 0:ea44dc9ed014 238 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 239 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 240 };
joeverbout 0:ea44dc9ed014 241
joeverbout 0:ea44dc9ed014 242
joeverbout 0:ea44dc9ed014 243 /** @brief Warper that maps an image onto the x\*x + z\*z = 1 cylinder.
joeverbout 0:ea44dc9ed014 244 */
joeverbout 0:ea44dc9ed014 245 class CV_EXPORTS CylindricalWarper : public RotationWarperBase<CylindricalProjector>
joeverbout 0:ea44dc9ed014 246 {
joeverbout 0:ea44dc9ed014 247 public:
joeverbout 0:ea44dc9ed014 248 /** @brief Construct an instance of the cylindrical warper class.
joeverbout 0:ea44dc9ed014 249
joeverbout 0:ea44dc9ed014 250 @param scale Projected image scale multiplier
joeverbout 0:ea44dc9ed014 251 */
joeverbout 0:ea44dc9ed014 252 CylindricalWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 253
joeverbout 0:ea44dc9ed014 254 Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap);
joeverbout 0:ea44dc9ed014 255 Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode, OutputArray dst);
joeverbout 0:ea44dc9ed014 256 protected:
joeverbout 0:ea44dc9ed014 257 void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
joeverbout 0:ea44dc9ed014 258 {
joeverbout 0:ea44dc9ed014 259 RotationWarperBase<CylindricalProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br);
joeverbout 0:ea44dc9ed014 260 }
joeverbout 0:ea44dc9ed014 261 };
joeverbout 0:ea44dc9ed014 262
joeverbout 0:ea44dc9ed014 263
joeverbout 0:ea44dc9ed014 264 struct CV_EXPORTS FisheyeProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 265 {
joeverbout 0:ea44dc9ed014 266 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 267 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 268 };
joeverbout 0:ea44dc9ed014 269
joeverbout 0:ea44dc9ed014 270
joeverbout 0:ea44dc9ed014 271 class CV_EXPORTS FisheyeWarper : public RotationWarperBase<FisheyeProjector>
joeverbout 0:ea44dc9ed014 272 {
joeverbout 0:ea44dc9ed014 273 public:
joeverbout 0:ea44dc9ed014 274 FisheyeWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 275 };
joeverbout 0:ea44dc9ed014 276
joeverbout 0:ea44dc9ed014 277
joeverbout 0:ea44dc9ed014 278 struct CV_EXPORTS StereographicProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 279 {
joeverbout 0:ea44dc9ed014 280 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 281 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 282 };
joeverbout 0:ea44dc9ed014 283
joeverbout 0:ea44dc9ed014 284
joeverbout 0:ea44dc9ed014 285 class CV_EXPORTS StereographicWarper : public RotationWarperBase<StereographicProjector>
joeverbout 0:ea44dc9ed014 286 {
joeverbout 0:ea44dc9ed014 287 public:
joeverbout 0:ea44dc9ed014 288 StereographicWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 289 };
joeverbout 0:ea44dc9ed014 290
joeverbout 0:ea44dc9ed014 291
joeverbout 0:ea44dc9ed014 292 struct CV_EXPORTS CompressedRectilinearProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 293 {
joeverbout 0:ea44dc9ed014 294 float a, b;
joeverbout 0:ea44dc9ed014 295
joeverbout 0:ea44dc9ed014 296 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 297 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 298 };
joeverbout 0:ea44dc9ed014 299
joeverbout 0:ea44dc9ed014 300
joeverbout 0:ea44dc9ed014 301 class CV_EXPORTS CompressedRectilinearWarper : public RotationWarperBase<CompressedRectilinearProjector>
joeverbout 0:ea44dc9ed014 302 {
joeverbout 0:ea44dc9ed014 303 public:
joeverbout 0:ea44dc9ed014 304 CompressedRectilinearWarper(float scale, float A = 1, float B = 1)
joeverbout 0:ea44dc9ed014 305 {
joeverbout 0:ea44dc9ed014 306 projector_.a = A;
joeverbout 0:ea44dc9ed014 307 projector_.b = B;
joeverbout 0:ea44dc9ed014 308 projector_.scale = scale;
joeverbout 0:ea44dc9ed014 309 }
joeverbout 0:ea44dc9ed014 310 };
joeverbout 0:ea44dc9ed014 311
joeverbout 0:ea44dc9ed014 312
joeverbout 0:ea44dc9ed014 313 struct CV_EXPORTS CompressedRectilinearPortraitProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 314 {
joeverbout 0:ea44dc9ed014 315 float a, b;
joeverbout 0:ea44dc9ed014 316
joeverbout 0:ea44dc9ed014 317 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 318 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 319 };
joeverbout 0:ea44dc9ed014 320
joeverbout 0:ea44dc9ed014 321
joeverbout 0:ea44dc9ed014 322 class CV_EXPORTS CompressedRectilinearPortraitWarper : public RotationWarperBase<CompressedRectilinearPortraitProjector>
joeverbout 0:ea44dc9ed014 323 {
joeverbout 0:ea44dc9ed014 324 public:
joeverbout 0:ea44dc9ed014 325 CompressedRectilinearPortraitWarper(float scale, float A = 1, float B = 1)
joeverbout 0:ea44dc9ed014 326 {
joeverbout 0:ea44dc9ed014 327 projector_.a = A;
joeverbout 0:ea44dc9ed014 328 projector_.b = B;
joeverbout 0:ea44dc9ed014 329 projector_.scale = scale;
joeverbout 0:ea44dc9ed014 330 }
joeverbout 0:ea44dc9ed014 331 };
joeverbout 0:ea44dc9ed014 332
joeverbout 0:ea44dc9ed014 333
joeverbout 0:ea44dc9ed014 334 struct CV_EXPORTS PaniniProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 335 {
joeverbout 0:ea44dc9ed014 336 float a, b;
joeverbout 0:ea44dc9ed014 337
joeverbout 0:ea44dc9ed014 338 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 339 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 340 };
joeverbout 0:ea44dc9ed014 341
joeverbout 0:ea44dc9ed014 342
joeverbout 0:ea44dc9ed014 343 class CV_EXPORTS PaniniWarper : public RotationWarperBase<PaniniProjector>
joeverbout 0:ea44dc9ed014 344 {
joeverbout 0:ea44dc9ed014 345 public:
joeverbout 0:ea44dc9ed014 346 PaniniWarper(float scale, float A = 1, float B = 1)
joeverbout 0:ea44dc9ed014 347 {
joeverbout 0:ea44dc9ed014 348 projector_.a = A;
joeverbout 0:ea44dc9ed014 349 projector_.b = B;
joeverbout 0:ea44dc9ed014 350 projector_.scale = scale;
joeverbout 0:ea44dc9ed014 351 }
joeverbout 0:ea44dc9ed014 352 };
joeverbout 0:ea44dc9ed014 353
joeverbout 0:ea44dc9ed014 354
joeverbout 0:ea44dc9ed014 355 struct CV_EXPORTS PaniniPortraitProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 356 {
joeverbout 0:ea44dc9ed014 357 float a, b;
joeverbout 0:ea44dc9ed014 358
joeverbout 0:ea44dc9ed014 359 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 360 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 361 };
joeverbout 0:ea44dc9ed014 362
joeverbout 0:ea44dc9ed014 363
joeverbout 0:ea44dc9ed014 364 class CV_EXPORTS PaniniPortraitWarper : public RotationWarperBase<PaniniPortraitProjector>
joeverbout 0:ea44dc9ed014 365 {
joeverbout 0:ea44dc9ed014 366 public:
joeverbout 0:ea44dc9ed014 367 PaniniPortraitWarper(float scale, float A = 1, float B = 1)
joeverbout 0:ea44dc9ed014 368 {
joeverbout 0:ea44dc9ed014 369 projector_.a = A;
joeverbout 0:ea44dc9ed014 370 projector_.b = B;
joeverbout 0:ea44dc9ed014 371 projector_.scale = scale;
joeverbout 0:ea44dc9ed014 372 }
joeverbout 0:ea44dc9ed014 373
joeverbout 0:ea44dc9ed014 374 };
joeverbout 0:ea44dc9ed014 375
joeverbout 0:ea44dc9ed014 376
joeverbout 0:ea44dc9ed014 377 struct CV_EXPORTS MercatorProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 378 {
joeverbout 0:ea44dc9ed014 379 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 380 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 381 };
joeverbout 0:ea44dc9ed014 382
joeverbout 0:ea44dc9ed014 383
joeverbout 0:ea44dc9ed014 384 class CV_EXPORTS MercatorWarper : public RotationWarperBase<MercatorProjector>
joeverbout 0:ea44dc9ed014 385 {
joeverbout 0:ea44dc9ed014 386 public:
joeverbout 0:ea44dc9ed014 387 MercatorWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 388 };
joeverbout 0:ea44dc9ed014 389
joeverbout 0:ea44dc9ed014 390
joeverbout 0:ea44dc9ed014 391 struct CV_EXPORTS TransverseMercatorProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 392 {
joeverbout 0:ea44dc9ed014 393 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 394 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 395 };
joeverbout 0:ea44dc9ed014 396
joeverbout 0:ea44dc9ed014 397
joeverbout 0:ea44dc9ed014 398 class CV_EXPORTS TransverseMercatorWarper : public RotationWarperBase<TransverseMercatorProjector>
joeverbout 0:ea44dc9ed014 399 {
joeverbout 0:ea44dc9ed014 400 public:
joeverbout 0:ea44dc9ed014 401 TransverseMercatorWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 402 };
joeverbout 0:ea44dc9ed014 403
joeverbout 0:ea44dc9ed014 404
joeverbout 0:ea44dc9ed014 405 class CV_EXPORTS PlaneWarperGpu : public PlaneWarper
joeverbout 0:ea44dc9ed014 406 {
joeverbout 0:ea44dc9ed014 407 public:
joeverbout 0:ea44dc9ed014 408 PlaneWarperGpu(float scale = 1.f) : PlaneWarper(scale) {}
joeverbout 0:ea44dc9ed014 409
joeverbout 0:ea44dc9ed014 410 Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
joeverbout 0:ea44dc9ed014 411 {
joeverbout 0:ea44dc9ed014 412 Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
joeverbout 0:ea44dc9ed014 413 d_xmap_.download(xmap);
joeverbout 0:ea44dc9ed014 414 d_ymap_.download(ymap);
joeverbout 0:ea44dc9ed014 415 return result;
joeverbout 0:ea44dc9ed014 416 }
joeverbout 0:ea44dc9ed014 417
joeverbout 0:ea44dc9ed014 418 Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, OutputArray xmap, OutputArray ymap)
joeverbout 0:ea44dc9ed014 419 {
joeverbout 0:ea44dc9ed014 420 Rect result = buildMaps(src_size, K, R, T, d_xmap_, d_ymap_);
joeverbout 0:ea44dc9ed014 421 d_xmap_.download(xmap);
joeverbout 0:ea44dc9ed014 422 d_ymap_.download(ymap);
joeverbout 0:ea44dc9ed014 423 return result;
joeverbout 0:ea44dc9ed014 424 }
joeverbout 0:ea44dc9ed014 425
joeverbout 0:ea44dc9ed014 426 Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 427 OutputArray dst)
joeverbout 0:ea44dc9ed014 428 {
joeverbout 0:ea44dc9ed014 429 d_src_.upload(src);
joeverbout 0:ea44dc9ed014 430 Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
joeverbout 0:ea44dc9ed014 431 d_dst_.download(dst);
joeverbout 0:ea44dc9ed014 432 return result;
joeverbout 0:ea44dc9ed014 433 }
joeverbout 0:ea44dc9ed014 434
joeverbout 0:ea44dc9ed014 435 Point warp(InputArray src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 436 OutputArray dst)
joeverbout 0:ea44dc9ed014 437 {
joeverbout 0:ea44dc9ed014 438 d_src_.upload(src);
joeverbout 0:ea44dc9ed014 439 Point result = warp(d_src_, K, R, T, interp_mode, border_mode, d_dst_);
joeverbout 0:ea44dc9ed014 440 d_dst_.download(dst);
joeverbout 0:ea44dc9ed014 441 return result;
joeverbout 0:ea44dc9ed014 442 }
joeverbout 0:ea44dc9ed014 443
joeverbout 0:ea44dc9ed014 444 Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
joeverbout 0:ea44dc9ed014 445
joeverbout 0:ea44dc9ed014 446 Rect buildMaps(Size src_size, InputArray K, InputArray R, InputArray T, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
joeverbout 0:ea44dc9ed014 447
joeverbout 0:ea44dc9ed014 448 Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 449 cuda::GpuMat & dst);
joeverbout 0:ea44dc9ed014 450
joeverbout 0:ea44dc9ed014 451 Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, InputArray T, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 452 cuda::GpuMat & dst);
joeverbout 0:ea44dc9ed014 453
joeverbout 0:ea44dc9ed014 454 private:
joeverbout 0:ea44dc9ed014 455 cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
joeverbout 0:ea44dc9ed014 456 };
joeverbout 0:ea44dc9ed014 457
joeverbout 0:ea44dc9ed014 458
joeverbout 0:ea44dc9ed014 459 class CV_EXPORTS SphericalWarperGpu : public SphericalWarper
joeverbout 0:ea44dc9ed014 460 {
joeverbout 0:ea44dc9ed014 461 public:
joeverbout 0:ea44dc9ed014 462 SphericalWarperGpu(float scale) : SphericalWarper(scale) {}
joeverbout 0:ea44dc9ed014 463
joeverbout 0:ea44dc9ed014 464 Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
joeverbout 0:ea44dc9ed014 465 {
joeverbout 0:ea44dc9ed014 466 Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
joeverbout 0:ea44dc9ed014 467 d_xmap_.download(xmap);
joeverbout 0:ea44dc9ed014 468 d_ymap_.download(ymap);
joeverbout 0:ea44dc9ed014 469 return result;
joeverbout 0:ea44dc9ed014 470 }
joeverbout 0:ea44dc9ed014 471
joeverbout 0:ea44dc9ed014 472 Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 473 OutputArray dst)
joeverbout 0:ea44dc9ed014 474 {
joeverbout 0:ea44dc9ed014 475 d_src_.upload(src);
joeverbout 0:ea44dc9ed014 476 Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
joeverbout 0:ea44dc9ed014 477 d_dst_.download(dst);
joeverbout 0:ea44dc9ed014 478 return result;
joeverbout 0:ea44dc9ed014 479 }
joeverbout 0:ea44dc9ed014 480
joeverbout 0:ea44dc9ed014 481 Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
joeverbout 0:ea44dc9ed014 482
joeverbout 0:ea44dc9ed014 483 Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 484 cuda::GpuMat & dst);
joeverbout 0:ea44dc9ed014 485
joeverbout 0:ea44dc9ed014 486 private:
joeverbout 0:ea44dc9ed014 487 cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
joeverbout 0:ea44dc9ed014 488 };
joeverbout 0:ea44dc9ed014 489
joeverbout 0:ea44dc9ed014 490
joeverbout 0:ea44dc9ed014 491 class CV_EXPORTS CylindricalWarperGpu : public CylindricalWarper
joeverbout 0:ea44dc9ed014 492 {
joeverbout 0:ea44dc9ed014 493 public:
joeverbout 0:ea44dc9ed014 494 CylindricalWarperGpu(float scale) : CylindricalWarper(scale) {}
joeverbout 0:ea44dc9ed014 495
joeverbout 0:ea44dc9ed014 496 Rect buildMaps(Size src_size, InputArray K, InputArray R, OutputArray xmap, OutputArray ymap)
joeverbout 0:ea44dc9ed014 497 {
joeverbout 0:ea44dc9ed014 498 Rect result = buildMaps(src_size, K, R, d_xmap_, d_ymap_);
joeverbout 0:ea44dc9ed014 499 d_xmap_.download(xmap);
joeverbout 0:ea44dc9ed014 500 d_ymap_.download(ymap);
joeverbout 0:ea44dc9ed014 501 return result;
joeverbout 0:ea44dc9ed014 502 }
joeverbout 0:ea44dc9ed014 503
joeverbout 0:ea44dc9ed014 504 Point warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 505 OutputArray dst)
joeverbout 0:ea44dc9ed014 506 {
joeverbout 0:ea44dc9ed014 507 d_src_.upload(src);
joeverbout 0:ea44dc9ed014 508 Point result = warp(d_src_, K, R, interp_mode, border_mode, d_dst_);
joeverbout 0:ea44dc9ed014 509 d_dst_.download(dst);
joeverbout 0:ea44dc9ed014 510 return result;
joeverbout 0:ea44dc9ed014 511 }
joeverbout 0:ea44dc9ed014 512
joeverbout 0:ea44dc9ed014 513 Rect buildMaps(Size src_size, InputArray K, InputArray R, cuda::GpuMat & xmap, cuda::GpuMat & ymap);
joeverbout 0:ea44dc9ed014 514
joeverbout 0:ea44dc9ed014 515 Point warp(const cuda::GpuMat & src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 516 cuda::GpuMat & dst);
joeverbout 0:ea44dc9ed014 517
joeverbout 0:ea44dc9ed014 518 private:
joeverbout 0:ea44dc9ed014 519 cuda::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_;
joeverbout 0:ea44dc9ed014 520 };
joeverbout 0:ea44dc9ed014 521
joeverbout 0:ea44dc9ed014 522
joeverbout 0:ea44dc9ed014 523 struct SphericalPortraitProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 524 {
joeverbout 0:ea44dc9ed014 525 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 526 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 527 };
joeverbout 0:ea44dc9ed014 528
joeverbout 0:ea44dc9ed014 529
joeverbout 0:ea44dc9ed014 530 // Projects image onto unit sphere with origin at (0, 0, 0).
joeverbout 0:ea44dc9ed014 531 // Poles are located NOT at (0, -1, 0) and (0, 1, 0) points, BUT at (1, 0, 0) and (-1, 0, 0) points.
joeverbout 0:ea44dc9ed014 532 class CV_EXPORTS SphericalPortraitWarper : public RotationWarperBase<SphericalPortraitProjector>
joeverbout 0:ea44dc9ed014 533 {
joeverbout 0:ea44dc9ed014 534 public:
joeverbout 0:ea44dc9ed014 535 SphericalPortraitWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 536
joeverbout 0:ea44dc9ed014 537 protected:
joeverbout 0:ea44dc9ed014 538 void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br);
joeverbout 0:ea44dc9ed014 539 };
joeverbout 0:ea44dc9ed014 540
joeverbout 0:ea44dc9ed014 541 struct CylindricalPortraitProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 542 {
joeverbout 0:ea44dc9ed014 543 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 544 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 545 };
joeverbout 0:ea44dc9ed014 546
joeverbout 0:ea44dc9ed014 547
joeverbout 0:ea44dc9ed014 548 class CV_EXPORTS CylindricalPortraitWarper : public RotationWarperBase<CylindricalPortraitProjector>
joeverbout 0:ea44dc9ed014 549 {
joeverbout 0:ea44dc9ed014 550 public:
joeverbout 0:ea44dc9ed014 551 CylindricalPortraitWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 552
joeverbout 0:ea44dc9ed014 553 protected:
joeverbout 0:ea44dc9ed014 554 void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
joeverbout 0:ea44dc9ed014 555 {
joeverbout 0:ea44dc9ed014 556 RotationWarperBase<CylindricalPortraitProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br);
joeverbout 0:ea44dc9ed014 557 }
joeverbout 0:ea44dc9ed014 558 };
joeverbout 0:ea44dc9ed014 559
joeverbout 0:ea44dc9ed014 560 struct PlanePortraitProjector : ProjectorBase
joeverbout 0:ea44dc9ed014 561 {
joeverbout 0:ea44dc9ed014 562 void mapForward(float x, float y, float &u, float &v);
joeverbout 0:ea44dc9ed014 563 void mapBackward(float u, float v, float &x, float &y);
joeverbout 0:ea44dc9ed014 564 };
joeverbout 0:ea44dc9ed014 565
joeverbout 0:ea44dc9ed014 566
joeverbout 0:ea44dc9ed014 567 class CV_EXPORTS PlanePortraitWarper : public RotationWarperBase<PlanePortraitProjector>
joeverbout 0:ea44dc9ed014 568 {
joeverbout 0:ea44dc9ed014 569 public:
joeverbout 0:ea44dc9ed014 570 PlanePortraitWarper(float scale) { projector_.scale = scale; }
joeverbout 0:ea44dc9ed014 571
joeverbout 0:ea44dc9ed014 572 protected:
joeverbout 0:ea44dc9ed014 573 void detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
joeverbout 0:ea44dc9ed014 574 {
joeverbout 0:ea44dc9ed014 575 RotationWarperBase<PlanePortraitProjector>::detectResultRoiByBorder(src_size, dst_tl, dst_br);
joeverbout 0:ea44dc9ed014 576 }
joeverbout 0:ea44dc9ed014 577 };
joeverbout 0:ea44dc9ed014 578
joeverbout 0:ea44dc9ed014 579 //! @} stitching_warp
joeverbout 0:ea44dc9ed014 580
joeverbout 0:ea44dc9ed014 581 } // namespace detail
joeverbout 0:ea44dc9ed014 582 } // namespace cv
joeverbout 0:ea44dc9ed014 583
joeverbout 0:ea44dc9ed014 584 #include "warpers_inl.hpp"
joeverbout 0:ea44dc9ed014 585
joeverbout 0:ea44dc9ed014 586 #endif // __OPENCV_STITCHING_WARPERS_HPP__
joeverbout 0:ea44dc9ed014 587