Esempio n. 1
0
    def test_stitcher_aquaduct(self):
        stitcher = Stitcher(nfeatures=250)
        result = stitcher.stitch(["s1.jpg", "s2.jpg"])
        cv.imwrite("result.jpg", result)

        max_image_shape_derivation = 3
        np.testing.assert_allclose(result.shape[:2], (700, 1811),
                                   atol=max_image_shape_derivation)
Esempio n. 2
0
    def test_stitcher_boat_aquaduct_subset(self):
        settings = {"final_megapix": 1, "crop": True}

        stitcher = Stitcher(**settings)
        result = stitcher.stitch([
            "boat5.jpg", "s1.jpg", "s2.jpg", "boat2.jpg", "boat3.jpg",
            "boat4.jpg", "boat1.jpg", "boat6.jpg"
        ])
        cv.imwrite("subset_low_res.jpg", result)

        max_image_shape_derivation = 100
        np.testing.assert_allclose(result.shape[:2], (705, 3374),
                                   atol=max_image_shape_derivation)
Esempio n. 3
0
    def test_timelapse(self):
        stitcher = Stitcher(timelapse='as_is')
        _ = stitcher.stitch(["s1.jpg", "s2.jpg"])
        frame1 = cv.imread("fixed_s1.jpg")

        max_image_shape_derivation = 3
        np.testing.assert_allclose(frame1.shape[:2],
                                   (700, 1811),
                                   atol=max_image_shape_derivation)

        left = cv.cvtColor(frame1[:, :1300, ], cv.COLOR_BGR2GRAY)
        right = cv.cvtColor(frame1[:, 1300:, ], cv.COLOR_BGR2GRAY)

        self.assertGreater(cv.countNonZero(left), 800000)
        self.assertEqual(cv.countNonZero(right), 0)
Esempio n. 4
0
    def test_stitcher_boat2(self):
        settings = {"warper_type": "compressedPlaneA2B1",
                    "finder": "dp_colorgrad",
                    "compensator": "channel_blocks",
                    "conf_thresh": 0.3}

        stitcher = Stitcher(**settings)
        result = stitcher.stitch(["boat5.jpg", "boat2.jpg",
                                  "boat3.jpg", "boat4.jpg",
                                  "boat1.jpg", "boat6.jpg"])

        cv.imwrite("boat_plane.jpg", result)

        max_image_shape_derivation = 600
        np.testing.assert_allclose(result.shape[:2],
                                   (7400, 12340),
                                   atol=max_image_shape_derivation)
Esempio n. 5
0
    def test_stitcher_boat1(self):
        settings = {"warper_type": "fisheye",
                    "wave_correct_kind": "no",
                    "finder": "dp_colorgrad",
                    "compensator": "no",
                    "conf_thresh": 0.3}

        stitcher = Stitcher(**settings)
        result = stitcher.stitch(["boat5.jpg", "boat2.jpg",
                                  "boat3.jpg", "boat4.jpg",
                                  "boat1.jpg", "boat6.jpg"])

        cv.imwrite("boat_fisheye.jpg", result)

        max_image_shape_derivation = 600
        np.testing.assert_allclose(result.shape[:2],
                                   (14488,  7556),
                                   atol=max_image_shape_derivation)
Esempio n. 6
0
    def test_stitcher_budapest(self):
        settings = {"matcher_type": "affine",
                    "estimator": "affine",
                    "adjuster": "affine",
                    "warper_type": "affine",
                    "wave_correct_kind": "no",
                    "confidence_threshold": 0.3}

        stitcher = Stitcher(**settings)
        result = stitcher.stitch(["budapest1.jpg", "budapest2.jpg",
                                  "budapest3.jpg", "budapest4.jpg",
                                  "budapest5.jpg", "budapest6.jpg"])

        cv.imwrite("budapest.jpg", result)

        max_image_shape_derivation = 50
        np.testing.assert_allclose(result.shape[:2],
                                   (1155, 2310),
                                   atol=max_image_shape_derivation)
Esempio n. 7
0
    def test_performance(self):

        print("Run new Stitcher class:")

        start = time.time()
        tracemalloc.start()

        stitcher = Stitcher(final_megapix=3)
        stitcher.stitch([
            "boat5.jpg", "boat2.jpg", "boat3.jpg", "boat4.jpg", "boat1.jpg",
            "boat6.jpg"
        ])

        _, peak_memory = tracemalloc.get_traced_memory()
        tracemalloc.stop()
        end = time.time()
        time_needed = end - start

        print(f"Peak was {peak_memory / 10**6} MB")
        print(f"Time was {time_needed} s")

        print("Run original stitching_detailed.py:")

        start = time.time()
        tracemalloc.start()

        main()

        _, peak_memory_detailed = tracemalloc.get_traced_memory()
        tracemalloc.stop()
        end = time.time()
        time_needed_detailed = end - start

        print(f"Peak was {peak_memory_detailed / 10**6} MB")
        print(f"Time was {time_needed_detailed} s")

        self.assertLessEqual(peak_memory / 10**6, peak_memory_detailed / 10**6)
        uncertainty_based_on_run = 0.25
        self.assertLessEqual(time_needed - uncertainty_based_on_run,
                             time_needed_detailed)
Esempio n. 8
0
    def test_exposure_compensation(self):
        img = cv.imread("s1.jpg")
        img = increase_brightness(img, value=25)
        cv.imwrite("s1_bright.jpg", img)

        stitcher = Stitcher(compensator="no", blender_type="no")
        result = stitcher.stitch(["s1_bright.jpg", "s2.jpg"])

        cv.imwrite("without_exposure_comp.jpg", result)

        stitcher = Stitcher(blender_type="no")
        result = stitcher.stitch(["s1_bright.jpg", "s2.jpg"])

        cv.imwrite("with_exposure_comp.jpg", result)
parser.add_argument('--output',
                    action='store',
                    default='result.jpg',
                    help="The default is 'result.jpg'",
                    type=str,
                    dest='output')

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

if __name__ == '__main__':
    print(__doc__)
    args = parser.parse_args()
    args_dict = vars(args)

    # Extract In- and Output
    img_names = args_dict.pop("img_names")
    img_names = [cv.samples.findFile(img_name) for img_name in img_names]
    output = args_dict.pop("output")

    stitcher = Stitcher(**args_dict)
    panorama = stitcher.stitch(img_names)

    cv.imwrite(output, panorama)

    zoom_x = 600.0 / panorama.shape[1]
    preview = cv.resize(panorama, dsize=None, fx=zoom_x, fy=zoom_x)

    cv.imshow(output, preview)
    cv.waitKey()
    cv.destroyAllWindows()