From 53a3a31075af54e0ffd362705eb9e3e1540b5653 Mon Sep 17 00:00:00 2001 From: rainyl Date: Mon, 13 May 2024 15:18:24 +0800 Subject: [PATCH] fix: Stitcher.composePanorama --- lib/src/stitching/stitching.dart | 4 ++-- test/stitching_test.dart | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/src/stitching/stitching.dart b/lib/src/stitching/stitching.dart index f79ca0f2..22187281 100644 --- a/lib/src/stitching/stitching.dart +++ b/lib/src/stitching/stitching.dart @@ -153,11 +153,11 @@ class Stitcher extends CvStruct { (StitcherStatus, Mat pano) composePanorama({VecMat? images}) { return using<(StitcherStatus, Mat)>((arena) { final rptr = arena(); - final rpano = arena(); + final rpano = Mat.empty(); images == null ? cvRun(() => CFFI.Stitcher_ComposePanorama(stitcher, rpano.ref, rptr)) : cvRun(() => CFFI.Stitcher_ComposePanorama_1(stitcher, images.ref, rpano.ref, rptr)); - return (StitcherStatus.fromInt(rptr.value), Mat.fromCMat(rpano.ref)); + return (StitcherStatus.fromInt(rptr.value), rpano); }); } diff --git a/test/stitching_test.dart b/test/stitching_test.dart index edec6059..8e505dc4 100644 --- a/test/stitching_test.dart +++ b/test/stitching_test.dart @@ -12,7 +12,7 @@ void main() { final (status, pano) = stitcher.stitch(images.cvd); expect(status, cv.StitcherStatus.OK); expect(pano.isEmpty, false); - cv.imwrite('test/images_out/stitcher_test.jpg', pano); + // cv.imwrite('test/images_out/stitcher_test.jpg', pano); }); test('cv.Stitcher with mask', () { @@ -29,7 +29,7 @@ void main() { final (status, pano) = stitcher.stitch(images.cvd, masks: masks.cvd); expect(status, cv.StitcherStatus.OK); expect(pano.isEmpty, false); - cv.imwrite('test/images_out/stitcher_test_mask.jpg', pano); + // cv.imwrite('test/images_out/stitcher_test_mask.jpg', pano); }); test('cv.Stitcher getter/setter', () { @@ -57,4 +57,26 @@ void main() { expect(stitcher.component.length, greaterThanOrEqualTo(0)); }); + + test('Issue 48', () { + final images = [ + cv.imread("test/images/barcode1.png", flags: cv.IMREAD_COLOR), + cv.imread("test/images/barcode2.png", flags: cv.IMREAD_COLOR), + ]; + + // Create Stitcher object + final cv.Stitcher stitcher = cv.Stitcher.create(); + + // Estimate transformations and stitch images + final cv.StitcherStatus status = stitcher.estimateTransform(images.cvd); + expect(status, cv.StitcherStatus.OK); + + final result = stitcher.composePanorama(); + expect(result.$1, cv.StitcherStatus.OK); + expect(result.$2.isEmpty, false); + + final result1 = stitcher.composePanorama(images: images.cvd); + expect(result1.$1, cv.StitcherStatus.OK); + expect(result1.$2.isEmpty, false); + }); }