From fb1771833ac67759c86d6475828cb18cc8f5de72 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Mon, 30 May 2011 10:18:02 +0000 Subject: [PATCH] added --blend_strength parameter into opencv_stitching --- modules/stitching/exposure_compensate.cpp | 5 ++-- modules/stitching/main.cpp | 31 +++++++++++++++-------- modules/stitching/motion_estimators.cpp | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/modules/stitching/exposure_compensate.cpp b/modules/stitching/exposure_compensate.cpp index 02ef8e6ddb..9bbb6c3d64 100644 --- a/modules/stitching/exposure_compensate.cpp +++ b/modules/stitching/exposure_compensate.cpp @@ -197,6 +197,9 @@ void BlocksGainCompensator::feed(const vector &corners, const vector vector gains = compensator.gains(); gain_maps_.resize(num_images); + Mat_ ker(1, 3); + ker(0,0) = 0.25; ker(0,1) = 0.5; ker(0,2) = 0.25; + int bl_idx = 0; for (int img_idx = 0; img_idx < num_images; ++img_idx) { @@ -207,8 +210,6 @@ void BlocksGainCompensator::feed(const vector &corners, const vector for (int bx = 0; bx < bl_per_img.width; ++bx, ++bl_idx) gain_maps_[img_idx](by, bx) = static_cast(gains[bl_idx]); - Mat_ ker(1, 3); - ker(0,0) = 0.25; ker(0,1) = 0.5; ker(0,2) = 0.25; sepFilter2D(gain_maps_[img_idx], gain_maps_[img_idx], CV_32F, ker, ker); sepFilter2D(gain_maps_[img_idx], gain_maps_[img_idx], CV_32F, ker, ker); } diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index b71756f8ba..753ec91e92 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -94,11 +94,11 @@ void printUsage() " Resolution for compositing step. Use -1 for original resolution.\n" " The default is -1.\n" " --expos_comp (no|gain|gain_blocks)\n" - " Exposure compensation method. The default is 'gain'.\n" + " Exposure compensation method. The default is 'gain_blocks'.\n" " --blend (no|feather|multiband)\n" " Blending method. The default is 'multiband'.\n" - " --num_bands \n" - " Number of bands for multi-band blending method. The default is 5.\n" + " --blend_strength \n" + " Blend strength from [0,100] range. The default is 5.\n" " --output \n"; } @@ -114,11 +114,11 @@ int ba_space = BundleAdjuster::FOCAL_RAY_SPACE; float conf_thresh = 1.f; bool wave_correct = true; int warp_type = Warper::SPHERICAL; -int expos_comp_type = ExposureCompensator::GAIN; -float match_conf = 0.7f; +int expos_comp_type = ExposureCompensator::GAIN_BLOCKS; +float match_conf = 0.65f; int seam_find_type = SeamFinder::GC_COLOR; int blend_type = Blender::MULTI_BAND; -int num_bands = 5; +float blend_strength = 5; string result_name = "result.png"; int parseCmdArgs(int argc, char** argv) @@ -270,9 +270,9 @@ int parseCmdArgs(int argc, char** argv) } i++; } - else if (string(argv[i]) == "--num_bands") + else if (string(argv[i]) == "--blend_strength") { - num_bands = atoi(argv[i + 1]); + blend_strength = static_cast(atof(argv[i + 1])); i++; } else if (string(argv[i]) == "--output") @@ -562,10 +562,21 @@ int main(int argc, char* argv[]) if (static_cast(blender) == 0) { blender = Blender::createDefault(blend_type); - if (blend_type == Blender::MULTI_BAND) + Size dst_sz = resultRoi(corners, sizes).size(); + float blend_width = sqrt(static_cast(dst_sz.area())) * blend_strength / 100.f; + if (blend_width < 1.f) + blender = Blender::createDefault(Blender::NO); + else if (blend_type == Blender::MULTI_BAND) { MultiBandBlender* mb = dynamic_cast(static_cast(blender)); - mb->setNumBands(num_bands); + mb->setNumBands(static_cast(ceil(log(blend_width)/log(2.)) - 1.)); + LOGLN("Multi-band blender, number of bands: " << mb->numBands()); + } + else if (blend_type == Blender::FEATHER) + { + FeatherBlender* fb = dynamic_cast(static_cast(blender)); + fb->setSharpness(1.f/blend_width); + LOGLN("Feather blender, number of bands: " << fb->sharpness()); } blender->prepare(corners, sizes); } diff --git a/modules/stitching/motion_estimators.cpp b/modules/stitching/motion_estimators.cpp index 86cac2d63d..e1fac70e80 100644 --- a/modules/stitching/motion_estimators.cpp +++ b/modules/stitching/motion_estimators.cpp @@ -432,7 +432,7 @@ vector leaveBiggestComponent(vector &features, vector