fisheye_stitcher.hpp
Go to the documentation of this file.
1 /* Copied from https://github.com/drNoob13/fisheyeStitcher/tree/45d65907b63c300523c6143794124411920cdbb9, 2020/02/05 */
2 /*
3 MIT License
4 
5 Copyright (c) 2018-2020 Tuan Phan Minh Ho
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 */
25 
26 //----------------------------------------------------------------------------//
27 // //
28 // This file is part of the fisheye stitcher project. //
29 // Copyright (c) 2018-2020 Tuan Phan Minh Ho <drnoob2013@gmail.com> //
30 // https://github.com/drNoob13/fisheyeStitcher //
31 // //
32 //----------------------------------------------------------------------------//
33 #ifndef FISHEYE_STITCHER_HPP
34 #define FISHEYE_STITCHER_HPP
35 
36 #include <iostream>
37 #include <fstream>
38 #include <string>
39 #include <vector>
40 #include <tuple>
41 
42 #include <opencv2/imgcodecs.hpp>
43 #include <opencv2/imgproc.hpp>
44 #include <opencv2/highgui.hpp> // for imshow
45 #include <opencv2/calib3d.hpp> // for findHomography
46 #include "opencv2/stitching/detail/seam_finders.hpp" // seam_finder
47 #include <opencv2/core/utility.hpp>
48 
49 #define MAX_FOVD 195.0f
50 
51 // Polynomial Coefficients
52 #define P1_ -7.5625e-17
53 #define P2_ 1.9589e-13
54 #define P3_ -1.8547e-10
55 #define P4_ 6.1997e-08
56 #define P5_ -6.9432e-05
57 #define P6_ 0.9976
58 
59 namespace stitcher
60 {
61 
63 {
64 public:
65  FisheyeStitcher(int width, int height, float in_fovd,
66  bool enb_light_compen, bool enb_refine_align,
67  bool save_unwarped, std::string map_path);
69  cv::Mat stitch(const cv::Mat& image1, const cv::Mat& image2,
70  uint16_t p_wid,
71  uint16_t p_x1,
72  uint16_t p_x2,
73  uint16_t row_start,
74  uint16_t row_end);
75 
76 private:
77  cv::Mat unwarp(const cv::Mat &in_img);
78  std::tuple<double, double> fish2Eqt(const double x_dest,
79  const double y_dest,
80  const double W_rad);
81  void fish2Map();
82  void createMask();
83  cv::Mat deform( const cv::Mat &in_img);
84  void genScaleMap();
85  cv::Mat compenLightFO(const cv::Mat &in_img);
86  void createBlendMask();
87  void init();
88 
89  cv::Point2f findMatchLoc(const cv::Mat &Ref,
90  const cv::Mat &Tmpl,
91  const std::string &img_window,
92  const bool disable_display);
93 
94  std::tuple<std::vector<cv::Point2f>, std::vector<cv::Point2f> >
95  createControlPoints(const cv::Point2f &matchLocLeft,
96  const cv::Point2f &matchLocRight, const int row_start,
97  const int row_end, const int p_wid, const int p_x1,
98  const int p_x2, const int p_x2_ref);
99 
100  cv::Mat blendRight(const cv::Mat &bg1, const cv::Mat &bg2);
101  cv::Mat blendLeft(const cv::Mat &bg1, const cv::Mat &bg2);
102  cv::Mat blend(const cv::Mat &left_img, const cv::Mat &right_img_aligned);
103 
104  // Parameters
105  int m_hs_org; // height of the input image (2xfisheyes), e.g. 1920
106  int m_ws_org; // width of the input image (2xfisheyes), e.g. 3840
107  int m_ws; // width of one fisheye image, e.g. 1920
108  int m_hs; // height of one fisheye image, e.g. 1920
109  int m_ws2; // m_ws / 2
110  int m_hs2; // m_hs / 2
111  int m_hd; // height of destination pano image
112  int m_wd; // width of destination pano image
113  int m_wd2; // m_wd / 2
114  int m_hd2; // m_hd / 2
115  float m_in_fovd;
116  float m_inner_fovd; // used in creating mask
121  std::string m_map_path; // path of MLS grids
122  cv::Mat m_map_x; // used in deformation
123  cv::Mat m_map_y; // used in deformation
124  cv::Mat m_cir_mask;
126  cv::Mat m_binary_mask;
127  std::vector<int> m_blend_post;
128  cv::Mat m_scale_map;
129  cv::Mat m_mls_map_x;
130  cv::Mat m_mls_map_y;
131 
132 }; // class
133 
134 } // namespace
135 
136 #endif // FISHEYE_STITCHER_HPP
stitcher::FisheyeStitcher::m_cir_mask
cv::Mat m_cir_mask
Definition: fisheye_stitcher.hpp:124
stitcher::FisheyeStitcher::compenLightFO
cv::Mat compenLightFO(const cv::Mat &in_img)
Fisheye Light Fall-off Compensation.
Definition: fisheye_stitcher.cpp:313
stitcher::FisheyeStitcher::m_wd2
int m_wd2
Definition: fisheye_stitcher.hpp:113
stitcher::FisheyeStitcher::m_disable_light_compen
bool m_disable_light_compen
Definition: fisheye_stitcher.hpp:118
stitcher::FisheyeStitcher::blendLeft
cv::Mat blendLeft(const cv::Mat &bg1, const cv::Mat &bg2)
Ramp blending on the left patch.
Definition: fisheye_stitcher.cpp:645
stitcher::FisheyeStitcher::m_hd2
int m_hd2
Definition: fisheye_stitcher.hpp:114
stitcher::FisheyeStitcher::genScaleMap
void genScaleMap()
Fisheye Light Fall-off Compensation: Scale_Map Construction.
Definition: fisheye_stitcher.cpp:219
stitcher::FisheyeStitcher::findMatchLoc
cv::Point2f findMatchLoc(const cv::Mat &Ref, const cv::Mat &Tmpl, const std::string &img_window, const bool disable_display)
Adaptive Alignment: Norm XCorr.
Definition: fisheye_stitcher.cpp:489
stitcher::FisheyeStitcher::m_inner_fovd
float m_inner_fovd
Definition: fisheye_stitcher.hpp:116
stitcher::FisheyeStitcher::m_ws2
int m_ws2
Definition: fisheye_stitcher.hpp:109
stitcher::FisheyeStitcher::m_hd
int m_hd
Definition: fisheye_stitcher.hpp:111
stitcher::FisheyeStitcher::fish2Eqt
std::tuple< double, double > fish2Eqt(const double x_dest, const double y_dest, const double W_rad)
Convert fisheye-vertical to equirectangular (reference: Panotool)
Definition: fisheye_stitcher.cpp:88
stitcher::FisheyeStitcher::m_mls_map_x
cv::Mat m_mls_map_x
Definition: fisheye_stitcher.hpp:129
stitcher::FisheyeStitcher::m_mls_map_y
cv::Mat m_mls_map_y
Definition: fisheye_stitcher.hpp:130
stitcher::FisheyeStitcher::m_ws
int m_ws
Definition: fisheye_stitcher.hpp:107
stitcher::FisheyeStitcher::m_enb_light_compen
bool m_enb_light_compen
Definition: fisheye_stitcher.hpp:117
stitcher::FisheyeStitcher::m_hs2
int m_hs2
Definition: fisheye_stitcher.hpp:110
stitcher::FisheyeStitcher::m_map_y
cv::Mat m_map_y
Definition: fisheye_stitcher.hpp:123
stitcher::FisheyeStitcher::createMask
void createMask()
Mask creation for cropping image data inside the FOVD circle.
Definition: fisheye_stitcher.cpp:172
stitcher::FisheyeStitcher::~FisheyeStitcher
~FisheyeStitcher()
Definition: fisheye_stitcher.cpp:65
stitcher::FisheyeStitcher::m_ws_org
int m_ws_org
Definition: fisheye_stitcher.hpp:106
stitcher::FisheyeStitcher::init
void init()
Definition: fisheye_stitcher.cpp:436
stitcher::FisheyeStitcher::m_binary_mask
cv::Mat m_binary_mask
Definition: fisheye_stitcher.hpp:126
stitcher::FisheyeStitcher::deform
cv::Mat deform(const cv::Mat &in_img)
Rigid Moving Least Squares Interpolation.
Definition: fisheye_stitcher.cpp:203
stitcher::FisheyeStitcher::m_in_fovd
float m_in_fovd
Definition: fisheye_stitcher.hpp:115
stitcher::FisheyeStitcher::m_hs
int m_hs
Definition: fisheye_stitcher.hpp:108
stitcher::FisheyeStitcher::unwarp
cv::Mat unwarp(const cv::Mat &in_img)
Fisheye Unwarping.
Definition: fisheye_stitcher.cpp:75
stitcher::FisheyeStitcher::m_enb_refine_align
bool m_enb_refine_align
Definition: fisheye_stitcher.hpp:119
stitcher::FisheyeStitcher::createBlendMask
void createBlendMask()
Create binary mask for blending.
Definition: fisheye_stitcher.cpp:340
stitcher::FisheyeStitcher::m_save_unwarped
bool m_save_unwarped
Definition: fisheye_stitcher.hpp:120
stitcher::FisheyeStitcher::fish2Map
void fish2Map()
Map 2D fisheye image to 2D projected sphere.
Definition: fisheye_stitcher.cpp:128
width
width
stitcher::FisheyeStitcher::m_hs_org
int m_hs_org
Definition: fisheye_stitcher.hpp:105
stitcher::FisheyeStitcher::m_inner_cir_mask
cv::Mat m_inner_cir_mask
Definition: fisheye_stitcher.hpp:125
stitcher::FisheyeStitcher::m_blend_post
std::vector< int > m_blend_post
Definition: fisheye_stitcher.hpp:127
stitcher::FisheyeStitcher::m_scale_map
cv::Mat m_scale_map
Definition: fisheye_stitcher.hpp:128
stitcher
Definition: fisheye_stitcher.cpp:35
stitcher::FisheyeStitcher::blend
cv::Mat blend(const cv::Mat &left_img, const cv::Mat &right_img_aligned)
Blending aligned images.
Definition: fisheye_stitcher.cpp:693
stitcher::FisheyeStitcher::blendRight
cv::Mat blendRight(const cv::Mat &bg1, const cv::Mat &bg2)
Ramp blending on the right patch.
Definition: fisheye_stitcher.cpp:598
height
height
stitcher::FisheyeStitcher::createControlPoints
std::tuple< std::vector< cv::Point2f >, std::vector< cv::Point2f > > createControlPoints(const cv::Point2f &matchLocLeft, const cv::Point2f &matchLocRight, const int row_start, const int row_end, const int p_wid, const int p_x1, const int p_x2, const int p_x2_ref)
Construct control points for affine2D.
Definition: fisheye_stitcher.cpp:546
stitcher::FisheyeStitcher::m_wd
int m_wd
Definition: fisheye_stitcher.hpp:112
stitcher::FisheyeStitcher::m_map_x
cv::Mat m_map_x
Definition: fisheye_stitcher.hpp:122
stitcher::FisheyeStitcher::FisheyeStitcher
FisheyeStitcher(int width, int height, float in_fovd, bool enb_light_compen, bool enb_refine_align, bool save_unwarped, std::string map_path)
Definition: fisheye_stitcher.cpp:38
stitcher::FisheyeStitcher::m_map_path
std::string m_map_path
Definition: fisheye_stitcher.hpp:121
stitcher::FisheyeStitcher
Definition: fisheye_stitcher.hpp:62
stitcher::FisheyeStitcher::stitch
cv::Mat stitch(const cv::Mat &image1, const cv::Mat &image2, uint16_t p_wid, uint16_t p_x1, uint16_t p_x2, uint16_t row_start, uint16_t row_end)
single frame stitching
Definition: fisheye_stitcher.cpp:795


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Fri May 16 2025 03:11:17