openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

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