PanoWeave
Loading...
Searching...
No Matches
panoweave.hpp
1#pragma once
2#include <opencv2/core.hpp>
3#include <opencv2/core/affine.hpp>
4#include "basalt/calibration/calibration.hpp"
5
6namespace panoweave
7{
8 #define CvMatT CV_32FC
9 using ScalarT = float;
10 using CvFovT = cv::Size_<ScalarT>;
11 using CvAffine3T = cv::Affine3<ScalarT>;
12
18 struct DeviceData;
19
41 {
42 public:
43
51
63 Stitcher(const std::string &calibration_filepath);
64
77 Stitcher(const std::string &calibration_filepath, ScalarT depth);
78
91 Stitcher(const std::string &calibration_filepath, const cv::Mat &depth);
92
99
100
112 void loadCalibration(const std::string &calibration_filepath);
113
119 const basalt::Calibration<ScalarT> &calibration() const;
120
130 void setDepth(ScalarT depth);
131
142 void setDepth(const cv::Mat &depth);
143
144
150 cv::Size resolution() const;
151
159 cv::Size resolution(const cv::Size &resolution);
160
172 cv::Size resolution(int width, int height);
173
179 int width() const;
180
188 int width(int width);
189
195 int height() const;
196
204 int height(int height);
205
206
212 CvFovT fov() const;
213
224 CvFovT fov(CvFovT fov);
225
237 CvFovT fov(ScalarT fov_x, ScalarT fov_y);
238
244 ScalarT fovX() const;
245
256 ScalarT fovX(ScalarT fov);
257
263 ScalarT fovY() const;
264
275 ScalarT fovY(ScalarT fov);
276
277
283 ScalarT vignetteThreshold() const;
284
297 ScalarT vignetteThreshold(ScalarT threshold);
298
299
305 bool useMaskAsVignette() const;
306
319 bool useMaskAsVignette(bool use);
320
321
327 CvAffine3T transform() const;
328
341 CvAffine3T transform(const CvAffine3T &transform);
342
351 CvAffine3T transform(const CvAffine3T::Mat4 &affine);
352
362 CvAffine3T transform(const CvAffine3T::Mat3 &rotation, const CvAffine3T::Vec3 &translation = CvAffine3T::Vec3(0, 0, 0));
363
373 CvAffine3T transform(const CvAffine3T::Vec3 &rotation, const CvAffine3T::Vec3 &translation = CvAffine3T::Vec3(0, 0, 0));
374
375
387 void stitch(const std::vector<cv::Mat> &images, const std::vector<ScalarT> &exposure, cv::Mat &pano);
388
397 void stitch(const std::vector<cv::Mat> &images, cv::Mat &pano);
398
414 void stitch(const std::vector<cv::Mat> &images, const std::vector<ScalarT> &exposure, ScalarT depth, cv::Mat &pano);
415
431 void stitch(const std::vector<cv::Mat> &images, const std::vector<ScalarT> &exposure, const cv::Mat &depth, cv::Mat &pano);
432
433
444
445 private:
446
459 bool buildMaps();
460
469
478 void buildMask();
479
486
487 bool build_maps = true, build_vigns = true, build_mask = true, build_mirrors = true;
488 bool use_mask_as_vign = false;
489 int channels = 0;
490 cv::Size res;
491 std::vector<cv::UMat> maps;
492 ScalarT vign_thresh = 0.5;
493 cv::Mat depth_dynamic;
494 ScalarT depth_static = 0.0;
495 CvFovT fov_ = {M_PI * 2.0, M_PI};
496 CvAffine3T tf;
497 basalt::Calibration<ScalarT> calib;
498 std::vector<cv::UMat> vigns, vigns_base;
499 std::vector<cv::UMat> response;
500 std::vector<cv::UMat> weights, weights_base, weights_raw;
501
502 // Additional resources
503 std::unique_ptr<DeviceData> dev;
504 };
505
506}
cv::Size resolution(const cv::Size &resolution)
Set the output resolution for the panorama.
void setDepth(const cv::Mat &depth)
Sets a per-point depth map for the panorama.
Stitcher()
Constructs an empty Stitcher object.
bool buildInternals()
Builds all necessary internal data structures required for stitching.
ScalarT fovX(ScalarT fov)
Set the horizontal field of view (FOV) for the panorama.
bool useMaskAsVignette(bool use)
Sets whether to use the mask as vignette.
int height() const
Get the current output height for the panorama.
cv::Size resolution(int width, int height)
Set the output resolution for the panorama.
void stitch(const std::vector< cv::Mat > &images, const std::vector< ScalarT > &exposure, cv::Mat &pano)
Stitches the provided input images into a single panoramic image.
ScalarT vignetteThreshold() const
Get the current vignette threshold.
CvFovT fov(ScalarT fov_x, ScalarT fov_y)
Set the field of view (FOV) for the panorama.
const basalt::Calibration< ScalarT > & calibration() const
Returns a read-only reference to the calibration data.
CvAffine3T transform(const CvAffine3T::Vec3 &rotation, const CvAffine3T::Vec3 &translation=CvAffine3T::Vec3(0, 0, 0))
Set the transformation using a rotation vector and translation vector.
void setDepth(ScalarT depth)
Sets a uniform depth for the panorama.
int width() const
Get the current output width for the panorama.
ScalarT fovX() const
Get the current horizontal field of view (FOV) for the panorama.
CvAffine3T transform(const CvAffine3T::Mat3 &rotation, const CvAffine3T::Vec3 &translation=CvAffine3T::Vec3(0, 0, 0))
Set the transformation using rotation matrix and translation vector.
void buildMirrors()
Builds the vignette map and weight mirrors for multi-channel images.
int width(int width)
Set the output width for the panorama.
void buildVignettes()
Builds the vignette maps.
Stitcher(const std::string &calibration_filepath, const cv::Mat &depth)
Constructs a Stitcher object with the specified calibration file and per-point depth.
void buildMask()
Builds the masks and finalizes the weights.
bool buildMaps()
Builds the lookup tables and initial proximity-based weights.
cv::Size resolution() const
Get the current output resolution for the panorama.
Stitcher(const std::string &calibration_filepath, ScalarT depth)
Constructs a Stitcher object with the specified calibration file and uniform depth.
CvFovT fov() const
Get the current field of view (FOV) for the panorama.
Stitcher(const std::string &calibration_filepath)
Constructs a Stitcher object with the specified calibration file.
void loadCalibration(const std::string &calibration_filepath)
Loads camera calibration data from the specified file.
ScalarT vignetteThreshold(ScalarT threshold)
Set the vignette threshold used to generate vignette maps.
~Stitcher()
Destructor for the Stitcher class.
ScalarT fovY() const
Get the current vertical field of view (FOV) for the panorama.
void stitch(const std::vector< cv::Mat > &images, const std::vector< ScalarT > &exposure, const cv::Mat &depth, cv::Mat &pano)
Stitches the provided input images into a single panoramic image.
CvFovT fov(CvFovT fov)
Set the field of view (FOV) for the panorama.
CvAffine3T transform(const CvAffine3T &transform)
Set the transformation from body to calibration coordinate system.
bool useMaskAsVignette() const
Gets whether the mask is used as vignette.
void stitch(const std::vector< cv::Mat > &images, const std::vector< ScalarT > &exposure, ScalarT depth, cv::Mat &pano)
Stitches the provided input images into a single panoramic image.
CvAffine3T transform(const CvAffine3T::Mat4 &affine)
Set the transformation using an affine matrix.
void stitch(const std::vector< cv::Mat > &images, cv::Mat &pano)
Stitches the provided input images into a single panoramic image.
CvAffine3T transform() const
Get the current transformation from body to calibration coordinate system.
ScalarT fovY(ScalarT fov)
Set the vertical field of view (FOV) for the panorama.
int height(int height)
Set the output height for the panorama.