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 
71 private:
72  cv::Mat unwarp(const cv::Mat &in_img);
73  std::tuple<double, double> fish2Eqt(const double x_dest,
74  const double y_dest,
75  const double W_rad);
76  void fish2Map();
77  void createMask();
78  cv::Mat deform( const cv::Mat &in_img);
79  void genScaleMap();
80  cv::Mat compenLightFO(const cv::Mat &in_img);
81  void createBlendMask();
82  void init();
83 
84  cv::Point2f findMatchLoc(const cv::Mat &Ref,
85  const cv::Mat &Tmpl,
86  const std::string &img_window,
87  const bool disable_display);
88 
89  std::tuple<std::vector<cv::Point2f>, std::vector<cv::Point2f> >
90  createControlPoints(const cv::Point2f &matchLocLeft,
91  const cv::Point2f &matchLocRight, const int row_start,
92  const int row_end, const int p_wid, const int p_x1,
93  const int p_x2, const int p_x2_ref);
94 
95  cv::Mat blendRight(const cv::Mat &bg1, const cv::Mat &bg2);
96  cv::Mat blendLeft(const cv::Mat &bg1, const cv::Mat &bg2);
97  cv::Mat blend(const cv::Mat &left_img, const cv::Mat &right_img_aligned);
98 
99  // Parameters
100  int m_hs_org; // height of the input image (2xfisheyes), e.g. 1920
101  int m_ws_org; // width of the input image (2xfisheyes), e.g. 3840
102  int m_ws; // width of one fisheye image, e.g. 1920
103  int m_hs; // height of one fisheye image, e.g. 1920
104  int m_ws2; // m_ws / 2
105  int m_hs2; // m_hs / 2
106  int m_hd; // height of destination pano image
107  int m_wd; // width of destination pano image
108  int m_wd2; // m_wd / 2
109  int m_hd2; // m_hd / 2
110  float m_in_fovd;
111  float m_inner_fovd; // used in creating mask
116  std::string m_map_path; // path of MLS grids
117  cv::Mat m_map_x; // used in deformation
118  cv::Mat m_map_y; // used in deformation
119  cv::Mat m_cir_mask;
121  cv::Mat m_binary_mask;
122  std::vector<int> m_blend_post;
123  cv::Mat m_scale_map;
124  cv::Mat m_mls_map_x;
125  cv::Mat m_mls_map_y;
126 
127 }; // class
128 
129 } // namespace
130 
131 #endif // FISHEYE_STITCHER_HPP
FisheyeStitcher(int width, int height, float in_fovd, bool enb_light_compen, bool enb_refine_align, bool save_unwarped, std::string map_path)
void createMask()
Mask creation for cropping image data inside the FOVD circle.
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.
void genScaleMap()
Fisheye Light Fall-off Compensation: Scale_Map Construction.
width
cv::Mat blendLeft(const cv::Mat &bg1, const cv::Mat &bg2)
Ramp blending on the left patch.
cv::Point2f findMatchLoc(const cv::Mat &Ref, const cv::Mat &Tmpl, const std::string &img_window, const bool disable_display)
Adaptive Alignment: Norm XCorr.
cv::Mat stitch(const cv::Mat &image1, const cv::Mat &image2)
single frame stitching
void fish2Map()
Map 2D fisheye image to 2D projected sphere.
std::tuple< double, double > fish2Eqt(const double x_dest, const double y_dest, const double W_rad)
Convert fisheye-vertical to equirectangular (reference: Panotool)
cv::Mat deform(const cv::Mat &in_img)
Rigid Moving Least Squares Interpolation.
std::vector< int > m_blend_post
cv::Mat unwarp(const cv::Mat &in_img)
Fisheye Unwarping.
void createBlendMask()
Create binary mask for blending.
cv::Mat blend(const cv::Mat &left_img, const cv::Mat &right_img_aligned)
Blending aligned images.
height
cv::Mat compenLightFO(const cv::Mat &in_img)
Fisheye Light Fall-off Compensation.
cv::Mat blendRight(const cv::Mat &bg1, const cv::Mat &bg2)
Ramp blending on the right patch.


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Mon May 3 2021 03:03:27