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_INL_HPP__
joeverbout 0:ea44dc9ed014 44 #define __OPENCV_STITCHING_WARPERS_INL_HPP__
joeverbout 0:ea44dc9ed014 45
joeverbout 0:ea44dc9ed014 46 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 47 #include "warpers.hpp" // Make your IDE see declarations
joeverbout 0:ea44dc9ed014 48 #include <limits>
joeverbout 0:ea44dc9ed014 49
joeverbout 0:ea44dc9ed014 50 //! @cond IGNORED
joeverbout 0:ea44dc9ed014 51
joeverbout 0:ea44dc9ed014 52 namespace cv {
joeverbout 0:ea44dc9ed014 53 namespace detail {
joeverbout 0:ea44dc9ed014 54
joeverbout 0:ea44dc9ed014 55 template <class P>
joeverbout 0:ea44dc9ed014 56 Point2f RotationWarperBase<P>::warpPoint(const Point2f &pt, InputArray K, InputArray R)
joeverbout 0:ea44dc9ed014 57 {
joeverbout 0:ea44dc9ed014 58 projector_.setCameraParams(K, R);
joeverbout 0:ea44dc9ed014 59 Point2f uv;
joeverbout 0:ea44dc9ed014 60 projector_.mapForward(pt.x, pt.y, uv.x, uv.y);
joeverbout 0:ea44dc9ed014 61 return uv;
joeverbout 0:ea44dc9ed014 62 }
joeverbout 0:ea44dc9ed014 63
joeverbout 0:ea44dc9ed014 64
joeverbout 0:ea44dc9ed014 65 template <class P>
joeverbout 0:ea44dc9ed014 66 Rect RotationWarperBase<P>::buildMaps(Size src_size, InputArray K, InputArray R, OutputArray _xmap, OutputArray _ymap)
joeverbout 0:ea44dc9ed014 67 {
joeverbout 0:ea44dc9ed014 68 projector_.setCameraParams(K, R);
joeverbout 0:ea44dc9ed014 69
joeverbout 0:ea44dc9ed014 70 Point dst_tl, dst_br;
joeverbout 0:ea44dc9ed014 71 detectResultRoi(src_size, dst_tl, dst_br);
joeverbout 0:ea44dc9ed014 72
joeverbout 0:ea44dc9ed014 73 _xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
joeverbout 0:ea44dc9ed014 74 _ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
joeverbout 0:ea44dc9ed014 75
joeverbout 0:ea44dc9ed014 76 Mat xmap = _xmap.getMat(), ymap = _ymap.getMat();
joeverbout 0:ea44dc9ed014 77
joeverbout 0:ea44dc9ed014 78 float x, y;
joeverbout 0:ea44dc9ed014 79 for (int v = dst_tl.y; v <= dst_br.y; ++v)
joeverbout 0:ea44dc9ed014 80 {
joeverbout 0:ea44dc9ed014 81 for (int u = dst_tl.x; u <= dst_br.x; ++u)
joeverbout 0:ea44dc9ed014 82 {
joeverbout 0:ea44dc9ed014 83 projector_.mapBackward(static_cast<float>(u), static_cast<float>(v), x, y);
joeverbout 0:ea44dc9ed014 84 xmap.at<float>(v - dst_tl.y, u - dst_tl.x) = x;
joeverbout 0:ea44dc9ed014 85 ymap.at<float>(v - dst_tl.y, u - dst_tl.x) = y;
joeverbout 0:ea44dc9ed014 86 }
joeverbout 0:ea44dc9ed014 87 }
joeverbout 0:ea44dc9ed014 88
joeverbout 0:ea44dc9ed014 89 return Rect(dst_tl, dst_br);
joeverbout 0:ea44dc9ed014 90 }
joeverbout 0:ea44dc9ed014 91
joeverbout 0:ea44dc9ed014 92
joeverbout 0:ea44dc9ed014 93 template <class P>
joeverbout 0:ea44dc9ed014 94 Point RotationWarperBase<P>::warp(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 95 OutputArray dst)
joeverbout 0:ea44dc9ed014 96 {
joeverbout 0:ea44dc9ed014 97 UMat xmap, ymap;
joeverbout 0:ea44dc9ed014 98 Rect dst_roi = buildMaps(src.size(), K, R, xmap, ymap);
joeverbout 0:ea44dc9ed014 99
joeverbout 0:ea44dc9ed014 100 dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
joeverbout 0:ea44dc9ed014 101 remap(src, dst, xmap, ymap, interp_mode, border_mode);
joeverbout 0:ea44dc9ed014 102
joeverbout 0:ea44dc9ed014 103 return dst_roi.tl();
joeverbout 0:ea44dc9ed014 104 }
joeverbout 0:ea44dc9ed014 105
joeverbout 0:ea44dc9ed014 106
joeverbout 0:ea44dc9ed014 107 template <class P>
joeverbout 0:ea44dc9ed014 108 void RotationWarperBase<P>::warpBackward(InputArray src, InputArray K, InputArray R, int interp_mode, int border_mode,
joeverbout 0:ea44dc9ed014 109 Size dst_size, OutputArray dst)
joeverbout 0:ea44dc9ed014 110 {
joeverbout 0:ea44dc9ed014 111 projector_.setCameraParams(K, R);
joeverbout 0:ea44dc9ed014 112
joeverbout 0:ea44dc9ed014 113 Point src_tl, src_br;
joeverbout 0:ea44dc9ed014 114 detectResultRoi(dst_size, src_tl, src_br);
joeverbout 0:ea44dc9ed014 115
joeverbout 0:ea44dc9ed014 116 Size size = src.size();
joeverbout 0:ea44dc9ed014 117 CV_Assert(src_br.x - src_tl.x + 1 == size.width && src_br.y - src_tl.y + 1 == size.height);
joeverbout 0:ea44dc9ed014 118
joeverbout 0:ea44dc9ed014 119 Mat xmap(dst_size, CV_32F);
joeverbout 0:ea44dc9ed014 120 Mat ymap(dst_size, CV_32F);
joeverbout 0:ea44dc9ed014 121
joeverbout 0:ea44dc9ed014 122 float u, v;
joeverbout 0:ea44dc9ed014 123 for (int y = 0; y < dst_size.height; ++y)
joeverbout 0:ea44dc9ed014 124 {
joeverbout 0:ea44dc9ed014 125 for (int x = 0; x < dst_size.width; ++x)
joeverbout 0:ea44dc9ed014 126 {
joeverbout 0:ea44dc9ed014 127 projector_.mapForward(static_cast<float>(x), static_cast<float>(y), u, v);
joeverbout 0:ea44dc9ed014 128 xmap.at<float>(y, x) = u - src_tl.x;
joeverbout 0:ea44dc9ed014 129 ymap.at<float>(y, x) = v - src_tl.y;
joeverbout 0:ea44dc9ed014 130 }
joeverbout 0:ea44dc9ed014 131 }
joeverbout 0:ea44dc9ed014 132
joeverbout 0:ea44dc9ed014 133 dst.create(dst_size, src.type());
joeverbout 0:ea44dc9ed014 134 remap(src, dst, xmap, ymap, interp_mode, border_mode);
joeverbout 0:ea44dc9ed014 135 }
joeverbout 0:ea44dc9ed014 136
joeverbout 0:ea44dc9ed014 137
joeverbout 0:ea44dc9ed014 138 template <class P>
joeverbout 0:ea44dc9ed014 139 Rect RotationWarperBase<P>::warpRoi(Size src_size, InputArray K, InputArray R)
joeverbout 0:ea44dc9ed014 140 {
joeverbout 0:ea44dc9ed014 141 projector_.setCameraParams(K, R);
joeverbout 0:ea44dc9ed014 142
joeverbout 0:ea44dc9ed014 143 Point dst_tl, dst_br;
joeverbout 0:ea44dc9ed014 144 detectResultRoi(src_size, dst_tl, dst_br);
joeverbout 0:ea44dc9ed014 145
joeverbout 0:ea44dc9ed014 146 return Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1));
joeverbout 0:ea44dc9ed014 147 }
joeverbout 0:ea44dc9ed014 148
joeverbout 0:ea44dc9ed014 149
joeverbout 0:ea44dc9ed014 150 template <class P>
joeverbout 0:ea44dc9ed014 151 void RotationWarperBase<P>::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
joeverbout 0:ea44dc9ed014 152 {
joeverbout 0:ea44dc9ed014 153 float tl_uf = std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 154 float tl_vf = std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 155 float br_uf = -std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 156 float br_vf = -std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 157
joeverbout 0:ea44dc9ed014 158 float u, v;
joeverbout 0:ea44dc9ed014 159 for (int y = 0; y < src_size.height; ++y)
joeverbout 0:ea44dc9ed014 160 {
joeverbout 0:ea44dc9ed014 161 for (int x = 0; x < src_size.width; ++x)
joeverbout 0:ea44dc9ed014 162 {
joeverbout 0:ea44dc9ed014 163 projector_.mapForward(static_cast<float>(x), static_cast<float>(y), u, v);
joeverbout 0:ea44dc9ed014 164 tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
joeverbout 0:ea44dc9ed014 165 br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
joeverbout 0:ea44dc9ed014 166 }
joeverbout 0:ea44dc9ed014 167 }
joeverbout 0:ea44dc9ed014 168
joeverbout 0:ea44dc9ed014 169 dst_tl.x = static_cast<int>(tl_uf);
joeverbout 0:ea44dc9ed014 170 dst_tl.y = static_cast<int>(tl_vf);
joeverbout 0:ea44dc9ed014 171 dst_br.x = static_cast<int>(br_uf);
joeverbout 0:ea44dc9ed014 172 dst_br.y = static_cast<int>(br_vf);
joeverbout 0:ea44dc9ed014 173 }
joeverbout 0:ea44dc9ed014 174
joeverbout 0:ea44dc9ed014 175
joeverbout 0:ea44dc9ed014 176 template <class P>
joeverbout 0:ea44dc9ed014 177 void RotationWarperBase<P>::detectResultRoiByBorder(Size src_size, Point &dst_tl, Point &dst_br)
joeverbout 0:ea44dc9ed014 178 {
joeverbout 0:ea44dc9ed014 179 float tl_uf = std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 180 float tl_vf = std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 181 float br_uf = -std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 182 float br_vf = -std::numeric_limits<float>::max();
joeverbout 0:ea44dc9ed014 183
joeverbout 0:ea44dc9ed014 184 float u, v;
joeverbout 0:ea44dc9ed014 185 for (float x = 0; x < src_size.width; ++x)
joeverbout 0:ea44dc9ed014 186 {
joeverbout 0:ea44dc9ed014 187 projector_.mapForward(static_cast<float>(x), 0, u, v);
joeverbout 0:ea44dc9ed014 188 tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
joeverbout 0:ea44dc9ed014 189 br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
joeverbout 0:ea44dc9ed014 190
joeverbout 0:ea44dc9ed014 191 projector_.mapForward(static_cast<float>(x), static_cast<float>(src_size.height - 1), u, v);
joeverbout 0:ea44dc9ed014 192 tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
joeverbout 0:ea44dc9ed014 193 br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
joeverbout 0:ea44dc9ed014 194 }
joeverbout 0:ea44dc9ed014 195 for (int y = 0; y < src_size.height; ++y)
joeverbout 0:ea44dc9ed014 196 {
joeverbout 0:ea44dc9ed014 197 projector_.mapForward(0, static_cast<float>(y), u, v);
joeverbout 0:ea44dc9ed014 198 tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
joeverbout 0:ea44dc9ed014 199 br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
joeverbout 0:ea44dc9ed014 200
joeverbout 0:ea44dc9ed014 201 projector_.mapForward(static_cast<float>(src_size.width - 1), static_cast<float>(y), u, v);
joeverbout 0:ea44dc9ed014 202 tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
joeverbout 0:ea44dc9ed014 203 br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
joeverbout 0:ea44dc9ed014 204 }
joeverbout 0:ea44dc9ed014 205
joeverbout 0:ea44dc9ed014 206 dst_tl.x = static_cast<int>(tl_uf);
joeverbout 0:ea44dc9ed014 207 dst_tl.y = static_cast<int>(tl_vf);
joeverbout 0:ea44dc9ed014 208 dst_br.x = static_cast<int>(br_uf);
joeverbout 0:ea44dc9ed014 209 dst_br.y = static_cast<int>(br_vf);
joeverbout 0:ea44dc9ed014 210 }
joeverbout 0:ea44dc9ed014 211
joeverbout 0:ea44dc9ed014 212
joeverbout 0:ea44dc9ed014 213 inline
joeverbout 0:ea44dc9ed014 214 void PlaneProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 215 {
joeverbout 0:ea44dc9ed014 216 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 217 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 218 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 219
joeverbout 0:ea44dc9ed014 220 x_ = t[0] + x_ / z_ * (1 - t[2]);
joeverbout 0:ea44dc9ed014 221 y_ = t[1] + y_ / z_ * (1 - t[2]);
joeverbout 0:ea44dc9ed014 222
joeverbout 0:ea44dc9ed014 223 u = scale * x_;
joeverbout 0:ea44dc9ed014 224 v = scale * y_;
joeverbout 0:ea44dc9ed014 225 }
joeverbout 0:ea44dc9ed014 226
joeverbout 0:ea44dc9ed014 227
joeverbout 0:ea44dc9ed014 228 inline
joeverbout 0:ea44dc9ed014 229 void PlaneProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 230 {
joeverbout 0:ea44dc9ed014 231 u = u / scale - t[0];
joeverbout 0:ea44dc9ed014 232 v = v / scale - t[1];
joeverbout 0:ea44dc9ed014 233
joeverbout 0:ea44dc9ed014 234 float z;
joeverbout 0:ea44dc9ed014 235 x = k_rinv[0] * u + k_rinv[1] * v + k_rinv[2] * (1 - t[2]);
joeverbout 0:ea44dc9ed014 236 y = k_rinv[3] * u + k_rinv[4] * v + k_rinv[5] * (1 - t[2]);
joeverbout 0:ea44dc9ed014 237 z = k_rinv[6] * u + k_rinv[7] * v + k_rinv[8] * (1 - t[2]);
joeverbout 0:ea44dc9ed014 238
joeverbout 0:ea44dc9ed014 239 x /= z;
joeverbout 0:ea44dc9ed014 240 y /= z;
joeverbout 0:ea44dc9ed014 241 }
joeverbout 0:ea44dc9ed014 242
joeverbout 0:ea44dc9ed014 243
joeverbout 0:ea44dc9ed014 244 inline
joeverbout 0:ea44dc9ed014 245 void SphericalProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 246 {
joeverbout 0:ea44dc9ed014 247 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 248 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 249 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 250
joeverbout 0:ea44dc9ed014 251 u = scale * atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 252 float w = y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_);
joeverbout 0:ea44dc9ed014 253 v = scale * (static_cast<float>(CV_PI) - acosf(w == w ? w : 0));
joeverbout 0:ea44dc9ed014 254 }
joeverbout 0:ea44dc9ed014 255
joeverbout 0:ea44dc9ed014 256
joeverbout 0:ea44dc9ed014 257 inline
joeverbout 0:ea44dc9ed014 258 void SphericalProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 259 {
joeverbout 0:ea44dc9ed014 260 u /= scale;
joeverbout 0:ea44dc9ed014 261 v /= scale;
joeverbout 0:ea44dc9ed014 262
joeverbout 0:ea44dc9ed014 263 float sinv = sinf(static_cast<float>(CV_PI) - v);
joeverbout 0:ea44dc9ed014 264 float x_ = sinv * sinf(u);
joeverbout 0:ea44dc9ed014 265 float y_ = cosf(static_cast<float>(CV_PI) - v);
joeverbout 0:ea44dc9ed014 266 float z_ = sinv * cosf(u);
joeverbout 0:ea44dc9ed014 267
joeverbout 0:ea44dc9ed014 268 float z;
joeverbout 0:ea44dc9ed014 269 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 270 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 271 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 272
joeverbout 0:ea44dc9ed014 273 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 274 else x = y = -1;
joeverbout 0:ea44dc9ed014 275 }
joeverbout 0:ea44dc9ed014 276
joeverbout 0:ea44dc9ed014 277
joeverbout 0:ea44dc9ed014 278 inline
joeverbout 0:ea44dc9ed014 279 void CylindricalProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 280 {
joeverbout 0:ea44dc9ed014 281 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 282 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 283 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 284
joeverbout 0:ea44dc9ed014 285 u = scale * atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 286 v = scale * y_ / sqrtf(x_ * x_ + z_ * z_);
joeverbout 0:ea44dc9ed014 287 }
joeverbout 0:ea44dc9ed014 288
joeverbout 0:ea44dc9ed014 289
joeverbout 0:ea44dc9ed014 290 inline
joeverbout 0:ea44dc9ed014 291 void CylindricalProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 292 {
joeverbout 0:ea44dc9ed014 293 u /= scale;
joeverbout 0:ea44dc9ed014 294 v /= scale;
joeverbout 0:ea44dc9ed014 295
joeverbout 0:ea44dc9ed014 296 float x_ = sinf(u);
joeverbout 0:ea44dc9ed014 297 float y_ = v;
joeverbout 0:ea44dc9ed014 298 float z_ = cosf(u);
joeverbout 0:ea44dc9ed014 299
joeverbout 0:ea44dc9ed014 300 float z;
joeverbout 0:ea44dc9ed014 301 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 302 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 303 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 304
joeverbout 0:ea44dc9ed014 305 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 306 else x = y = -1;
joeverbout 0:ea44dc9ed014 307 }
joeverbout 0:ea44dc9ed014 308
joeverbout 0:ea44dc9ed014 309 inline
joeverbout 0:ea44dc9ed014 310 void FisheyeProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 311 {
joeverbout 0:ea44dc9ed014 312 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 313 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 314 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 315
joeverbout 0:ea44dc9ed014 316 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 317 float v_ = (float)CV_PI - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 318
joeverbout 0:ea44dc9ed014 319 u = scale * v_ * cosf(u_);
joeverbout 0:ea44dc9ed014 320 v = scale * v_ * sinf(u_);
joeverbout 0:ea44dc9ed014 321 }
joeverbout 0:ea44dc9ed014 322
joeverbout 0:ea44dc9ed014 323 inline
joeverbout 0:ea44dc9ed014 324 void FisheyeProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 325 {
joeverbout 0:ea44dc9ed014 326 u /= scale;
joeverbout 0:ea44dc9ed014 327 v /= scale;
joeverbout 0:ea44dc9ed014 328
joeverbout 0:ea44dc9ed014 329 float u_ = atan2f(v, u);
joeverbout 0:ea44dc9ed014 330 float v_ = sqrtf(u*u + v*v);
joeverbout 0:ea44dc9ed014 331
joeverbout 0:ea44dc9ed014 332 float sinv = sinf((float)CV_PI - v_);
joeverbout 0:ea44dc9ed014 333 float x_ = sinv * sinf(u_);
joeverbout 0:ea44dc9ed014 334 float y_ = cosf((float)CV_PI - v_);
joeverbout 0:ea44dc9ed014 335 float z_ = sinv * cosf(u_);
joeverbout 0:ea44dc9ed014 336
joeverbout 0:ea44dc9ed014 337 float z;
joeverbout 0:ea44dc9ed014 338 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 339 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 340 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 341
joeverbout 0:ea44dc9ed014 342 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 343 else x = y = -1;
joeverbout 0:ea44dc9ed014 344 }
joeverbout 0:ea44dc9ed014 345
joeverbout 0:ea44dc9ed014 346 inline
joeverbout 0:ea44dc9ed014 347 void StereographicProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 348 {
joeverbout 0:ea44dc9ed014 349 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 350 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 351 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 352
joeverbout 0:ea44dc9ed014 353 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 354 float v_ = (float)CV_PI - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 355
joeverbout 0:ea44dc9ed014 356 float r = sinf(v_) / (1 - cosf(v_));
joeverbout 0:ea44dc9ed014 357
joeverbout 0:ea44dc9ed014 358 u = scale * r * cos(u_);
joeverbout 0:ea44dc9ed014 359 v = scale * r * sin(u_);
joeverbout 0:ea44dc9ed014 360 }
joeverbout 0:ea44dc9ed014 361
joeverbout 0:ea44dc9ed014 362 inline
joeverbout 0:ea44dc9ed014 363 void StereographicProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 364 {
joeverbout 0:ea44dc9ed014 365 u /= scale;
joeverbout 0:ea44dc9ed014 366 v /= scale;
joeverbout 0:ea44dc9ed014 367
joeverbout 0:ea44dc9ed014 368 float u_ = atan2f(v, u);
joeverbout 0:ea44dc9ed014 369 float r = sqrtf(u*u + v*v);
joeverbout 0:ea44dc9ed014 370 float v_ = 2 * atanf(1.f / r);
joeverbout 0:ea44dc9ed014 371
joeverbout 0:ea44dc9ed014 372 float sinv = sinf((float)CV_PI - v_);
joeverbout 0:ea44dc9ed014 373 float x_ = sinv * sinf(u_);
joeverbout 0:ea44dc9ed014 374 float y_ = cosf((float)CV_PI - v_);
joeverbout 0:ea44dc9ed014 375 float z_ = sinv * cosf(u_);
joeverbout 0:ea44dc9ed014 376
joeverbout 0:ea44dc9ed014 377 float z;
joeverbout 0:ea44dc9ed014 378 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 379 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 380 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 381
joeverbout 0:ea44dc9ed014 382 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 383 else x = y = -1;
joeverbout 0:ea44dc9ed014 384 }
joeverbout 0:ea44dc9ed014 385
joeverbout 0:ea44dc9ed014 386 inline
joeverbout 0:ea44dc9ed014 387 void CompressedRectilinearProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 388 {
joeverbout 0:ea44dc9ed014 389 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 390 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 391 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 392
joeverbout 0:ea44dc9ed014 393 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 394 float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 395
joeverbout 0:ea44dc9ed014 396 u = scale * a * tanf(u_ / a);
joeverbout 0:ea44dc9ed014 397 v = scale * b * tanf(v_) / cosf(u_);
joeverbout 0:ea44dc9ed014 398 }
joeverbout 0:ea44dc9ed014 399
joeverbout 0:ea44dc9ed014 400 inline
joeverbout 0:ea44dc9ed014 401 void CompressedRectilinearProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 402 {
joeverbout 0:ea44dc9ed014 403 u /= scale;
joeverbout 0:ea44dc9ed014 404 v /= scale;
joeverbout 0:ea44dc9ed014 405
joeverbout 0:ea44dc9ed014 406 float aatg = a * atanf(u / a);
joeverbout 0:ea44dc9ed014 407 float u_ = aatg;
joeverbout 0:ea44dc9ed014 408 float v_ = atanf(v * cosf(aatg) / b);
joeverbout 0:ea44dc9ed014 409
joeverbout 0:ea44dc9ed014 410 float cosv = cosf(v_);
joeverbout 0:ea44dc9ed014 411 float x_ = cosv * sinf(u_);
joeverbout 0:ea44dc9ed014 412 float y_ = sinf(v_);
joeverbout 0:ea44dc9ed014 413 float z_ = cosv * cosf(u_);
joeverbout 0:ea44dc9ed014 414
joeverbout 0:ea44dc9ed014 415 float z;
joeverbout 0:ea44dc9ed014 416 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 417 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 418 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 419
joeverbout 0:ea44dc9ed014 420 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 421 else x = y = -1;
joeverbout 0:ea44dc9ed014 422 }
joeverbout 0:ea44dc9ed014 423
joeverbout 0:ea44dc9ed014 424 inline
joeverbout 0:ea44dc9ed014 425 void CompressedRectilinearPortraitProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 426 {
joeverbout 0:ea44dc9ed014 427 float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 428 float x_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 429 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 430
joeverbout 0:ea44dc9ed014 431 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 432 float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 433
joeverbout 0:ea44dc9ed014 434 u = - scale * a * tanf(u_ / a);
joeverbout 0:ea44dc9ed014 435 v = scale * b * tanf(v_) / cosf(u_);
joeverbout 0:ea44dc9ed014 436 }
joeverbout 0:ea44dc9ed014 437
joeverbout 0:ea44dc9ed014 438 inline
joeverbout 0:ea44dc9ed014 439 void CompressedRectilinearPortraitProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 440 {
joeverbout 0:ea44dc9ed014 441 u /= - scale;
joeverbout 0:ea44dc9ed014 442 v /= scale;
joeverbout 0:ea44dc9ed014 443
joeverbout 0:ea44dc9ed014 444 float aatg = a * atanf(u / a);
joeverbout 0:ea44dc9ed014 445 float u_ = aatg;
joeverbout 0:ea44dc9ed014 446 float v_ = atanf(v * cosf( aatg ) / b);
joeverbout 0:ea44dc9ed014 447
joeverbout 0:ea44dc9ed014 448 float cosv = cosf(v_);
joeverbout 0:ea44dc9ed014 449 float y_ = cosv * sinf(u_);
joeverbout 0:ea44dc9ed014 450 float x_ = sinf(v_);
joeverbout 0:ea44dc9ed014 451 float z_ = cosv * cosf(u_);
joeverbout 0:ea44dc9ed014 452
joeverbout 0:ea44dc9ed014 453 float z;
joeverbout 0:ea44dc9ed014 454 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 455 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 456 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 457
joeverbout 0:ea44dc9ed014 458 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 459 else x = y = -1;
joeverbout 0:ea44dc9ed014 460 }
joeverbout 0:ea44dc9ed014 461
joeverbout 0:ea44dc9ed014 462 inline
joeverbout 0:ea44dc9ed014 463 void PaniniProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 464 {
joeverbout 0:ea44dc9ed014 465 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 466 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 467 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 468
joeverbout 0:ea44dc9ed014 469 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 470 float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 471
joeverbout 0:ea44dc9ed014 472 float tg = a * tanf(u_ / a);
joeverbout 0:ea44dc9ed014 473 u = scale * tg;
joeverbout 0:ea44dc9ed014 474
joeverbout 0:ea44dc9ed014 475 float sinu = sinf(u_);
joeverbout 0:ea44dc9ed014 476 if ( fabs(sinu) < 1E-7 )
joeverbout 0:ea44dc9ed014 477 v = scale * b * tanf(v_);
joeverbout 0:ea44dc9ed014 478 else
joeverbout 0:ea44dc9ed014 479 v = scale * b * tg * tanf(v_) / sinu;
joeverbout 0:ea44dc9ed014 480 }
joeverbout 0:ea44dc9ed014 481
joeverbout 0:ea44dc9ed014 482 inline
joeverbout 0:ea44dc9ed014 483 void PaniniProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 484 {
joeverbout 0:ea44dc9ed014 485 u /= scale;
joeverbout 0:ea44dc9ed014 486 v /= scale;
joeverbout 0:ea44dc9ed014 487
joeverbout 0:ea44dc9ed014 488 float lamda = a * atanf(u / a);
joeverbout 0:ea44dc9ed014 489 float u_ = lamda;
joeverbout 0:ea44dc9ed014 490
joeverbout 0:ea44dc9ed014 491 float v_;
joeverbout 0:ea44dc9ed014 492 if ( fabs(lamda) > 1E-7)
joeverbout 0:ea44dc9ed014 493 v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda / a)));
joeverbout 0:ea44dc9ed014 494 else
joeverbout 0:ea44dc9ed014 495 v_ = atanf(v / b);
joeverbout 0:ea44dc9ed014 496
joeverbout 0:ea44dc9ed014 497 float cosv = cosf(v_);
joeverbout 0:ea44dc9ed014 498 float x_ = cosv * sinf(u_);
joeverbout 0:ea44dc9ed014 499 float y_ = sinf(v_);
joeverbout 0:ea44dc9ed014 500 float z_ = cosv * cosf(u_);
joeverbout 0:ea44dc9ed014 501
joeverbout 0:ea44dc9ed014 502 float z;
joeverbout 0:ea44dc9ed014 503 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 504 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 505 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 506
joeverbout 0:ea44dc9ed014 507 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 508 else x = y = -1;
joeverbout 0:ea44dc9ed014 509 }
joeverbout 0:ea44dc9ed014 510
joeverbout 0:ea44dc9ed014 511 inline
joeverbout 0:ea44dc9ed014 512 void PaniniPortraitProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 513 {
joeverbout 0:ea44dc9ed014 514 float y_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 515 float x_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 516 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 517
joeverbout 0:ea44dc9ed014 518 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 519 float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 520
joeverbout 0:ea44dc9ed014 521 float tg = a * tanf(u_ / a);
joeverbout 0:ea44dc9ed014 522 u = - scale * tg;
joeverbout 0:ea44dc9ed014 523
joeverbout 0:ea44dc9ed014 524 float sinu = sinf( u_ );
joeverbout 0:ea44dc9ed014 525 if ( fabs(sinu) < 1E-7 )
joeverbout 0:ea44dc9ed014 526 v = scale * b * tanf(v_);
joeverbout 0:ea44dc9ed014 527 else
joeverbout 0:ea44dc9ed014 528 v = scale * b * tg * tanf(v_) / sinu;
joeverbout 0:ea44dc9ed014 529 }
joeverbout 0:ea44dc9ed014 530
joeverbout 0:ea44dc9ed014 531 inline
joeverbout 0:ea44dc9ed014 532 void PaniniPortraitProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 533 {
joeverbout 0:ea44dc9ed014 534 u /= - scale;
joeverbout 0:ea44dc9ed014 535 v /= scale;
joeverbout 0:ea44dc9ed014 536
joeverbout 0:ea44dc9ed014 537 float lamda = a * atanf(u / a);
joeverbout 0:ea44dc9ed014 538 float u_ = lamda;
joeverbout 0:ea44dc9ed014 539
joeverbout 0:ea44dc9ed014 540 float v_;
joeverbout 0:ea44dc9ed014 541 if ( fabs(lamda) > 1E-7)
joeverbout 0:ea44dc9ed014 542 v_ = atanf(v * sinf(lamda) / (b * a * tanf(lamda/a)));
joeverbout 0:ea44dc9ed014 543 else
joeverbout 0:ea44dc9ed014 544 v_ = atanf(v / b);
joeverbout 0:ea44dc9ed014 545
joeverbout 0:ea44dc9ed014 546 float cosv = cosf(v_);
joeverbout 0:ea44dc9ed014 547 float y_ = cosv * sinf(u_);
joeverbout 0:ea44dc9ed014 548 float x_ = sinf(v_);
joeverbout 0:ea44dc9ed014 549 float z_ = cosv * cosf(u_);
joeverbout 0:ea44dc9ed014 550
joeverbout 0:ea44dc9ed014 551 float z;
joeverbout 0:ea44dc9ed014 552 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 553 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 554 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 555
joeverbout 0:ea44dc9ed014 556 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 557 else x = y = -1;
joeverbout 0:ea44dc9ed014 558 }
joeverbout 0:ea44dc9ed014 559
joeverbout 0:ea44dc9ed014 560 inline
joeverbout 0:ea44dc9ed014 561 void MercatorProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 562 {
joeverbout 0:ea44dc9ed014 563 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 564 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 565 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 566
joeverbout 0:ea44dc9ed014 567 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 568 float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 569
joeverbout 0:ea44dc9ed014 570 u = scale * u_;
joeverbout 0:ea44dc9ed014 571 v = scale * logf( tanf( (float)(CV_PI/4) + v_/2 ) );
joeverbout 0:ea44dc9ed014 572 }
joeverbout 0:ea44dc9ed014 573
joeverbout 0:ea44dc9ed014 574 inline
joeverbout 0:ea44dc9ed014 575 void MercatorProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 576 {
joeverbout 0:ea44dc9ed014 577 u /= scale;
joeverbout 0:ea44dc9ed014 578 v /= scale;
joeverbout 0:ea44dc9ed014 579
joeverbout 0:ea44dc9ed014 580 float v_ = atanf( sinhf(v) );
joeverbout 0:ea44dc9ed014 581 float u_ = u;
joeverbout 0:ea44dc9ed014 582
joeverbout 0:ea44dc9ed014 583 float cosv = cosf(v_);
joeverbout 0:ea44dc9ed014 584 float x_ = cosv * sinf(u_);
joeverbout 0:ea44dc9ed014 585 float y_ = sinf(v_);
joeverbout 0:ea44dc9ed014 586 float z_ = cosv * cosf(u_);
joeverbout 0:ea44dc9ed014 587
joeverbout 0:ea44dc9ed014 588 float z;
joeverbout 0:ea44dc9ed014 589 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 590 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 591 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 592
joeverbout 0:ea44dc9ed014 593 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 594 else x = y = -1;
joeverbout 0:ea44dc9ed014 595 }
joeverbout 0:ea44dc9ed014 596
joeverbout 0:ea44dc9ed014 597 inline
joeverbout 0:ea44dc9ed014 598 void TransverseMercatorProjector::mapForward(float x, float y, float &u, float &v)
joeverbout 0:ea44dc9ed014 599 {
joeverbout 0:ea44dc9ed014 600 float x_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 601 float y_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 602 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 603
joeverbout 0:ea44dc9ed014 604 float u_ = atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 605 float v_ = asinf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_));
joeverbout 0:ea44dc9ed014 606
joeverbout 0:ea44dc9ed014 607 float B = cosf(v_) * sinf(u_);
joeverbout 0:ea44dc9ed014 608
joeverbout 0:ea44dc9ed014 609 u = scale / 2 * logf( (1+B) / (1-B) );
joeverbout 0:ea44dc9ed014 610 v = scale * atan2f(tanf(v_), cosf(u_));
joeverbout 0:ea44dc9ed014 611 }
joeverbout 0:ea44dc9ed014 612
joeverbout 0:ea44dc9ed014 613 inline
joeverbout 0:ea44dc9ed014 614 void TransverseMercatorProjector::mapBackward(float u, float v, float &x, float &y)
joeverbout 0:ea44dc9ed014 615 {
joeverbout 0:ea44dc9ed014 616 u /= scale;
joeverbout 0:ea44dc9ed014 617 v /= scale;
joeverbout 0:ea44dc9ed014 618
joeverbout 0:ea44dc9ed014 619 float v_ = asinf( sinf(v) / coshf(u) );
joeverbout 0:ea44dc9ed014 620 float u_ = atan2f( sinhf(u), cos(v) );
joeverbout 0:ea44dc9ed014 621
joeverbout 0:ea44dc9ed014 622 float cosv = cosf(v_);
joeverbout 0:ea44dc9ed014 623 float x_ = cosv * sinf(u_);
joeverbout 0:ea44dc9ed014 624 float y_ = sinf(v_);
joeverbout 0:ea44dc9ed014 625 float z_ = cosv * cosf(u_);
joeverbout 0:ea44dc9ed014 626
joeverbout 0:ea44dc9ed014 627 float z;
joeverbout 0:ea44dc9ed014 628 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 629 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 630 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 631
joeverbout 0:ea44dc9ed014 632 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 633 else x = y = -1;
joeverbout 0:ea44dc9ed014 634 }
joeverbout 0:ea44dc9ed014 635
joeverbout 0:ea44dc9ed014 636 inline
joeverbout 0:ea44dc9ed014 637 void SphericalPortraitProjector::mapForward(float x, float y, float &u0, float &v0)
joeverbout 0:ea44dc9ed014 638 {
joeverbout 0:ea44dc9ed014 639 float x0_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 640 float y0_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 641 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 642
joeverbout 0:ea44dc9ed014 643 float x_ = y0_;
joeverbout 0:ea44dc9ed014 644 float y_ = x0_;
joeverbout 0:ea44dc9ed014 645 float u, v;
joeverbout 0:ea44dc9ed014 646
joeverbout 0:ea44dc9ed014 647 u = scale * atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 648 v = scale * (static_cast<float>(CV_PI) - acosf(y_ / sqrtf(x_ * x_ + y_ * y_ + z_ * z_)));
joeverbout 0:ea44dc9ed014 649
joeverbout 0:ea44dc9ed014 650 u0 = -u;//v;
joeverbout 0:ea44dc9ed014 651 v0 = v;//u;
joeverbout 0:ea44dc9ed014 652 }
joeverbout 0:ea44dc9ed014 653
joeverbout 0:ea44dc9ed014 654
joeverbout 0:ea44dc9ed014 655 inline
joeverbout 0:ea44dc9ed014 656 void SphericalPortraitProjector::mapBackward(float u0, float v0, float &x, float &y)
joeverbout 0:ea44dc9ed014 657 {
joeverbout 0:ea44dc9ed014 658 float u, v;
joeverbout 0:ea44dc9ed014 659 u = -u0;//v0;
joeverbout 0:ea44dc9ed014 660 v = v0;//u0;
joeverbout 0:ea44dc9ed014 661
joeverbout 0:ea44dc9ed014 662 u /= scale;
joeverbout 0:ea44dc9ed014 663 v /= scale;
joeverbout 0:ea44dc9ed014 664
joeverbout 0:ea44dc9ed014 665 float sinv = sinf(static_cast<float>(CV_PI) - v);
joeverbout 0:ea44dc9ed014 666 float x0_ = sinv * sinf(u);
joeverbout 0:ea44dc9ed014 667 float y0_ = cosf(static_cast<float>(CV_PI) - v);
joeverbout 0:ea44dc9ed014 668 float z_ = sinv * cosf(u);
joeverbout 0:ea44dc9ed014 669
joeverbout 0:ea44dc9ed014 670 float x_ = y0_;
joeverbout 0:ea44dc9ed014 671 float y_ = x0_;
joeverbout 0:ea44dc9ed014 672
joeverbout 0:ea44dc9ed014 673 float z;
joeverbout 0:ea44dc9ed014 674 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 675 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 676 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 677
joeverbout 0:ea44dc9ed014 678 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 679 else x = y = -1;
joeverbout 0:ea44dc9ed014 680 }
joeverbout 0:ea44dc9ed014 681
joeverbout 0:ea44dc9ed014 682 inline
joeverbout 0:ea44dc9ed014 683 void CylindricalPortraitProjector::mapForward(float x, float y, float &u0, float &v0)
joeverbout 0:ea44dc9ed014 684 {
joeverbout 0:ea44dc9ed014 685 float x0_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 686 float y0_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 687 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 688
joeverbout 0:ea44dc9ed014 689 float x_ = y0_;
joeverbout 0:ea44dc9ed014 690 float y_ = x0_;
joeverbout 0:ea44dc9ed014 691 float u, v;
joeverbout 0:ea44dc9ed014 692
joeverbout 0:ea44dc9ed014 693 u = scale * atan2f(x_, z_);
joeverbout 0:ea44dc9ed014 694 v = scale * y_ / sqrtf(x_ * x_ + z_ * z_);
joeverbout 0:ea44dc9ed014 695
joeverbout 0:ea44dc9ed014 696 u0 = -u;//v;
joeverbout 0:ea44dc9ed014 697 v0 = v;//u;
joeverbout 0:ea44dc9ed014 698 }
joeverbout 0:ea44dc9ed014 699
joeverbout 0:ea44dc9ed014 700
joeverbout 0:ea44dc9ed014 701 inline
joeverbout 0:ea44dc9ed014 702 void CylindricalPortraitProjector::mapBackward(float u0, float v0, float &x, float &y)
joeverbout 0:ea44dc9ed014 703 {
joeverbout 0:ea44dc9ed014 704 float u, v;
joeverbout 0:ea44dc9ed014 705 u = -u0;//v0;
joeverbout 0:ea44dc9ed014 706 v = v0;//u0;
joeverbout 0:ea44dc9ed014 707
joeverbout 0:ea44dc9ed014 708 u /= scale;
joeverbout 0:ea44dc9ed014 709 v /= scale;
joeverbout 0:ea44dc9ed014 710
joeverbout 0:ea44dc9ed014 711 float x0_ = sinf(u);
joeverbout 0:ea44dc9ed014 712 float y0_ = v;
joeverbout 0:ea44dc9ed014 713 float z_ = cosf(u);
joeverbout 0:ea44dc9ed014 714
joeverbout 0:ea44dc9ed014 715 float x_ = y0_;
joeverbout 0:ea44dc9ed014 716 float y_ = x0_;
joeverbout 0:ea44dc9ed014 717
joeverbout 0:ea44dc9ed014 718 float z;
joeverbout 0:ea44dc9ed014 719 x = k_rinv[0] * x_ + k_rinv[1] * y_ + k_rinv[2] * z_;
joeverbout 0:ea44dc9ed014 720 y = k_rinv[3] * x_ + k_rinv[4] * y_ + k_rinv[5] * z_;
joeverbout 0:ea44dc9ed014 721 z = k_rinv[6] * x_ + k_rinv[7] * y_ + k_rinv[8] * z_;
joeverbout 0:ea44dc9ed014 722
joeverbout 0:ea44dc9ed014 723 if (z > 0) { x /= z; y /= z; }
joeverbout 0:ea44dc9ed014 724 else x = y = -1;
joeverbout 0:ea44dc9ed014 725 }
joeverbout 0:ea44dc9ed014 726
joeverbout 0:ea44dc9ed014 727 inline
joeverbout 0:ea44dc9ed014 728 void PlanePortraitProjector::mapForward(float x, float y, float &u0, float &v0)
joeverbout 0:ea44dc9ed014 729 {
joeverbout 0:ea44dc9ed014 730 float x0_ = r_kinv[0] * x + r_kinv[1] * y + r_kinv[2];
joeverbout 0:ea44dc9ed014 731 float y0_ = r_kinv[3] * x + r_kinv[4] * y + r_kinv[5];
joeverbout 0:ea44dc9ed014 732 float z_ = r_kinv[6] * x + r_kinv[7] * y + r_kinv[8];
joeverbout 0:ea44dc9ed014 733
joeverbout 0:ea44dc9ed014 734 float x_ = y0_;
joeverbout 0:ea44dc9ed014 735 float y_ = x0_;
joeverbout 0:ea44dc9ed014 736
joeverbout 0:ea44dc9ed014 737 x_ = t[0] + x_ / z_ * (1 - t[2]);
joeverbout 0:ea44dc9ed014 738 y_ = t[1] + y_ / z_ * (1 - t[2]);
joeverbout 0:ea44dc9ed014 739
joeverbout 0:ea44dc9ed014 740 float u,v;
joeverbout 0:ea44dc9ed014 741 u = scale * x_;
joeverbout 0:ea44dc9ed014 742 v = scale * y_;
joeverbout 0:ea44dc9ed014 743
joeverbout 0:ea44dc9ed014 744 u0 = -u;
joeverbout 0:ea44dc9ed014 745 v0 = v;
joeverbout 0:ea44dc9ed014 746 }
joeverbout 0:ea44dc9ed014 747
joeverbout 0:ea44dc9ed014 748
joeverbout 0:ea44dc9ed014 749 inline
joeverbout 0:ea44dc9ed014 750 void PlanePortraitProjector::mapBackward(float u0, float v0, float &x, float &y)
joeverbout 0:ea44dc9ed014 751 {
joeverbout 0:ea44dc9ed014 752 float u, v;
joeverbout 0:ea44dc9ed014 753 u = -u0;
joeverbout 0:ea44dc9ed014 754 v = v0;
joeverbout 0:ea44dc9ed014 755
joeverbout 0:ea44dc9ed014 756 u = u / scale - t[0];
joeverbout 0:ea44dc9ed014 757 v = v / scale - t[1];
joeverbout 0:ea44dc9ed014 758
joeverbout 0:ea44dc9ed014 759 float z;
joeverbout 0:ea44dc9ed014 760 x = k_rinv[0] * v + k_rinv[1] * u + k_rinv[2] * (1 - t[2]);
joeverbout 0:ea44dc9ed014 761 y = k_rinv[3] * v + k_rinv[4] * u + k_rinv[5] * (1 - t[2]);
joeverbout 0:ea44dc9ed014 762 z = k_rinv[6] * v + k_rinv[7] * u + k_rinv[8] * (1 - t[2]);
joeverbout 0:ea44dc9ed014 763
joeverbout 0:ea44dc9ed014 764 x /= z;
joeverbout 0:ea44dc9ed014 765 y /= z;
joeverbout 0:ea44dc9ed014 766 }
joeverbout 0:ea44dc9ed014 767
joeverbout 0:ea44dc9ed014 768
joeverbout 0:ea44dc9ed014 769 } // namespace detail
joeverbout 0:ea44dc9ed014 770 } // namespace cv
joeverbout 0:ea44dc9ed014 771
joeverbout 0:ea44dc9ed014 772 //! @endcond
joeverbout 0:ea44dc9ed014 773
joeverbout 0:ea44dc9ed014 774 #endif // __OPENCV_STITCHING_WARPERS_INL_HPP__
joeverbout 0:ea44dc9ed014 775