2023-07-29 OpenCV build info Tags: opencvdiff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index 44f35eb59b..644b537941 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -8,6 +8,6 @@ set(STITCHING_CONTRIB_DEPS "opencv_xfeatures2d") if(BUILD_SHARED_LIBS AND BUILD_opencv_world AND OPENCV_WORLD_EXCLUDE_EXTRA_MODULES) set(STITCHING_CONTRIB_DEPS "") endif() -ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_flann +ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_flann opencv_imgcodecs OPTIONAL opencv_cudaarithm opencv_cudawarping opencv_cudafeatures2d opencv_cudalegacy opencv_cudaimgproc ${STITCHING_CONTRIB_DEPS} WRAP python) diff --git a/modules/stitching/src/stitcher.cpp b/modules/stitching/src/stitcher.cpp index f9ba60c1b9..904aa19639 100644 --- a/modules/stitching/src/stitcher.cpp +++ b/modules/stitching/src/stitcher.cpp @@ -42,6 +42,9 @@ #include "precomp.hpp" +#include <sstream> +#include <opencv2/imgcodecs.hpp> + namespace cv { #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) @@ -125,6 +128,50 @@ Stitcher::Status Stitcher::composePanorama(OutputArray pano) return composePanorama(std::vector<UMat>(), pano); } +namespace +{ + void dump_blend_inputs_1(const std::vector<Point>& corners) + { + // Dump corners for the blend executable + a full command line for multiblend + + cv::FileStorage dump("blender_inputs.yml", cv::FileStorage::WRITE | FileStorage::FORMAT_YAML); + + std::stringstream multi_cmd; + multi_cmd << "multiblend -o result_multiblend.png"; + + dump << "corners" << "["; + for (size_t i = 0; i < corners.size(); ++i) + { + dump << corners[i]; + + multi_cmd << " img_" << i << ".png " << corners[i].x << "," << corners[i].y; + } + dump << "]"; + + dump << "multi_cmd" << multi_cmd.str(); + } + + void dump_blend_inputs_2(size_t pos, cv::UMat image_16s, cv::UMat mask) + { + // Convert input to 8-bit (data is already in [0, 255]) + // and add mask as alpha channel, save as png + + cv::UMat image; + image_16s.convertTo(image, CV_8U); + + std::vector<cv::UMat> image_channels; + cv::split(image, image_channels); + image_channels.push_back(mask); + + cv::UMat image_with_alpha; + cv::merge(image_channels, image_with_alpha); + + // write image to disk + std::stringstream ss; + ss << "img_" << pos << ".png"; + cv::imwrite(ss.str(), image_with_alpha); + } +} Stitcher::Status Stitcher::composePanorama(InputArrayOfArrays images, OutputArray pano) { @@ -343,6 +390,7 @@ Stitcher::Status Stitcher::composePanorama(InputArrayOfArrays images, OutputArra if (!is_blender_prepared) { + dump_blend_inputs_1(corners); blender_->prepare(corners, sizes); is_blender_prepared = true; } @@ -354,6 +402,7 @@ Stitcher::Status Stitcher::composePanorama(InputArrayOfArrays images, OutputArra int64 feed_t = getTickCount(); #endif // Blend the current image + dump_blend_inputs_2(img_idx, img_warped_s, mask_warped); blender_->feed(img_warped_s, mask_warped, corners[img_idx]); LOGLN(" feed time: " << ((getTickCount() - feed_t) / getTickFrequency()) << " sec"); LOGLN("Compositing ## time: " << ((getTickCount() - compositing_t) / getTickFrequency()) << " sec");