Skip to content

Commit

Permalink
Changed getMatrix to use a pointer instead of copying
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Lesches committed Jan 30, 2024
1 parent 7d45e65 commit 2169f64
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/src/camera.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "dart:ffi";
import "dart:typed_data";
import "package:ffi/ffi.dart";

import "exceptions.dart";
Expand Down Expand Up @@ -152,16 +151,11 @@ OpenCVImage? encodeJpg(Pointer<Mat> image, {int quality = 100}) {
return OpenCVImage(pointer: buffer, length: size);
}

/// Converts an [image] with the given [width] and [height] into an OpenCV image.
/// Converts an image with the given [width] and [height] into an OpenCV matrix.
///
/// The matrix must be disposed using [freeMatrix].
Pointer<Mat> getMatrix(int height, int width, Uint8List image) {
final Pointer<Uint8> pointer = arena<Uint8>(image.length);
for (int i = 0; i < image.length; i++) {
pointer[i] = image[i];
}
return nativeLib.Mat_createFrom(height, width, pointer);
}
Pointer<Mat> getMatrix(int height, int width, Pointer<Uint8> bytes) =>
nativeLib.Mat_createFrom(height, width, bytes);

/// Frees memory associated with the given matrix and its underlying image.
void freeMatrix(Pointer<Mat> pointer) => nativeLib.Mat_destroy(pointer);

0 comments on commit 2169f64

Please sign in to comment.