<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; ❔ 4.3 / 3.4</li>
<li>Operating System / Platform =&gt; <g-emoji class="g-emoji" alias="grey_question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2754.png">❔</g-emoji> Linux Ubuntu 16.04</li>
<li>Compiler =&gt; ❔ Android Studio (Gradle / Ninja / CMake / clang++)</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I'm trying to use OpenCV on Android's NDK.<br>
I have two similar environments - one integrated with OpenCV 4.3 and the other with OpenCV 3.4.<br>
I created an Android C++ app.<br>
For the 4.3 integration I followed <a href="https://github.com/VlSomers/native-opencv-android-template">this</a> tutorial.<br>
For the 3.4 integration I followed <a href="https://github.com/leadrien/opencv_native_androidstudio">this</a> tutorial.<br>
I have a very basic <code class="notranslate">native-lib.cpp</code> file (see below), which is trying to use <code class="notranslate">cv::imread</code>.</p>
<p dir="auto">In my code I provide the last trial - which includes the <code class="notranslate">OpenCVLoader.initAsync</code> instance, but I also tried the <code class="notranslate">OpenCVLoader.initDebug</code> way and <code class="notranslate">System.loadLibrary("opencv_java4")</code>, but the error remains.</p>
<p dir="auto">I'm aware of the following issues:</p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="617554614" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/17282" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/17282/hovercard" href="https://github.com/opencv/opencv/issues/17282">#17282</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="495244870" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/15536" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/15536/hovercard" href="https://github.com/opencv/opencv/issues/15536">#15536</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="344939589" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/12074" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/12074/hovercard" href="https://github.com/opencv/opencv/issues/12074">#12074</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="253881876" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/9512" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/9512/hovercard" href="https://github.com/opencv/opencv/issues/9512">#9512</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="251995452" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/9437" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/9437/hovercard" href="https://github.com/opencv/opencv/issues/9437">#9437</a></li>
</ul>
<p dir="auto">and noticed the recent update regarding link issues (which I assumed was my problem):</p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="617554614" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/17282" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/17282/hovercard" href="https://github.com/opencv/opencv/issues/17282">#17282</a></li>
</ul>
<p dir="auto">I tried to build for my SDK version or against libc++, as described in the following:</p>
<ul dir="auto">
<li><a href="https://stackoverflow.com/questions/51767214/android-studio-with-ndk-link-error-undefined-reference-to-stderr" rel="nofollow">https://stackoverflow.com/questions/51767214/android-studio-with-ndk-link-error-undefined-reference-to-stderr</a></li>
<li><a href="https://stackoverflow.com/questions/52436506/undefined-references-error-opencv-android-with-ndk-18-c-static" rel="nofollow">https://stackoverflow.com/questions/52436506/undefined-references-error-opencv-android-with-ndk-18-c-static</a></li>
<li><a href="https://stackoverflow.com/questions/52410712/ndk-problems-after-gnustl-has-been-removed-from-the-ndk-revision-r18/52436751#52436751" rel="nofollow">https://stackoverflow.com/questions/52410712/ndk-problems-after-gnustl-has-been-removed-from-the-ndk-revision-r18/52436751#52436751</a></li>
</ul>
<p dir="auto">and noticed some other issues, which do not use exactly the same setup (for example, using ndk-build instead of cmake):</p>
<ul dir="auto">
<li><a href="https://stackoverflow.com/questions/14649710/opencv-with-android-ndk-undefined-references" rel="nofollow">https://stackoverflow.com/questions/14649710/opencv-with-android-ndk-undefined-references</a></li>
</ul>
<p dir="auto">but failed to find anything new.</p>
<p dir="auto">When trying to run the app I get the following errors:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="undefined reference to `cv::imread'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed."><pre class="notranslate"><code class="notranslate">undefined reference to `cv::imread'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
</code></pre></div>
<p dir="auto">Isn't undefined reference a linker issue?<br>
Did I forget a compiler flag or something?</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Follow one of the tutorials (<a href="https://github.com/VlSomers/native-opencv-android-template">4.3 tutorial</a> or <a href="https://github.com/leadrien/opencv_native_androidstudio">3.4 tutorial</a>) to integrate OpenCV library into Android Studio.</p>
<p dir="auto">Create the following simple <strong>native-lib.cpp</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;jni.h&gt;
#include &lt;string&gt;
#include &lt;opencv2/core.hpp&gt;
#include &lt;opencv2/imgcodecs.hpp&gt;

extern &quot;C&quot; JNIEXPORT jstring JNICALL
Java_com_ocv_MainActivity_ocvLoadImage(
        JNIEnv *env,
        jobject thiz) {
    using namespace cv;
    using namespace std;
    Mat image;
    string imageName = &quot;/Pictures/images/image-001.jpg&quot;;
    image = imread(imageName, IMREAD_COLOR);
    std::string returnString = &quot;OpenCV load image: &quot;;
    if (! image.empty()){
        returnString.append(imageName);
    }
    return env -&gt; NewStringUTF(returnString.c_str());
}"><pre class="notranslate"><code class="notranslate">#include &lt;jni.h&gt;
#include &lt;string&gt;
#include &lt;opencv2/core.hpp&gt;
#include &lt;opencv2/imgcodecs.hpp&gt;

extern "C" JNIEXPORT jstring JNICALL
Java_com_ocv_MainActivity_ocvLoadImage(
        JNIEnv *env,
        jobject thiz) {
    using namespace cv;
    using namespace std;
    Mat image;
    string imageName = "/Pictures/images/image-001.jpg";
    image = imread(imageName, IMREAD_COLOR);
    std::string returnString = "OpenCV load image: ";
    if (! image.empty()){
        returnString.append(imageName);
    }
    return env -&gt; NewStringUTF(returnString.c_str());
}
</code></pre></div>
<p dir="auto">and call it from this simple <strong>MainActivity.java</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package com.ocv;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.util.Log;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;

public class MainActivity extends AppCompatActivity {

    static {
        System.loadLibrary(&quot;native-lib&quot;);
        System.loadLibrary(&quot;opencv_java4&quot;);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            if (status == LoaderCallbackInterface.SUCCESS) {
                TextView textView = findViewById(R.id.sample_text);
                String displayString =
                        textView.getText() +
                                &quot;\n&quot; + &quot;OpenCV loaded successfully via initAsync&quot; +
                                &quot;\n&quot; + ocvLoadImage();
                textView.setText(displayString);
            } else {
                super.onManagerConnected(status);
            }
        }
    };

    @Override
    public void onResume()
    {
        super.onResume();
        OpenCVLoader.initAsync(
                OpenCVLoader.OPENCV_VERSION_3_4_0,
                this,
                mLoaderCallback);
    }
    public native String ocvLoadImage(String imagePath);
}"><pre class="notranslate"><code class="notranslate">package com.ocv;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.util.Log;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;

public class MainActivity extends AppCompatActivity {

    static {
        System.loadLibrary("native-lib");
        System.loadLibrary("opencv_java4");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            if (status == LoaderCallbackInterface.SUCCESS) {
                TextView textView = findViewById(R.id.sample_text);
                String displayString =
                        textView.getText() +
                                "\n" + "OpenCV loaded successfully via initAsync" +
                                "\n" + ocvLoadImage();
                textView.setText(displayString);
            } else {
                super.onManagerConnected(status);
            }
        }
    };

    @Override
    public void onResume()
    {
        super.onResume();
        OpenCVLoader.initAsync(
                OpenCVLoader.OPENCV_VERSION_3_4_0,
                this,
                mLoaderCallback);
    }
    public native String ocvLoadImage(String imagePath);
}
</code></pre></div>
<p dir="auto"><strong>NOTES</strong>:</p>
<ul dir="auto">
<li>When calling <code class="notranslate">OpenCVLoader.initAsync</code>, both the 4.3 and the 3.4 version use the <code class="notranslate">OPENCV_VERSION_3_4_0</code> flag, since <code class="notranslate">OPENCV_VERSION</code> on 4.3 results in an error. I also tried the <code class="notranslate">OpenCVLoader.initDebug</code> and it produces the same error.</li>
<li>When commenting out the <code class="notranslate">image = imread</code> line in <code class="notranslate">native-lib.cpp</code>, the app runs OK, and returns the string (all cases).</li>
</ul>
<p dir="auto">the app's <strong>build.gradle</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="externalNativeBuild {
            cmake {
                        cppFlags &quot;-frtti -fexceptions&quot;
                        abiFilters 'arm64-v8a'
                        arguments &quot;-DOpenCV_DIR=&quot; + opencvsdk + &quot;/sdk/native/jni&quot;
            }
}
...
packagingOptions {
        pickFirst 'lib/arm64-v8a/libopencv_java4.so'
    }"><pre class="notranslate"><code class="notranslate">externalNativeBuild {
            cmake {
                        cppFlags "-frtti -fexceptions"
                        abiFilters 'arm64-v8a'
                        arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni"
            }
}
...
packagingOptions {
        pickFirst 'lib/arm64-v8a/libopencv_java4.so'
    }
</code></pre></div>
<p dir="auto"><strong>CMakeLists.txt</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cmake_minimum_required(VERSION 3.4.1)
include_directories(${OpenCV_DIR}/jni/include)
find_package(OpenCV 4.3
        REQUIRED
        java)
add_library(
             native-lib
             SHARED
             native-lib.cpp )
find_library(
              log-lib
              log )
target_link_libraries( # Specifies the target library.
        native-lib
        ${OpenCV_LIBRARIES}
        ${log-lib} )"><pre class="notranslate"><code class="notranslate">cmake_minimum_required(VERSION 3.4.1)
include_directories(${OpenCV_DIR}/jni/include)
find_package(OpenCV 4.3
        REQUIRED
        java)
add_library(
             native-lib
             SHARED
             native-lib.cpp )
find_library(
              log-lib
              log )
target_link_libraries( # Specifies the target library.
        native-lib
        ${OpenCV_LIBRARIES}
        ${log-lib} )
</code></pre></div>
<h5 dir="auto">Error</h5>
<p dir="auto"><strong>ERROR</strong>:<br>
<code class="notranslate">undefined reference to "cv::imread"</code></p>
<p dir="auto"><strong>CLANG++</strong>:<br>
<code class="notranslate">/path/to/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android29 --gcc-toolchain=/path/to/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/path/to/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -frtti -fexceptions -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libnative-lib.so -o /path/to/app/build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so CMakeFiles/native-lib.dir/native-lib.cpp.o  /path/to/opencv-4.3.0-android-sdk/OpenCV-android-sdk/sdk/native/libs/arm64-v8a/libopencv_java4.so /path/to/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/29/liblog.so -ljnigraphics -llog -ldl -lz -latomic -lm</code></p>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt;  4.1.0.25</li>
<li>Operating System / Platform =&gt; Ubuntu 18.04.3 LTS</li>
<li>Compiler =&gt; python wheel</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I'm trying to use the seam_finder of the stitching package (<a href="https://docs.opencv.org/master/d9/d24/group__stitching__seam.html" rel="nofollow">https://docs.opencv.org/master/d9/d24/group__stitching__seam.html</a>).<br>
This classes aims to find the optimal seams between two overlapping images. Regardless of the used seam finder, the inputs masks aren't updated.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">I've tried using a modified version of the detailed_stitching python scripts : <a href="https://github.com/opencv/opencv/blob/master/samples/python/stitching_detailed.py">https://github.com/opencv/opencv/blob/master/samples/python/stitching_detailed.py</a></p>
<p dir="auto">Here my modified code which tests all the seam_finder and plot the masks using matplotlib :<br>
I've also attached two images with which i've tried :</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/45284585/64870725-1cc05e00-d644-11e9-88e4-4fcb89a7b52a.jpg"><img src="https://user-images.githubusercontent.com/45284585/64870725-1cc05e00-d644-11e9-88e4-4fcb89a7b52a.jpg" alt="img_2" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/45284585/64870726-1cc05e00-d644-11e9-9297-bdf072e68982.jpg"><img src="https://user-images.githubusercontent.com/45284585/64870726-1cc05e00-d644-11e9-9297-bdf072e68982.jpg" alt="img_1" style="max-width: 100%;"></a></p>
<p dir="auto">Here an example of non updated mask for the voronoi seam_finder :<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/45284585/64871145-e6cfa980-d644-11e9-8416-e9f498e1822e.png"><img src="https://user-images.githubusercontent.com/45284585/64871145-e6cfa980-d644-11e9-8416-e9f498e1822e.png" alt="Screenshot from 2019-09-13 16-38-04" style="max-width: 100%;"></a></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="   &quot;&quot;&quot;
Stitching sample (advanced)
===========================

Show how to use Stitcher API from python.
&quot;&quot;&quot;

# Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import copy
import cv2 as cv
import matplotlib.pyplot as plt

import sys
import argparse

parser = argparse.ArgumentParser(prog='stitching_detailed.py', description='Rotation model images stitcher')
parser.add_argument('img_names', nargs='+',help='files to stitch',type=str)
parser.add_argument('--preview',help='Run stitching in the preview mode. Works faster than usual mode but output image will have lower resolution.',type=bool,dest = 'preview' )
parser.add_argument('--try_cuda',action = 'store', default = False,help='Try to use CUDA. The default value is no. All default values are for CPU mode.',type=bool,dest = 'try_cuda' )
parser.add_argument('--work_megapix',action = 'store', default = 0.6,help=' Resolution for image registration step. The default is 0.6 Mpx',type=float,dest = 'work_megapix' )
parser.add_argument('--features',action = 'store', default = 'orb',help='Type of features used for images matching. The default is orb.',type=str,dest = 'features' )
parser.add_argument('--matcher',action = 'store', default = 'homography',help='Matcher used for pairwise image matching.',type=str,dest = 'matcher' )
parser.add_argument('--estimator',action = 'store', default = 'homography',help='Type of estimator used for transformation estimation.',type=str,dest = 'estimator' )
parser.add_argument('--match_conf',action = 'store', default = 0.3,help='Confidence for feature matching step. The default is 0.65 for surf and 0.3 for orb.',type=float,dest = 'match_conf' )
parser.add_argument('--conf_thresh',action = 'store', default = 1.0,help='Threshold for two images are from the same panorama confidence.The default is 1.0.',type=float,dest = 'conf_thresh' )
parser.add_argument('--ba',action = 'store', default = 'ray',help='Bundle adjustment cost function. The default is ray.',type=str,dest = 'ba' )
parser.add_argument('--ba_refine_mask',action = 'store', default = 'xxxxx',help='Set refinement mask for bundle adjustment.  mask is &quot;xxxxx&quot;',type=str,dest = 'ba_refine_mask' )
parser.add_argument('--wave_correct',action = 'store', default = 'horiz',help='Perform wave effect correction. The default is &quot;horiz&quot;',type=str,dest = 'wave_correct' )
parser.add_argument('--save_graph',action = 'store', default = None,help='Save matches graph represented in DOT language to &lt;file_name&gt; file.',type=str,dest = 'save_graph' )
parser.add_argument('--warp',action = 'store', default = 'plane',help='Warp surface type. The default is &quot;spherical&quot;.',type=str,dest = 'warp' )
parser.add_argument('--seam_megapix',action = 'store', default = 0.1,help=' Resolution for seam estimation step. The default is 0.1 Mpx.',type=float,dest = 'seam_megapix' )
parser.add_argument('--seam',action = 'store', default = 'no',help='Seam estimation method. The default is &quot;gc_color&quot;.',type=str,dest = 'seam' )
parser.add_argument('--compose_megapix',action = 'store', default = -1,help='Resolution for compositing step. Use -1 for original resolution.',type=float,dest = 'compose_megapix' )
parser.add_argument('--expos_comp',action = 'store', default = 'no',help='Exposure compensation method. The default is &quot;gain_blocks&quot;.',type=str,dest = 'expos_comp' )
parser.add_argument('--expos_comp_nr_feeds',action = 'store', default = 1,help='Number of exposure compensation feed.',type=np.int32,dest = 'expos_comp_nr_feeds' )
parser.add_argument('--expos_comp_nr_filtering',action = 'store', default = 2,help='Number of filtering iterations of the exposure compensation gains',type=float,dest = 'expos_comp_nr_filtering' )
parser.add_argument('--expos_comp_block_size',action = 'store', default = 32,help='BLock size in pixels used by the exposure compensator.',type=np.int32,dest = 'expos_comp_block_size' )
parser.add_argument('--blend',action = 'store', default = 'multiband',help='Blending method. The default is &quot;multiband&quot;.',type=str,dest = 'blend' )
parser.add_argument('--blend_strength',action = 'store', default = 5,help='Blending strength from [0,100] range.',type=np.int32,dest = 'blend_strength' )
parser.add_argument('--output',action = 'store', default = 'result.jpg',help='The default is &quot;result.jpg&quot;',type=str,dest = 'output' )
parser.add_argument('--timelapse',action = 'store', default = None,help='Output warped images separately as frames of a time lapse movie, with &quot;fixed_&quot; prepended to input file names.',type=str,dest = 'timelapse' )
parser.add_argument('--rangewidth',action = 'store', default = -1,help='uses range_width to limit number of images to match with.',type=int,dest = 'rangewidth' )

__doc__ += '\n' + parser.format_help()

def main():
    args = parser.parse_args()
    img_names=args.img_names
    print(img_names)
    preview = args.preview
    try_cuda = args.try_cuda
    work_megapix = args.work_megapix
    seam_megapix = args.seam_megapix
    compose_megapix = args.compose_megapix
    conf_thresh = args.conf_thresh
    features_type = args.features
    matcher_type = args.matcher
    estimator_type = args.estimator
    ba_cost_func = args.ba
    ba_refine_mask = args.ba_refine_mask
    wave_correct = args.wave_correct
    if wave_correct=='no':
        do_wave_correct= False
    else:
        do_wave_correct=True
    if args.save_graph is None:
        save_graph = False
    else:
        save_graph =True
        save_graph_to = args.save_graph
    warp_type = args.warp
    if args.expos_comp=='no':
        expos_comp_type = cv.detail.ExposureCompensator_NO
    elif  args.expos_comp=='gain':
        expos_comp_type = cv.detail.ExposureCompensator_GAIN
    elif  args.expos_comp=='gain_blocks':
        expos_comp_type = cv.detail.ExposureCompensator_GAIN_BLOCKS
    elif  args.expos_comp=='channel':
        expos_comp_type = cv.detail.ExposureCompensator_CHANNELS
    elif  args.expos_comp=='channel_blocks':
        expos_comp_type = cv.detail.ExposureCompensator_CHANNELS_BLOCKS
    else:
        print(&quot;Bad exposure compensation method&quot;)
        exit()
    expos_comp_nr_feeds = args.expos_comp_nr_feeds
    expos_comp_nr_filtering = args.expos_comp_nr_filtering
    expos_comp_block_size = args.expos_comp_block_size
    match_conf = args.match_conf
    seam_find_type = args.seam
    blend_type = args.blend
    blend_strength = args.blend_strength
    result_name = args.output
    if args.timelapse is not None:
        timelapse = True
        if args.timelapse==&quot;as_is&quot;:
            timelapse_type = cv.detail.Timelapser_AS_IS
        elif args.timelapse==&quot;crop&quot;:
            timelapse_type = cv.detail.Timelapser_CROP
        else:
            print(&quot;Bad timelapse method&quot;)
            exit()
    else:
        timelapse= False
    range_width = args.rangewidth
    if features_type=='orb':
        finder= cv.ORB.create()
    elif features_type=='surf':
        finder= cv.xfeatures2d_SURF.create()
    elif features_type=='sift':
        finder= cv.xfeatures2d_SIFT.create()
    else:
        print (&quot;Unknown descriptor type&quot;)
        exit()
    seam_work_aspect = 1
    full_img_sizes=[]
    features=[]
    images=[]
    is_work_scale_set = False
    is_seam_scale_set = False
    is_compose_scale_set = False;
    for name in img_names:
        full_img = cv.imread(cv.samples.findFile(name))
        if full_img is None:
            print(&quot;Cannot read image &quot;, name)
            exit()
        full_img_sizes.append((full_img.shape[1],full_img.shape[0]))
        if work_megapix &lt; 0:
            img = full_img
            work_scale = 1
            is_work_scale_set = True
        else:
            if is_work_scale_set is False:
                work_scale = min(1.0, np.sqrt(work_megapix * 1e6 / (full_img.shape[0]*full_img.shape[1])))
                is_work_scale_set = True
            img = cv.resize(src=full_img, dsize=None, fx=work_scale, fy=work_scale, interpolation=cv.INTER_LINEAR_EXACT)
        if is_seam_scale_set is False:
            seam_scale = min(1.0, np.sqrt(seam_megapix * 1e6 / (full_img.shape[0]*full_img.shape[1])))
            seam_work_aspect = seam_scale / work_scale
            is_seam_scale_set = True
        imgFea= cv.detail.computeImageFeatures2(finder,img)
        features.append(imgFea)
        img = cv.resize(src=full_img, dsize=None, fx=seam_scale, fy=seam_scale, interpolation=cv.INTER_LINEAR_EXACT)
        images.append(img)
    if matcher_type== &quot;affine&quot;:
        matcher = cv.detail_AffineBestOf2NearestMatcher(False, try_cuda, match_conf)
    elif range_width==-1:
        matcher = cv.detail.BestOf2NearestMatcher_create(try_cuda, match_conf)
    else:
        matcher = cv.detail.BestOf2NearestRangeMatcher_create(range_width, try_cuda, match_conf)
    p=matcher.apply2(features)
    matcher.collectGarbage()
    if save_graph:
        f = open(save_graph_to,&quot;w&quot;)
        f.write(cv.detail.matchesGraphAsString(img_names, p, conf_thresh))
        f.close()
    indices=cv.detail.leaveBiggestComponent(features,p,0.3)
    img_subset =[]
    img_names_subset=[]
    full_img_sizes_subset=[]
    num_images=len(indices)
    for i in range(len(indices)):
        img_names_subset.append(img_names[indices[i,0]])
        img_subset.append(images[indices[i,0]])
        full_img_sizes_subset.append(full_img_sizes[indices[i,0]])
    images = img_subset;
    img_names = img_names_subset;
    full_img_sizes = full_img_sizes_subset;
    num_images = len(img_names)
    if num_images &lt; 2:
        print(&quot;Need more images&quot;)
        exit()

    if estimator_type == &quot;affine&quot;:
        estimator = cv.detail_AffineBasedEstimator()
    else:
        estimator = cv.detail_HomographyBasedEstimator()
    b, cameras =estimator.apply(features,p,None)
    if not b:
        print(&quot;Homography estimation failed.&quot;)
        exit()
    for cam in cameras:
        cam.R=cam.R.astype(np.float32)

    if ba_cost_func == &quot;reproj&quot;:
        adjuster = cv.detail_BundleAdjusterReproj()
    elif ba_cost_func == &quot;ray&quot;:
        adjuster = cv.detail_BundleAdjusterRay()
    elif ba_cost_func == &quot;affine&quot;:
        adjuster = cv.detail_BundleAdjusterAffinePartial()
    elif ba_cost_func == &quot;no&quot;:
        adjuster = cv.detail_NoBundleAdjuster()
    else:
        print( &quot;Unknown bundle adjustment cost function: &quot;, ba_cost_func )
        exit()
    adjuster.setConfThresh(1)
    refine_mask=np.zeros((3,3),np.uint8)
    if ba_refine_mask[0] == 'x':
        refine_mask[0,0] = 1
    if ba_refine_mask[1] == 'x':
        refine_mask[0,1] = 1
    if ba_refine_mask[2] == 'x':
        refine_mask[0,2] = 1
    if ba_refine_mask[3] == 'x':
        refine_mask[1,1] = 1
    if ba_refine_mask[4] == 'x':
        refine_mask[1,2] = 1
    adjuster.setRefinementMask(refine_mask)
    b,cameras = adjuster.apply(features,p,cameras)
    if not b:
        print(&quot;Camera parameters adjusting failed.&quot;)
        exit()
    focals=[]
    for cam in cameras:
        focals.append(cam.focal)
    sorted(focals)
    if len(focals)%2==1:
        warped_image_scale = focals[len(focals) // 2]
    else:
        warped_image_scale = (focals[len(focals) // 2]+focals[len(focals) // 2-1])/2
    if do_wave_correct:
        rmats=[]
        for cam in cameras:
            rmats.append(np.copy(cam.R))
        rmats	=	cv.detail.waveCorrect(	rmats,  cv.detail.WAVE_CORRECT_HORIZ)
        for idx,cam in enumerate(cameras):
            cam.R = rmats[idx]
    corners=[]
    mask=[]
    masks_warped=[]
    images_warped=[]
    sizes=[]
    masks=[]
    for i in range(0,num_images):
        um=cv.UMat(255*np.ones((images[i].shape[0],images[i].shape[1]),np.uint8))
        masks.append(um)

    warper = cv.PyRotationWarper(warp_type,warped_image_scale*seam_work_aspect) # warper peut etre nullptr?
    for idx in range(0,num_images):
        K = cameras[idx].K().astype(np.float32)
        swa = seam_work_aspect
        K[0,0] *= swa
        K[0,2] *= swa
        K[1,1] *= swa
        K[1,2] *= swa
        corner,image_wp =warper.warp(images[idx],K,cameras[idx].R,cv.INTER_LINEAR, cv.BORDER_REFLECT)
        corners.append(corner)
        sizes.append((image_wp.shape[1],image_wp.shape[0]))
        images_warped.append(image_wp)

        p,mask_wp =warper.warp(masks[idx],K,cameras[idx].R,cv.INTER_NEAREST, cv.BORDER_CONSTANT)
        masks_warped.append(mask_wp.get())
    images_warped_f=[]
    for img in images_warped:
        imgf=img.astype(np.float32)
        images_warped_f.append(imgf)
    if cv.detail.ExposureCompensator_CHANNELS == expos_comp_type:
        compensator = cv.detail_ChannelsCompensator(expos_comp_nr_feeds)
    #    compensator.setNrGainsFilteringIterations(expos_comp_nr_filtering)
    elif cv.detail.ExposureCompensator_CHANNELS_BLOCKS == expos_comp_type:
        compensator=cv.detail_BlocksChannelsCompensator(expos_comp_block_size, expos_comp_block_size,expos_comp_nr_feeds)
    #    compensator.setNrGainsFilteringIterations(expos_comp_nr_filtering)
    else:
        compensator=cv.detail.ExposureCompensator_createDefault(expos_comp_type)
    compensator.feed(corners=corners, images=images_warped, masks=masks_warped)
    for finder_id, finder_name in enumerate(
            [&quot;no&quot;, &quot;voronoi&quot;, &quot;gc_color&quot;, &quot;gc_colorgrad&quot;, &quot;dp_color&quot;, &quot;dp_colorgrad&quot;]
    ):
        if seam_find_type == &quot;no&quot;:
            seam_finder = cv.detail.SeamFinder_createDefault(cv.detail.SeamFinder_NO)
        elif seam_find_type == &quot;voronoi&quot;:
            seam_finder = cv.detail.SeamFinder_createDefault(cv.detail.SeamFinder_VORONOI_SEAM);
        elif seam_find_type == &quot;gc_color&quot;:
            seam_finder = cv.detail_GraphCutSeamFinder(&quot;COST_COLOR&quot;)
        elif seam_find_type == &quot;gc_colorgrad&quot;:
            seam_finder = cv.detail_GraphCutSeamFinder(&quot;COST_COLOR_GRAD&quot;)
        elif seam_find_type == &quot;dp_color&quot;:
            seam_finder = cv.detail_DpSeamFinder(&quot;COLOR&quot;)
        elif seam_find_type == &quot;dp_colorgrad&quot;:
            seam_finder = cv.detail_DpSeamFinder(&quot;COLOR_GRAD&quot;)
        if seam_finder is None:
            print(&quot;Can't create the following seam finder &quot;,seam_find_type)
            exit()

        masks_warped_updated = copy.deepcopy(masks_warped)
        seam_finder.find(images_warped_f, corners, masks_warped_updated)
        for figure_n in range(len(masks_warped)):
            plt.figure(figure_n)
            ax = plt.subplot(6, 3, finder_id*3+1)
            plt.imshow(images_warped[figure_n])
            plt.title(&quot;image&quot;)
            plt.subplot(6, 3, finder_id*3+2, sharex=ax, sharey=ax)
            plt.imshow(masks_warped[figure_n])
            plt.title(&quot;original mask&quot;)
            plt.subplot(6, 3, finder_id*3+3, sharex=ax, sharey=ax)
            plt.title(&quot;updated mask&quot;)
            plt.imshow(masks_warped_updated[figure_n])

    plt.show()
    imgListe=[]
    compose_scale=1
    corners=[]
    sizes=[]
    images_warped=[]
    images_warped_f=[]
    masks=[]
    blender= None
    timelapser=None
    compose_work_aspect=1
    for idx,name in enumerate(img_names): # https://github.com/opencv/opencv/blob/master/samples/cpp/stitching_detailed.cpp#L725 ?
        full_img  = cv.imread(name)
        if not is_compose_scale_set:
            if compose_megapix &gt; 0:
                compose_scale = min(1.0, np.sqrt(compose_megapix * 1e6 / (full_img.shape[0]*full_img.shape[1])))
            is_compose_scale_set = True;
            compose_work_aspect = compose_scale / work_scale;
            warped_image_scale *= compose_work_aspect
            warper =  cv.PyRotationWarper(warp_type,warped_image_scale)
            for i in range(0,len(img_names)):
                cameras[i].focal *= compose_work_aspect
                cameras[i].ppx *= compose_work_aspect
                cameras[i].ppy *= compose_work_aspect
                sz = (full_img_sizes[i][0] * compose_scale,full_img_sizes[i][1]* compose_scale)
                K = cameras[i].K().astype(np.float32)
                roi = warper.warpRoi(sz, K, cameras[i].R);
                corners.append(roi[0:2])
                sizes.append(roi[2:4])
        if abs(compose_scale - 1) &gt; 1e-1:
            img =cv.resize(src=full_img, dsize=None, fx=compose_scale, fy=compose_scale, interpolation=cv.INTER_LINEAR_EXACT)
        else:
            img = full_img;
        img_size = (img.shape[1],img.shape[0]);
        K=cameras[idx].K().astype(np.float32)
        corner,image_warped =warper.warp(img,K,cameras[idx].R,cv.INTER_LINEAR, cv.BORDER_REFLECT)
        mask =255*np.ones((img.shape[0],img.shape[1]),np.uint8)
        p,mask_warped =warper.warp(mask,K,cameras[idx].R,cv.INTER_NEAREST, cv.BORDER_CONSTANT)
        compensator.apply(idx,corners[idx],image_warped,mask_warped)
        image_warped_s = image_warped.astype(np.int16)
        image_warped=[]
        dilated_mask = cv.dilate(masks_warped[idx],None)
        seam_mask = cv.resize(dilated_mask,(mask_warped.shape[1],mask_warped.shape[0]),0,0,cv.INTER_LINEAR_EXACT)
        mask_warped = cv.bitwise_and(seam_mask,mask_warped)
        if blender==None and not timelapse:
            blender = cv.detail.Blender_createDefault(cv.detail.Blender_NO)
            dst_sz = cv.detail.resultRoi(corners=corners,sizes=sizes)
            blend_width = np.sqrt(dst_sz[2]*dst_sz[3]) * blend_strength / 100
            if blend_width &lt; 1:
                blender = cv.detail.Blender_createDefault(cv.detail.Blender_NO)
            elif blend_type == &quot;multiband&quot;:
                blender = cv.detail_MultiBandBlender()
                blender.setNumBands((np.log(blend_width)/np.log(2.) - 1.).astype(np.int))
            elif blend_type == &quot;feather&quot;:
                blender = cv.detail_FeatherBlender()
                blender.setSharpness(1./blend_width)
            blender.prepare(dst_sz)
        elif timelapser==None  and timelapse:
            timelapser = cv.detail.Timelapser_createDefault(timelapse_type)
            timelapser.initialize(corners, sizes)
        if timelapse:
            matones=np.ones((image_warped_s.shape[0],image_warped_s.shape[1]), np.uint8)
            timelapser.process(image_warped_s, matones, corners[idx])
            pos_s = img_names[idx].rfind(&quot;/&quot;);
            if pos_s == -1:
                fixedFileName = &quot;fixed_&quot; + img_names[idx];
            else:
                fixedFileName = img_names[idx][:pos_s + 1 ]+&quot;fixed_&quot; + img_names[idx][pos_s + 1: ]
            cv.imwrite(fixedFileName, timelapser.getDst())
        else:
            blender.feed(cv.UMat(image_warped_s), mask_warped, corners[idx])
    if not timelapse:
        result=None
        result_mask=None
        result,result_mask = blender.blend(result,result_mask)
        cv.imwrite(result_name,result)
        zoomx = 600.0 / result.shape[1]
        dst=cv.normalize(src=result,dst=None,alpha=255.,norm_type=cv.NORM_MINMAX,dtype=cv.CV_8U)
        dst=cv.resize(dst,dsize=None,fx=zoomx,fy=zoomx)
        cv.imshow(result_name,dst)
        cv.waitKey()

    print('Done')


if __name__ == '__main__':
    print(__doc__)
    main()
    cv.destroyAllWindows()"><pre class="notranslate">   <span class="pl-s">"""</span>
<span class="pl-s">Stitching sample (advanced)</span>
<span class="pl-s">===========================</span>
<span class="pl-s"></span>
<span class="pl-s">Show how to use Stitcher API from python.</span>
<span class="pl-s">"""</span>

<span class="pl-c"># Python 2/3 compatibility</span>
<span class="pl-k">from</span> __future__ <span class="pl-k">import</span> <span class="pl-s1">print_function</span>

<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">copy</span>
<span class="pl-k">import</span> <span class="pl-s1">cv2</span> <span class="pl-k">as</span> <span class="pl-s1">cv</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-k">import</span> <span class="pl-s1">sys</span>
<span class="pl-k">import</span> <span class="pl-s1">argparse</span>

<span class="pl-s1">parser</span> <span class="pl-c1">=</span> <span class="pl-s1">argparse</span>.<span class="pl-v">ArgumentParser</span>(<span class="pl-s1">prog</span><span class="pl-c1">=</span><span class="pl-s">'stitching_detailed.py'</span>, <span class="pl-s1">description</span><span class="pl-c1">=</span><span class="pl-s">'Rotation model images stitcher'</span>)
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'img_names'</span>, <span class="pl-s1">nargs</span><span class="pl-c1">=</span><span class="pl-s">'+'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'files to stitch'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>)
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--preview'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Run stitching in the preview mode. Works faster than usual mode but output image will have lower resolution.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">bool</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'preview'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--try_cuda'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Try to use CUDA. The default value is no. All default values are for CPU mode.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">bool</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'try_cuda'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--work_megapix'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">0.6</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">' Resolution for image registration step. The default is 0.6 Mpx'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">float</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'work_megapix'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--features'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'orb'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Type of features used for images matching. The default is orb.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'features'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--matcher'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'homography'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Matcher used for pairwise image matching.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'matcher'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--estimator'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'homography'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Type of estimator used for transformation estimation.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'estimator'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--match_conf'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">0.3</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Confidence for feature matching step. The default is 0.65 for surf and 0.3 for orb.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">float</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'match_conf'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--conf_thresh'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">1.0</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Threshold for two images are from the same panorama confidence.The default is 1.0.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">float</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'conf_thresh'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--ba'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'ray'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Bundle adjustment cost function. The default is ray.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'ba'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--ba_refine_mask'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'xxxxx'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Set refinement mask for bundle adjustment.  mask is "xxxxx"'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'ba_refine_mask'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--wave_correct'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'horiz'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Perform wave effect correction. The default is "horiz"'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'wave_correct'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--save_graph'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Save matches graph represented in DOT language to &lt;file_name&gt; file.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'save_graph'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--warp'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'plane'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Warp surface type. The default is "spherical".'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'warp'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--seam_megapix'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">0.1</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">' Resolution for seam estimation step. The default is 0.1 Mpx.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">float</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'seam_megapix'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--seam'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'no'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Seam estimation method. The default is "gc_color".'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'seam'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--compose_megapix'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Resolution for compositing step. Use -1 for original resolution.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">float</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'compose_megapix'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--expos_comp'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'no'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Exposure compensation method. The default is "gain_blocks".'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'expos_comp'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--expos_comp_nr_feeds'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Number of exposure compensation feed.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">int32</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'expos_comp_nr_feeds'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--expos_comp_nr_filtering'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Number of filtering iterations of the exposure compensation gains'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">float</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'expos_comp_nr_filtering'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--expos_comp_block_size'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">32</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'BLock size in pixels used by the exposure compensator.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">int32</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'expos_comp_block_size'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--blend'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'multiband'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Blending method. The default is "multiband".'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'blend'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--blend_strength'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">5</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Blending strength from [0,100] range.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">int32</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'blend_strength'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--output'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-s">'result.jpg'</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'The default is "result.jpg"'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'output'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--timelapse'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'Output warped images separately as frames of a time lapse movie, with "fixed_" prepended to input file names.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">str</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'timelapse'</span> )
<span class="pl-s1">parser</span>.<span class="pl-en">add_argument</span>(<span class="pl-s">'--rangewidth'</span>,<span class="pl-s1">action</span> <span class="pl-c1">=</span> <span class="pl-s">'store'</span>, <span class="pl-s1">default</span> <span class="pl-c1">=</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>,<span class="pl-s1">help</span><span class="pl-c1">=</span><span class="pl-s">'uses range_width to limit number of images to match with.'</span>,<span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s1">int</span>,<span class="pl-s1">dest</span> <span class="pl-c1">=</span> <span class="pl-s">'rangewidth'</span> )

<span class="pl-s1">__doc__</span> <span class="pl-c1">+=</span> <span class="pl-s">'<span class="pl-cce">\n</span>'</span> <span class="pl-c1">+</span> <span class="pl-s1">parser</span>.<span class="pl-en">format_help</span>()

<span class="pl-k">def</span> <span class="pl-en">main</span>():
    <span class="pl-s1">args</span> <span class="pl-c1">=</span> <span class="pl-s1">parser</span>.<span class="pl-en">parse_args</span>()
    <span class="pl-s1">img_names</span><span class="pl-c1">=</span><span class="pl-s1">args</span>.<span class="pl-s1">img_names</span>
    <span class="pl-en">print</span>(<span class="pl-s1">img_names</span>)
    <span class="pl-s1">preview</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">preview</span>
    <span class="pl-s1">try_cuda</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">try_cuda</span>
    <span class="pl-s1">work_megapix</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">work_megapix</span>
    <span class="pl-s1">seam_megapix</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">seam_megapix</span>
    <span class="pl-s1">compose_megapix</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">compose_megapix</span>
    <span class="pl-s1">conf_thresh</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">conf_thresh</span>
    <span class="pl-s1">features_type</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">features</span>
    <span class="pl-s1">matcher_type</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">matcher</span>
    <span class="pl-s1">estimator_type</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">estimator</span>
    <span class="pl-s1">ba_cost_func</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">ba</span>
    <span class="pl-s1">ba_refine_mask</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">ba_refine_mask</span>
    <span class="pl-s1">wave_correct</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">wave_correct</span>
    <span class="pl-k">if</span> <span class="pl-s1">wave_correct</span><span class="pl-c1">==</span><span class="pl-s">'no'</span>:
        <span class="pl-s1">do_wave_correct</span><span class="pl-c1">=</span> <span class="pl-c1">False</span>
    <span class="pl-k">else</span>:
        <span class="pl-s1">do_wave_correct</span><span class="pl-c1">=</span><span class="pl-c1">True</span>
    <span class="pl-k">if</span> <span class="pl-s1">args</span>.<span class="pl-s1">save_graph</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
        <span class="pl-s1">save_graph</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
    <span class="pl-k">else</span>:
        <span class="pl-s1">save_graph</span> <span class="pl-c1">=</span><span class="pl-c1">True</span>
        <span class="pl-s1">save_graph_to</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">save_graph</span>
    <span class="pl-s1">warp_type</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">warp</span>
    <span class="pl-k">if</span> <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp</span><span class="pl-c1">==</span><span class="pl-s">'no'</span>:
        <span class="pl-s1">expos_comp_type</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_NO</span>
    <span class="pl-k">elif</span>  <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp</span><span class="pl-c1">==</span><span class="pl-s">'gain'</span>:
        <span class="pl-s1">expos_comp_type</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_GAIN</span>
    <span class="pl-k">elif</span>  <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp</span><span class="pl-c1">==</span><span class="pl-s">'gain_blocks'</span>:
        <span class="pl-s1">expos_comp_type</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_GAIN_BLOCKS</span>
    <span class="pl-k">elif</span>  <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp</span><span class="pl-c1">==</span><span class="pl-s">'channel'</span>:
        <span class="pl-s1">expos_comp_type</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_CHANNELS</span>
    <span class="pl-k">elif</span>  <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp</span><span class="pl-c1">==</span><span class="pl-s">'channel_blocks'</span>:
        <span class="pl-s1">expos_comp_type</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_CHANNELS_BLOCKS</span>
    <span class="pl-k">else</span>:
        <span class="pl-en">print</span>(<span class="pl-s">"Bad exposure compensation method"</span>)
        <span class="pl-en">exit</span>()
    <span class="pl-s1">expos_comp_nr_feeds</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp_nr_feeds</span>
    <span class="pl-s1">expos_comp_nr_filtering</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp_nr_filtering</span>
    <span class="pl-s1">expos_comp_block_size</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">expos_comp_block_size</span>
    <span class="pl-s1">match_conf</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">match_conf</span>
    <span class="pl-s1">seam_find_type</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">seam</span>
    <span class="pl-s1">blend_type</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">blend</span>
    <span class="pl-s1">blend_strength</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">blend_strength</span>
    <span class="pl-s1">result_name</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">output</span>
    <span class="pl-k">if</span> <span class="pl-s1">args</span>.<span class="pl-s1">timelapse</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>:
        <span class="pl-s1">timelapse</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
        <span class="pl-k">if</span> <span class="pl-s1">args</span>.<span class="pl-s1">timelapse</span><span class="pl-c1">==</span><span class="pl-s">"as_is"</span>:
            <span class="pl-s1">timelapse_type</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">Timelapser_AS_IS</span>
        <span class="pl-k">elif</span> <span class="pl-s1">args</span>.<span class="pl-s1">timelapse</span><span class="pl-c1">==</span><span class="pl-s">"crop"</span>:
            <span class="pl-s1">timelapse_type</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">Timelapser_CROP</span>
        <span class="pl-k">else</span>:
            <span class="pl-en">print</span>(<span class="pl-s">"Bad timelapse method"</span>)
            <span class="pl-en">exit</span>()
    <span class="pl-k">else</span>:
        <span class="pl-s1">timelapse</span><span class="pl-c1">=</span> <span class="pl-c1">False</span>
    <span class="pl-s1">range_width</span> <span class="pl-c1">=</span> <span class="pl-s1">args</span>.<span class="pl-s1">rangewidth</span>
    <span class="pl-k">if</span> <span class="pl-s1">features_type</span><span class="pl-c1">==</span><span class="pl-s">'orb'</span>:
        <span class="pl-s1">finder</span><span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-v">ORB</span>.<span class="pl-en">create</span>()
    <span class="pl-k">elif</span> <span class="pl-s1">features_type</span><span class="pl-c1">==</span><span class="pl-s">'surf'</span>:
        <span class="pl-s1">finder</span><span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">xfeatures2d_SURF</span>.<span class="pl-en">create</span>()
    <span class="pl-k">elif</span> <span class="pl-s1">features_type</span><span class="pl-c1">==</span><span class="pl-s">'sift'</span>:
        <span class="pl-s1">finder</span><span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">xfeatures2d_SIFT</span>.<span class="pl-en">create</span>()
    <span class="pl-k">else</span>:
        <span class="pl-en">print</span> (<span class="pl-s">"Unknown descriptor type"</span>)
        <span class="pl-en">exit</span>()
    <span class="pl-s1">seam_work_aspect</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-s1">full_img_sizes</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">features</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">images</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">is_work_scale_set</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
    <span class="pl-s1">is_seam_scale_set</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
    <span class="pl-s1">is_compose_scale_set</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>;
    <span class="pl-k">for</span> <span class="pl-s1">name</span> <span class="pl-c1">in</span> <span class="pl-s1">img_names</span>:
        <span class="pl-s1">full_img</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">imread</span>(<span class="pl-s1">cv</span>.<span class="pl-s1">samples</span>.<span class="pl-en">findFile</span>(<span class="pl-s1">name</span>))
        <span class="pl-k">if</span> <span class="pl-s1">full_img</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
            <span class="pl-en">print</span>(<span class="pl-s">"Cannot read image "</span>, <span class="pl-s1">name</span>)
            <span class="pl-en">exit</span>()
        <span class="pl-s1">full_img_sizes</span>.<span class="pl-en">append</span>((<span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>],<span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]))
        <span class="pl-k">if</span> <span class="pl-s1">work_megapix</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">0</span>:
            <span class="pl-s1">img</span> <span class="pl-c1">=</span> <span class="pl-s1">full_img</span>
            <span class="pl-s1">work_scale</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
            <span class="pl-s1">is_work_scale_set</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
        <span class="pl-k">else</span>:
            <span class="pl-k">if</span> <span class="pl-s1">is_work_scale_set</span> <span class="pl-c1">is</span> <span class="pl-c1">False</span>:
                <span class="pl-s1">work_scale</span> <span class="pl-c1">=</span> <span class="pl-en">min</span>(<span class="pl-c1">1.0</span>, <span class="pl-s1">np</span>.<span class="pl-en">sqrt</span>(<span class="pl-s1">work_megapix</span> <span class="pl-c1">*</span> <span class="pl-c1">1e6</span> <span class="pl-c1">/</span> (<span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]<span class="pl-c1">*</span><span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>])))
                <span class="pl-s1">is_work_scale_set</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
            <span class="pl-s1">img</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">resize</span>(<span class="pl-s1">src</span><span class="pl-c1">=</span><span class="pl-s1">full_img</span>, <span class="pl-s1">dsize</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">fx</span><span class="pl-c1">=</span><span class="pl-s1">work_scale</span>, <span class="pl-s1">fy</span><span class="pl-c1">=</span><span class="pl-s1">work_scale</span>, <span class="pl-s1">interpolation</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-v">INTER_LINEAR_EXACT</span>)
        <span class="pl-k">if</span> <span class="pl-s1">is_seam_scale_set</span> <span class="pl-c1">is</span> <span class="pl-c1">False</span>:
            <span class="pl-s1">seam_scale</span> <span class="pl-c1">=</span> <span class="pl-en">min</span>(<span class="pl-c1">1.0</span>, <span class="pl-s1">np</span>.<span class="pl-en">sqrt</span>(<span class="pl-s1">seam_megapix</span> <span class="pl-c1">*</span> <span class="pl-c1">1e6</span> <span class="pl-c1">/</span> (<span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]<span class="pl-c1">*</span><span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>])))
            <span class="pl-s1">seam_work_aspect</span> <span class="pl-c1">=</span> <span class="pl-s1">seam_scale</span> <span class="pl-c1">/</span> <span class="pl-s1">work_scale</span>
            <span class="pl-s1">is_seam_scale_set</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>
        <span class="pl-s1">imgFea</span><span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-en">computeImageFeatures2</span>(<span class="pl-s1">finder</span>,<span class="pl-s1">img</span>)
        <span class="pl-s1">features</span>.<span class="pl-en">append</span>(<span class="pl-s1">imgFea</span>)
        <span class="pl-s1">img</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">resize</span>(<span class="pl-s1">src</span><span class="pl-c1">=</span><span class="pl-s1">full_img</span>, <span class="pl-s1">dsize</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">fx</span><span class="pl-c1">=</span><span class="pl-s1">seam_scale</span>, <span class="pl-s1">fy</span><span class="pl-c1">=</span><span class="pl-s1">seam_scale</span>, <span class="pl-s1">interpolation</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-v">INTER_LINEAR_EXACT</span>)
        <span class="pl-s1">images</span>.<span class="pl-en">append</span>(<span class="pl-s1">img</span>)
    <span class="pl-k">if</span> <span class="pl-s1">matcher_type</span><span class="pl-c1">==</span> <span class="pl-s">"affine"</span>:
        <span class="pl-s1">matcher</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_AffineBestOf2NearestMatcher</span>(<span class="pl-c1">False</span>, <span class="pl-s1">try_cuda</span>, <span class="pl-s1">match_conf</span>)
    <span class="pl-k">elif</span> <span class="pl-s1">range_width</span><span class="pl-c1">==</span><span class="pl-c1">-</span><span class="pl-c1">1</span>:
        <span class="pl-s1">matcher</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">BestOf2NearestMatcher_create</span>(<span class="pl-s1">try_cuda</span>, <span class="pl-s1">match_conf</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">matcher</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">BestOf2NearestRangeMatcher_create</span>(<span class="pl-s1">range_width</span>, <span class="pl-s1">try_cuda</span>, <span class="pl-s1">match_conf</span>)
    <span class="pl-s1">p</span><span class="pl-c1">=</span><span class="pl-s1">matcher</span>.<span class="pl-en">apply2</span>(<span class="pl-s1">features</span>)
    <span class="pl-s1">matcher</span>.<span class="pl-en">collectGarbage</span>()
    <span class="pl-k">if</span> <span class="pl-s1">save_graph</span>:
        <span class="pl-s1">f</span> <span class="pl-c1">=</span> <span class="pl-en">open</span>(<span class="pl-s1">save_graph_to</span>,<span class="pl-s">"w"</span>)
        <span class="pl-s1">f</span>.<span class="pl-en">write</span>(<span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-en">matchesGraphAsString</span>(<span class="pl-s1">img_names</span>, <span class="pl-s1">p</span>, <span class="pl-s1">conf_thresh</span>))
        <span class="pl-s1">f</span>.<span class="pl-en">close</span>()
    <span class="pl-s1">indices</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-en">leaveBiggestComponent</span>(<span class="pl-s1">features</span>,<span class="pl-s1">p</span>,<span class="pl-c1">0.3</span>)
    <span class="pl-s1">img_subset</span> <span class="pl-c1">=</span>[]
    <span class="pl-s1">img_names_subset</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">full_img_sizes_subset</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">num_images</span><span class="pl-c1">=</span><span class="pl-en">len</span>(<span class="pl-s1">indices</span>)
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">indices</span>)):
        <span class="pl-s1">img_names_subset</span>.<span class="pl-en">append</span>(<span class="pl-s1">img_names</span>[<span class="pl-s1">indices</span>[<span class="pl-s1">i</span>,<span class="pl-c1">0</span>]])
        <span class="pl-s1">img_subset</span>.<span class="pl-en">append</span>(<span class="pl-s1">images</span>[<span class="pl-s1">indices</span>[<span class="pl-s1">i</span>,<span class="pl-c1">0</span>]])
        <span class="pl-s1">full_img_sizes_subset</span>.<span class="pl-en">append</span>(<span class="pl-s1">full_img_sizes</span>[<span class="pl-s1">indices</span>[<span class="pl-s1">i</span>,<span class="pl-c1">0</span>]])
    <span class="pl-s1">images</span> <span class="pl-c1">=</span> <span class="pl-s1">img_subset</span>;
    <span class="pl-s1">img_names</span> <span class="pl-c1">=</span> <span class="pl-s1">img_names_subset</span>;
    <span class="pl-s1">full_img_sizes</span> <span class="pl-c1">=</span> <span class="pl-s1">full_img_sizes_subset</span>;
    <span class="pl-s1">num_images</span> <span class="pl-c1">=</span> <span class="pl-en">len</span>(<span class="pl-s1">img_names</span>)
    <span class="pl-k">if</span> <span class="pl-s1">num_images</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">2</span>:
        <span class="pl-en">print</span>(<span class="pl-s">"Need more images"</span>)
        <span class="pl-en">exit</span>()

    <span class="pl-k">if</span> <span class="pl-s1">estimator_type</span> <span class="pl-c1">==</span> <span class="pl-s">"affine"</span>:
        <span class="pl-s1">estimator</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_AffineBasedEstimator</span>()
    <span class="pl-k">else</span>:
        <span class="pl-s1">estimator</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_HomographyBasedEstimator</span>()
    <span class="pl-s1">b</span>, <span class="pl-s1">cameras</span> <span class="pl-c1">=</span><span class="pl-s1">estimator</span>.<span class="pl-en">apply</span>(<span class="pl-s1">features</span>,<span class="pl-s1">p</span>,<span class="pl-c1">None</span>)
    <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">b</span>:
        <span class="pl-en">print</span>(<span class="pl-s">"Homography estimation failed."</span>)
        <span class="pl-en">exit</span>()
    <span class="pl-k">for</span> <span class="pl-s1">cam</span> <span class="pl-c1">in</span> <span class="pl-s1">cameras</span>:
        <span class="pl-s1">cam</span>.<span class="pl-v">R</span><span class="pl-c1">=</span><span class="pl-s1">cam</span>.<span class="pl-v">R</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)

    <span class="pl-k">if</span> <span class="pl-s1">ba_cost_func</span> <span class="pl-c1">==</span> <span class="pl-s">"reproj"</span>:
        <span class="pl-s1">adjuster</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_BundleAdjusterReproj</span>()
    <span class="pl-k">elif</span> <span class="pl-s1">ba_cost_func</span> <span class="pl-c1">==</span> <span class="pl-s">"ray"</span>:
        <span class="pl-s1">adjuster</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_BundleAdjusterRay</span>()
    <span class="pl-k">elif</span> <span class="pl-s1">ba_cost_func</span> <span class="pl-c1">==</span> <span class="pl-s">"affine"</span>:
        <span class="pl-s1">adjuster</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_BundleAdjusterAffinePartial</span>()
    <span class="pl-k">elif</span> <span class="pl-s1">ba_cost_func</span> <span class="pl-c1">==</span> <span class="pl-s">"no"</span>:
        <span class="pl-s1">adjuster</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_NoBundleAdjuster</span>()
    <span class="pl-k">else</span>:
        <span class="pl-en">print</span>( <span class="pl-s">"Unknown bundle adjustment cost function: "</span>, <span class="pl-s1">ba_cost_func</span> )
        <span class="pl-en">exit</span>()
    <span class="pl-s1">adjuster</span>.<span class="pl-en">setConfThresh</span>(<span class="pl-c1">1</span>)
    <span class="pl-s1">refine_mask</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">zeros</span>((<span class="pl-c1">3</span>,<span class="pl-c1">3</span>),<span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>)
    <span class="pl-k">if</span> <span class="pl-s1">ba_refine_mask</span>[<span class="pl-c1">0</span>] <span class="pl-c1">==</span> <span class="pl-s">'x'</span>:
        <span class="pl-s1">refine_mask</span>[<span class="pl-c1">0</span>,<span class="pl-c1">0</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-k">if</span> <span class="pl-s1">ba_refine_mask</span>[<span class="pl-c1">1</span>] <span class="pl-c1">==</span> <span class="pl-s">'x'</span>:
        <span class="pl-s1">refine_mask</span>[<span class="pl-c1">0</span>,<span class="pl-c1">1</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-k">if</span> <span class="pl-s1">ba_refine_mask</span>[<span class="pl-c1">2</span>] <span class="pl-c1">==</span> <span class="pl-s">'x'</span>:
        <span class="pl-s1">refine_mask</span>[<span class="pl-c1">0</span>,<span class="pl-c1">2</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-k">if</span> <span class="pl-s1">ba_refine_mask</span>[<span class="pl-c1">3</span>] <span class="pl-c1">==</span> <span class="pl-s">'x'</span>:
        <span class="pl-s1">refine_mask</span>[<span class="pl-c1">1</span>,<span class="pl-c1">1</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-k">if</span> <span class="pl-s1">ba_refine_mask</span>[<span class="pl-c1">4</span>] <span class="pl-c1">==</span> <span class="pl-s">'x'</span>:
        <span class="pl-s1">refine_mask</span>[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
    <span class="pl-s1">adjuster</span>.<span class="pl-en">setRefinementMask</span>(<span class="pl-s1">refine_mask</span>)
    <span class="pl-s1">b</span>,<span class="pl-s1">cameras</span> <span class="pl-c1">=</span> <span class="pl-s1">adjuster</span>.<span class="pl-en">apply</span>(<span class="pl-s1">features</span>,<span class="pl-s1">p</span>,<span class="pl-s1">cameras</span>)
    <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">b</span>:
        <span class="pl-en">print</span>(<span class="pl-s">"Camera parameters adjusting failed."</span>)
        <span class="pl-en">exit</span>()
    <span class="pl-s1">focals</span><span class="pl-c1">=</span>[]
    <span class="pl-k">for</span> <span class="pl-s1">cam</span> <span class="pl-c1">in</span> <span class="pl-s1">cameras</span>:
        <span class="pl-s1">focals</span>.<span class="pl-en">append</span>(<span class="pl-s1">cam</span>.<span class="pl-s1">focal</span>)
    <span class="pl-en">sorted</span>(<span class="pl-s1">focals</span>)
    <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">focals</span>)<span class="pl-c1">%</span><span class="pl-c1">2</span><span class="pl-c1">==</span><span class="pl-c1">1</span>:
        <span class="pl-s1">warped_image_scale</span> <span class="pl-c1">=</span> <span class="pl-s1">focals</span>[<span class="pl-en">len</span>(<span class="pl-s1">focals</span>) <span class="pl-c1">//</span> <span class="pl-c1">2</span>]
    <span class="pl-k">else</span>:
        <span class="pl-s1">warped_image_scale</span> <span class="pl-c1">=</span> (<span class="pl-s1">focals</span>[<span class="pl-en">len</span>(<span class="pl-s1">focals</span>) <span class="pl-c1">//</span> <span class="pl-c1">2</span>]<span class="pl-c1">+</span><span class="pl-s1">focals</span>[<span class="pl-en">len</span>(<span class="pl-s1">focals</span>) <span class="pl-c1">//</span> <span class="pl-c1">2</span><span class="pl-c1">-</span><span class="pl-c1">1</span>])<span class="pl-c1">/</span><span class="pl-c1">2</span>
    <span class="pl-k">if</span> <span class="pl-s1">do_wave_correct</span>:
        <span class="pl-s1">rmats</span><span class="pl-c1">=</span>[]
        <span class="pl-k">for</span> <span class="pl-s1">cam</span> <span class="pl-c1">in</span> <span class="pl-s1">cameras</span>:
            <span class="pl-s1">rmats</span>.<span class="pl-en">append</span>(<span class="pl-s1">np</span>.<span class="pl-en">copy</span>(<span class="pl-s1">cam</span>.<span class="pl-v">R</span>))
        <span class="pl-s1">rmats</span>	<span class="pl-c1">=</span>	<span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-en">waveCorrect</span>(	<span class="pl-s1">rmats</span>,  <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">WAVE_CORRECT_HORIZ</span>)
        <span class="pl-k">for</span> <span class="pl-s1">idx</span>,<span class="pl-s1">cam</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(<span class="pl-s1">cameras</span>):
            <span class="pl-s1">cam</span>.<span class="pl-v">R</span> <span class="pl-c1">=</span> <span class="pl-s1">rmats</span>[<span class="pl-s1">idx</span>]
    <span class="pl-s1">corners</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">mask</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">masks_warped</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">images_warped</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">sizes</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">masks</span><span class="pl-c1">=</span>[]
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">0</span>,<span class="pl-s1">num_images</span>):
        <span class="pl-s1">um</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-v">UMat</span>(<span class="pl-c1">255</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-en">ones</span>((<span class="pl-s1">images</span>[<span class="pl-s1">i</span>].<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>],<span class="pl-s1">images</span>[<span class="pl-s1">i</span>].<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>]),<span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>))
        <span class="pl-s1">masks</span>.<span class="pl-en">append</span>(<span class="pl-s1">um</span>)

    <span class="pl-s1">warper</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-v">PyRotationWarper</span>(<span class="pl-s1">warp_type</span>,<span class="pl-s1">warped_image_scale</span><span class="pl-c1">*</span><span class="pl-s1">seam_work_aspect</span>) <span class="pl-c"># warper peut etre nullptr?</span>
    <span class="pl-k">for</span> <span class="pl-s1">idx</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">0</span>,<span class="pl-s1">num_images</span>):
        <span class="pl-v">K</span> <span class="pl-c1">=</span> <span class="pl-s1">cameras</span>[<span class="pl-s1">idx</span>].<span class="pl-v">K</span>().<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)
        <span class="pl-s1">swa</span> <span class="pl-c1">=</span> <span class="pl-s1">seam_work_aspect</span>
        <span class="pl-v">K</span>[<span class="pl-c1">0</span>,<span class="pl-c1">0</span>] <span class="pl-c1">*=</span> <span class="pl-s1">swa</span>
        <span class="pl-v">K</span>[<span class="pl-c1">0</span>,<span class="pl-c1">2</span>] <span class="pl-c1">*=</span> <span class="pl-s1">swa</span>
        <span class="pl-v">K</span>[<span class="pl-c1">1</span>,<span class="pl-c1">1</span>] <span class="pl-c1">*=</span> <span class="pl-s1">swa</span>
        <span class="pl-v">K</span>[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>] <span class="pl-c1">*=</span> <span class="pl-s1">swa</span>
        <span class="pl-s1">corner</span>,<span class="pl-s1">image_wp</span> <span class="pl-c1">=</span><span class="pl-s1">warper</span>.<span class="pl-en">warp</span>(<span class="pl-s1">images</span>[<span class="pl-s1">idx</span>],<span class="pl-v">K</span>,<span class="pl-s1">cameras</span>[<span class="pl-s1">idx</span>].<span class="pl-v">R</span>,<span class="pl-s1">cv</span>.<span class="pl-v">INTER_LINEAR</span>, <span class="pl-s1">cv</span>.<span class="pl-v">BORDER_REFLECT</span>)
        <span class="pl-s1">corners</span>.<span class="pl-en">append</span>(<span class="pl-s1">corner</span>)
        <span class="pl-s1">sizes</span>.<span class="pl-en">append</span>((<span class="pl-s1">image_wp</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>],<span class="pl-s1">image_wp</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]))
        <span class="pl-s1">images_warped</span>.<span class="pl-en">append</span>(<span class="pl-s1">image_wp</span>)

        <span class="pl-s1">p</span>,<span class="pl-s1">mask_wp</span> <span class="pl-c1">=</span><span class="pl-s1">warper</span>.<span class="pl-en">warp</span>(<span class="pl-s1">masks</span>[<span class="pl-s1">idx</span>],<span class="pl-v">K</span>,<span class="pl-s1">cameras</span>[<span class="pl-s1">idx</span>].<span class="pl-v">R</span>,<span class="pl-s1">cv</span>.<span class="pl-v">INTER_NEAREST</span>, <span class="pl-s1">cv</span>.<span class="pl-v">BORDER_CONSTANT</span>)
        <span class="pl-s1">masks_warped</span>.<span class="pl-en">append</span>(<span class="pl-s1">mask_wp</span>.<span class="pl-en">get</span>())
    <span class="pl-s1">images_warped_f</span><span class="pl-c1">=</span>[]
    <span class="pl-k">for</span> <span class="pl-s1">img</span> <span class="pl-c1">in</span> <span class="pl-s1">images_warped</span>:
        <span class="pl-s1">imgf</span><span class="pl-c1">=</span><span class="pl-s1">img</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)
        <span class="pl-s1">images_warped_f</span>.<span class="pl-en">append</span>(<span class="pl-s1">imgf</span>)
    <span class="pl-k">if</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_CHANNELS</span> <span class="pl-c1">==</span> <span class="pl-s1">expos_comp_type</span>:
        <span class="pl-s1">compensator</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_ChannelsCompensator</span>(<span class="pl-s1">expos_comp_nr_feeds</span>)
    <span class="pl-c">#    compensator.setNrGainsFilteringIterations(expos_comp_nr_filtering)</span>
    <span class="pl-k">elif</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_CHANNELS_BLOCKS</span> <span class="pl-c1">==</span> <span class="pl-s1">expos_comp_type</span>:
        <span class="pl-s1">compensator</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-en">detail_BlocksChannelsCompensator</span>(<span class="pl-s1">expos_comp_block_size</span>, <span class="pl-s1">expos_comp_block_size</span>,<span class="pl-s1">expos_comp_nr_feeds</span>)
    <span class="pl-c">#    compensator.setNrGainsFilteringIterations(expos_comp_nr_filtering)</span>
    <span class="pl-k">else</span>:
        <span class="pl-s1">compensator</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">ExposureCompensator_createDefault</span>(<span class="pl-s1">expos_comp_type</span>)
    <span class="pl-s1">compensator</span>.<span class="pl-en">feed</span>(<span class="pl-s1">corners</span><span class="pl-c1">=</span><span class="pl-s1">corners</span>, <span class="pl-s1">images</span><span class="pl-c1">=</span><span class="pl-s1">images_warped</span>, <span class="pl-s1">masks</span><span class="pl-c1">=</span><span class="pl-s1">masks_warped</span>)
    <span class="pl-k">for</span> <span class="pl-s1">finder_id</span>, <span class="pl-s1">finder_name</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(
            [<span class="pl-s">"no"</span>, <span class="pl-s">"voronoi"</span>, <span class="pl-s">"gc_color"</span>, <span class="pl-s">"gc_colorgrad"</span>, <span class="pl-s">"dp_color"</span>, <span class="pl-s">"dp_colorgrad"</span>]
    ):
        <span class="pl-k">if</span> <span class="pl-s1">seam_find_type</span> <span class="pl-c1">==</span> <span class="pl-s">"no"</span>:
            <span class="pl-s1">seam_finder</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">SeamFinder_createDefault</span>(<span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">SeamFinder_NO</span>)
        <span class="pl-k">elif</span> <span class="pl-s1">seam_find_type</span> <span class="pl-c1">==</span> <span class="pl-s">"voronoi"</span>:
            <span class="pl-s1">seam_finder</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">SeamFinder_createDefault</span>(<span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">SeamFinder_VORONOI_SEAM</span>);
        <span class="pl-k">elif</span> <span class="pl-s1">seam_find_type</span> <span class="pl-c1">==</span> <span class="pl-s">"gc_color"</span>:
            <span class="pl-s1">seam_finder</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_GraphCutSeamFinder</span>(<span class="pl-s">"COST_COLOR"</span>)
        <span class="pl-k">elif</span> <span class="pl-s1">seam_find_type</span> <span class="pl-c1">==</span> <span class="pl-s">"gc_colorgrad"</span>:
            <span class="pl-s1">seam_finder</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_GraphCutSeamFinder</span>(<span class="pl-s">"COST_COLOR_GRAD"</span>)
        <span class="pl-k">elif</span> <span class="pl-s1">seam_find_type</span> <span class="pl-c1">==</span> <span class="pl-s">"dp_color"</span>:
            <span class="pl-s1">seam_finder</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_DpSeamFinder</span>(<span class="pl-s">"COLOR"</span>)
        <span class="pl-k">elif</span> <span class="pl-s1">seam_find_type</span> <span class="pl-c1">==</span> <span class="pl-s">"dp_colorgrad"</span>:
            <span class="pl-s1">seam_finder</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_DpSeamFinder</span>(<span class="pl-s">"COLOR_GRAD"</span>)
        <span class="pl-k">if</span> <span class="pl-s1">seam_finder</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
            <span class="pl-en">print</span>(<span class="pl-s">"Can't create the following seam finder "</span>,<span class="pl-s1">seam_find_type</span>)
            <span class="pl-en">exit</span>()

        <span class="pl-s1">masks_warped_updated</span> <span class="pl-c1">=</span> <span class="pl-s1">copy</span>.<span class="pl-en">deepcopy</span>(<span class="pl-s1">masks_warped</span>)
        <span class="pl-s1">seam_finder</span>.<span class="pl-en">find</span>(<span class="pl-s1">images_warped_f</span>, <span class="pl-s1">corners</span>, <span class="pl-s1">masks_warped_updated</span>)
        <span class="pl-k">for</span> <span class="pl-s1">figure_n</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">masks_warped</span>)):
            <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s1">figure_n</span>)
            <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplot</span>(<span class="pl-c1">6</span>, <span class="pl-c1">3</span>, <span class="pl-s1">finder_id</span><span class="pl-c1">*</span><span class="pl-c1">3</span><span class="pl-c1">+</span><span class="pl-c1">1</span>)
            <span class="pl-s1">plt</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">images_warped</span>[<span class="pl-s1">figure_n</span>])
            <span class="pl-s1">plt</span>.<span class="pl-en">title</span>(<span class="pl-s">"image"</span>)
            <span class="pl-s1">plt</span>.<span class="pl-en">subplot</span>(<span class="pl-c1">6</span>, <span class="pl-c1">3</span>, <span class="pl-s1">finder_id</span><span class="pl-c1">*</span><span class="pl-c1">3</span><span class="pl-c1">+</span><span class="pl-c1">2</span>, <span class="pl-s1">sharex</span><span class="pl-c1">=</span><span class="pl-s1">ax</span>, <span class="pl-s1">sharey</span><span class="pl-c1">=</span><span class="pl-s1">ax</span>)
            <span class="pl-s1">plt</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">masks_warped</span>[<span class="pl-s1">figure_n</span>])
            <span class="pl-s1">plt</span>.<span class="pl-en">title</span>(<span class="pl-s">"original mask"</span>)
            <span class="pl-s1">plt</span>.<span class="pl-en">subplot</span>(<span class="pl-c1">6</span>, <span class="pl-c1">3</span>, <span class="pl-s1">finder_id</span><span class="pl-c1">*</span><span class="pl-c1">3</span><span class="pl-c1">+</span><span class="pl-c1">3</span>, <span class="pl-s1">sharex</span><span class="pl-c1">=</span><span class="pl-s1">ax</span>, <span class="pl-s1">sharey</span><span class="pl-c1">=</span><span class="pl-s1">ax</span>)
            <span class="pl-s1">plt</span>.<span class="pl-en">title</span>(<span class="pl-s">"updated mask"</span>)
            <span class="pl-s1">plt</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">masks_warped_updated</span>[<span class="pl-s1">figure_n</span>])

    <span class="pl-s1">plt</span>.<span class="pl-en">show</span>()
    <span class="pl-s1">imgListe</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">compose_scale</span><span class="pl-c1">=</span><span class="pl-c1">1</span>
    <span class="pl-s1">corners</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">sizes</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">images_warped</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">images_warped_f</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">masks</span><span class="pl-c1">=</span>[]
    <span class="pl-s1">blender</span><span class="pl-c1">=</span> <span class="pl-c1">None</span>
    <span class="pl-s1">timelapser</span><span class="pl-c1">=</span><span class="pl-c1">None</span>
    <span class="pl-s1">compose_work_aspect</span><span class="pl-c1">=</span><span class="pl-c1">1</span>
    <span class="pl-k">for</span> <span class="pl-s1">idx</span>,<span class="pl-s1">name</span> <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(<span class="pl-s1">img_names</span>): <span class="pl-c"># https://github.com/opencv/opencv/blob/master/samples/cpp/stitching_detailed.cpp#L725 ?</span>
        <span class="pl-s1">full_img</span>  <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">imread</span>(<span class="pl-s1">name</span>)
        <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">is_compose_scale_set</span>:
            <span class="pl-k">if</span> <span class="pl-s1">compose_megapix</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span>:
                <span class="pl-s1">compose_scale</span> <span class="pl-c1">=</span> <span class="pl-en">min</span>(<span class="pl-c1">1.0</span>, <span class="pl-s1">np</span>.<span class="pl-en">sqrt</span>(<span class="pl-s1">compose_megapix</span> <span class="pl-c1">*</span> <span class="pl-c1">1e6</span> <span class="pl-c1">/</span> (<span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]<span class="pl-c1">*</span><span class="pl-s1">full_img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>])))
            <span class="pl-s1">is_compose_scale_set</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>;
            <span class="pl-s1">compose_work_aspect</span> <span class="pl-c1">=</span> <span class="pl-s1">compose_scale</span> <span class="pl-c1">/</span> <span class="pl-s1">work_scale</span>;
            <span class="pl-s1">warped_image_scale</span> <span class="pl-c1">*=</span> <span class="pl-s1">compose_work_aspect</span>
            <span class="pl-s1">warper</span> <span class="pl-c1">=</span>  <span class="pl-s1">cv</span>.<span class="pl-v">PyRotationWarper</span>(<span class="pl-s1">warp_type</span>,<span class="pl-s1">warped_image_scale</span>)
            <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">0</span>,<span class="pl-en">len</span>(<span class="pl-s1">img_names</span>)):
                <span class="pl-s1">cameras</span>[<span class="pl-s1">i</span>].<span class="pl-s1">focal</span> <span class="pl-c1">*=</span> <span class="pl-s1">compose_work_aspect</span>
                <span class="pl-s1">cameras</span>[<span class="pl-s1">i</span>].<span class="pl-s1">ppx</span> <span class="pl-c1">*=</span> <span class="pl-s1">compose_work_aspect</span>
                <span class="pl-s1">cameras</span>[<span class="pl-s1">i</span>].<span class="pl-s1">ppy</span> <span class="pl-c1">*=</span> <span class="pl-s1">compose_work_aspect</span>
                <span class="pl-s1">sz</span> <span class="pl-c1">=</span> (<span class="pl-s1">full_img_sizes</span>[<span class="pl-s1">i</span>][<span class="pl-c1">0</span>] <span class="pl-c1">*</span> <span class="pl-s1">compose_scale</span>,<span class="pl-s1">full_img_sizes</span>[<span class="pl-s1">i</span>][<span class="pl-c1">1</span>]<span class="pl-c1">*</span> <span class="pl-s1">compose_scale</span>)
                <span class="pl-v">K</span> <span class="pl-c1">=</span> <span class="pl-s1">cameras</span>[<span class="pl-s1">i</span>].<span class="pl-v">K</span>().<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)
                <span class="pl-s1">roi</span> <span class="pl-c1">=</span> <span class="pl-s1">warper</span>.<span class="pl-en">warpRoi</span>(<span class="pl-s1">sz</span>, <span class="pl-v">K</span>, <span class="pl-s1">cameras</span>[<span class="pl-s1">i</span>].<span class="pl-v">R</span>);
                <span class="pl-s1">corners</span>.<span class="pl-en">append</span>(<span class="pl-s1">roi</span>[<span class="pl-c1">0</span>:<span class="pl-c1">2</span>])
                <span class="pl-s1">sizes</span>.<span class="pl-en">append</span>(<span class="pl-s1">roi</span>[<span class="pl-c1">2</span>:<span class="pl-c1">4</span>])
        <span class="pl-k">if</span> <span class="pl-en">abs</span>(<span class="pl-s1">compose_scale</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span>) <span class="pl-c1">&gt;</span> <span class="pl-c1">1e-1</span>:
            <span class="pl-s1">img</span> <span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-en">resize</span>(<span class="pl-s1">src</span><span class="pl-c1">=</span><span class="pl-s1">full_img</span>, <span class="pl-s1">dsize</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">fx</span><span class="pl-c1">=</span><span class="pl-s1">compose_scale</span>, <span class="pl-s1">fy</span><span class="pl-c1">=</span><span class="pl-s1">compose_scale</span>, <span class="pl-s1">interpolation</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-v">INTER_LINEAR_EXACT</span>)
        <span class="pl-k">else</span>:
            <span class="pl-s1">img</span> <span class="pl-c1">=</span> <span class="pl-s1">full_img</span>;
        <span class="pl-s1">img_size</span> <span class="pl-c1">=</span> (<span class="pl-s1">img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>],<span class="pl-s1">img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]);
        <span class="pl-v">K</span><span class="pl-c1">=</span><span class="pl-s1">cameras</span>[<span class="pl-s1">idx</span>].<span class="pl-v">K</span>().<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)
        <span class="pl-s1">corner</span>,<span class="pl-s1">image_warped</span> <span class="pl-c1">=</span><span class="pl-s1">warper</span>.<span class="pl-en">warp</span>(<span class="pl-s1">img</span>,<span class="pl-v">K</span>,<span class="pl-s1">cameras</span>[<span class="pl-s1">idx</span>].<span class="pl-v">R</span>,<span class="pl-s1">cv</span>.<span class="pl-v">INTER_LINEAR</span>, <span class="pl-s1">cv</span>.<span class="pl-v">BORDER_REFLECT</span>)
        <span class="pl-s1">mask</span> <span class="pl-c1">=</span><span class="pl-c1">255</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-en">ones</span>((<span class="pl-s1">img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>],<span class="pl-s1">img</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>]),<span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>)
        <span class="pl-s1">p</span>,<span class="pl-s1">mask_warped</span> <span class="pl-c1">=</span><span class="pl-s1">warper</span>.<span class="pl-en">warp</span>(<span class="pl-s1">mask</span>,<span class="pl-v">K</span>,<span class="pl-s1">cameras</span>[<span class="pl-s1">idx</span>].<span class="pl-v">R</span>,<span class="pl-s1">cv</span>.<span class="pl-v">INTER_NEAREST</span>, <span class="pl-s1">cv</span>.<span class="pl-v">BORDER_CONSTANT</span>)
        <span class="pl-s1">compensator</span>.<span class="pl-en">apply</span>(<span class="pl-s1">idx</span>,<span class="pl-s1">corners</span>[<span class="pl-s1">idx</span>],<span class="pl-s1">image_warped</span>,<span class="pl-s1">mask_warped</span>)
        <span class="pl-s1">image_warped_s</span> <span class="pl-c1">=</span> <span class="pl-s1">image_warped</span>.<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">int16</span>)
        <span class="pl-s1">image_warped</span><span class="pl-c1">=</span>[]
        <span class="pl-s1">dilated_mask</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">dilate</span>(<span class="pl-s1">masks_warped</span>[<span class="pl-s1">idx</span>],<span class="pl-c1">None</span>)
        <span class="pl-s1">seam_mask</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">resize</span>(<span class="pl-s1">dilated_mask</span>,(<span class="pl-s1">mask_warped</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>],<span class="pl-s1">mask_warped</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>]),<span class="pl-c1">0</span>,<span class="pl-c1">0</span>,<span class="pl-s1">cv</span>.<span class="pl-v">INTER_LINEAR_EXACT</span>)
        <span class="pl-s1">mask_warped</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">bitwise_and</span>(<span class="pl-s1">seam_mask</span>,<span class="pl-s1">mask_warped</span>)
        <span class="pl-k">if</span> <span class="pl-s1">blender</span><span class="pl-c1">==</span><span class="pl-c1">None</span> <span class="pl-c1">and</span> <span class="pl-c1">not</span> <span class="pl-s1">timelapse</span>:
            <span class="pl-s1">blender</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">Blender_createDefault</span>(<span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">Blender_NO</span>)
            <span class="pl-s1">dst_sz</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-en">resultRoi</span>(<span class="pl-s1">corners</span><span class="pl-c1">=</span><span class="pl-s1">corners</span>,<span class="pl-s1">sizes</span><span class="pl-c1">=</span><span class="pl-s1">sizes</span>)
            <span class="pl-s1">blend_width</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">sqrt</span>(<span class="pl-s1">dst_sz</span>[<span class="pl-c1">2</span>]<span class="pl-c1">*</span><span class="pl-s1">dst_sz</span>[<span class="pl-c1">3</span>]) <span class="pl-c1">*</span> <span class="pl-s1">blend_strength</span> <span class="pl-c1">/</span> <span class="pl-c1">100</span>
            <span class="pl-k">if</span> <span class="pl-s1">blend_width</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">1</span>:
                <span class="pl-s1">blender</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">Blender_createDefault</span>(<span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">Blender_NO</span>)
            <span class="pl-k">elif</span> <span class="pl-s1">blend_type</span> <span class="pl-c1">==</span> <span class="pl-s">"multiband"</span>:
                <span class="pl-s1">blender</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_MultiBandBlender</span>()
                <span class="pl-s1">blender</span>.<span class="pl-en">setNumBands</span>((<span class="pl-s1">np</span>.<span class="pl-en">log</span>(<span class="pl-s1">blend_width</span>)<span class="pl-c1">/</span><span class="pl-s1">np</span>.<span class="pl-en">log</span>(<span class="pl-c1">2.</span>) <span class="pl-c1">-</span> <span class="pl-c1">1.</span>).<span class="pl-en">astype</span>(<span class="pl-s1">np</span>.<span class="pl-s1">int</span>))
            <span class="pl-k">elif</span> <span class="pl-s1">blend_type</span> <span class="pl-c1">==</span> <span class="pl-s">"feather"</span>:
                <span class="pl-s1">blender</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-en">detail_FeatherBlender</span>()
                <span class="pl-s1">blender</span>.<span class="pl-en">setSharpness</span>(<span class="pl-c1">1.</span><span class="pl-c1">/</span><span class="pl-s1">blend_width</span>)
            <span class="pl-s1">blender</span>.<span class="pl-en">prepare</span>(<span class="pl-s1">dst_sz</span>)
        <span class="pl-k">elif</span> <span class="pl-s1">timelapser</span><span class="pl-c1">==</span><span class="pl-c1">None</span>  <span class="pl-c1">and</span> <span class="pl-s1">timelapse</span>:
            <span class="pl-s1">timelapser</span> <span class="pl-c1">=</span> <span class="pl-s1">cv</span>.<span class="pl-s1">detail</span>.<span class="pl-v">Timelapser_createDefault</span>(<span class="pl-s1">timelapse_type</span>)
            <span class="pl-s1">timelapser</span>.<span class="pl-en">initialize</span>(<span class="pl-s1">corners</span>, <span class="pl-s1">sizes</span>)
        <span class="pl-k">if</span> <span class="pl-s1">timelapse</span>:
            <span class="pl-s1">matones</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">ones</span>((<span class="pl-s1">image_warped_s</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">0</span>],<span class="pl-s1">image_warped_s</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>]), <span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>)
            <span class="pl-s1">timelapser</span>.<span class="pl-en">process</span>(<span class="pl-s1">image_warped_s</span>, <span class="pl-s1">matones</span>, <span class="pl-s1">corners</span>[<span class="pl-s1">idx</span>])
            <span class="pl-s1">pos_s</span> <span class="pl-c1">=</span> <span class="pl-s1">img_names</span>[<span class="pl-s1">idx</span>].<span class="pl-en">rfind</span>(<span class="pl-s">"/"</span>);
            <span class="pl-k">if</span> <span class="pl-s1">pos_s</span> <span class="pl-c1">==</span> <span class="pl-c1">-</span><span class="pl-c1">1</span>:
                <span class="pl-s1">fixedFileName</span> <span class="pl-c1">=</span> <span class="pl-s">"fixed_"</span> <span class="pl-c1">+</span> <span class="pl-s1">img_names</span>[<span class="pl-s1">idx</span>];
            <span class="pl-k">else</span>:
                <span class="pl-s1">fixedFileName</span> <span class="pl-c1">=</span> <span class="pl-s1">img_names</span>[<span class="pl-s1">idx</span>][:<span class="pl-s1">pos_s</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span> ]<span class="pl-c1">+</span><span class="pl-s">"fixed_"</span> <span class="pl-c1">+</span> <span class="pl-s1">img_names</span>[<span class="pl-s1">idx</span>][<span class="pl-s1">pos_s</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>: ]
            <span class="pl-s1">cv</span>.<span class="pl-en">imwrite</span>(<span class="pl-s1">fixedFileName</span>, <span class="pl-s1">timelapser</span>.<span class="pl-en">getDst</span>())
        <span class="pl-k">else</span>:
            <span class="pl-s1">blender</span>.<span class="pl-en">feed</span>(<span class="pl-s1">cv</span>.<span class="pl-v">UMat</span>(<span class="pl-s1">image_warped_s</span>), <span class="pl-s1">mask_warped</span>, <span class="pl-s1">corners</span>[<span class="pl-s1">idx</span>])
    <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">timelapse</span>:
        <span class="pl-s1">result</span><span class="pl-c1">=</span><span class="pl-c1">None</span>
        <span class="pl-s1">result_mask</span><span class="pl-c1">=</span><span class="pl-c1">None</span>
        <span class="pl-s1">result</span>,<span class="pl-s1">result_mask</span> <span class="pl-c1">=</span> <span class="pl-s1">blender</span>.<span class="pl-en">blend</span>(<span class="pl-s1">result</span>,<span class="pl-s1">result_mask</span>)
        <span class="pl-s1">cv</span>.<span class="pl-en">imwrite</span>(<span class="pl-s1">result_name</span>,<span class="pl-s1">result</span>)
        <span class="pl-s1">zoomx</span> <span class="pl-c1">=</span> <span class="pl-c1">600.0</span> <span class="pl-c1">/</span> <span class="pl-s1">result</span>.<span class="pl-s1">shape</span>[<span class="pl-c1">1</span>]
        <span class="pl-s1">dst</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-en">normalize</span>(<span class="pl-s1">src</span><span class="pl-c1">=</span><span class="pl-s1">result</span>,<span class="pl-s1">dst</span><span class="pl-c1">=</span><span class="pl-c1">None</span>,<span class="pl-s1">alpha</span><span class="pl-c1">=</span><span class="pl-c1">255.</span>,<span class="pl-s1">norm_type</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-v">NORM_MINMAX</span>,<span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-v">CV_8U</span>)
        <span class="pl-s1">dst</span><span class="pl-c1">=</span><span class="pl-s1">cv</span>.<span class="pl-en">resize</span>(<span class="pl-s1">dst</span>,<span class="pl-s1">dsize</span><span class="pl-c1">=</span><span class="pl-c1">None</span>,<span class="pl-s1">fx</span><span class="pl-c1">=</span><span class="pl-s1">zoomx</span>,<span class="pl-s1">fy</span><span class="pl-c1">=</span><span class="pl-s1">zoomx</span>)
        <span class="pl-s1">cv</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">result_name</span>,<span class="pl-s1">dst</span>)
        <span class="pl-s1">cv</span>.<span class="pl-en">waitKey</span>()

    <span class="pl-en">print</span>(<span class="pl-s">'Done'</span>)


<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-en">print</span>(<span class="pl-s1">__doc__</span>)
    <span class="pl-en">main</span>()
    <span class="pl-s1">cv</span>.<span class="pl-en">destroyAllWindows</span>()</pre></div>