Skip to content

fix Mat.size is not correct #170 #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/src/core/mat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,13 @@ class Mat extends CvStruct<cvg.Mat> {
return p.value;
});

/// ([rows], [cols])
List<int> get size => [rows, cols];

// List<int> get shape {
// return cvRunArena<List<int>>((arena) {
// final s = arena<cvg.VecI32>();
// cvRun(() => cffiCore.Mat_Size(ref, s));
// final vec = VecI32.fromPointer(s.value);
// return vec.toList();
// });
// }
/// Mat.size
VecI32 get size {
final p = calloc<cvg.VecI32>();
cvRun(() => ccore.Mat_Size(ref, p));
final vec = VecI32.fromPointer(p);
return vec;
}

/// ([rows], [cols], [channels])
List<int> get shape => [rows, cols, channels];
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ CvStatus *Mat_Size(Mat m, VecI32 *rval) {
BEGIN_WRAP
auto size = m.ptr->size;
int *ptr = new int[size.dims()];
memcpy(ptr, size.p, size.dims());
memcpy(ptr, size.p, size.dims() * sizeof(int));
*rval = {ptr, static_cast<size_t>(size.dims())};
END_WRAP
}
Expand Down
2 changes: 2 additions & 0 deletions test/imgcodecs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ void main() async {
final cvImage = cv.imread("test/images/circles.jpg", flags: cv.IMREAD_COLOR);
expect((cvImage.width, cvImage.height), (512, 512));
final (success, buf) = cv.imencode(".png", cvImage);
expect(success, true);
expect(buf.length, greaterThan(0));
await File("test/images_out/test_imencode.png").writeAsBytes(buf);
final params = [cv.IMWRITE_PNG_COMPRESSION, 9].i32;
final (success1, buf1) = cv.imencode(".png", cvImage, params: params);
expect(success1, true);
expect(buf1.length, greaterThan(0));

final cvimgDecode = cv.imdecode(buf, cv.IMREAD_COLOR);
Expand Down
Loading