cropIdCard static method
rgbaBytes is the source frame's RGBA buffer (any width/height).
Returns a tightly-packed RGBA buffer of size
idCardOutputWidth * idCardOutputHeight * 4, or null if no card
was detected.
Implementation
static Uint8List? cropIdCard(Uint8List rgbaBytes, int width, int height) {
final outWidth = idCardOutputWidth;
final outHeight = idCardOutputHeight;
final outputLength = outWidth * outHeight * 4;
final Pointer<Uint8> inputPointer = malloc<Uint8>(rgbaBytes.length);
final Pointer<Uint8> outputPointer = malloc<Uint8>(outputLength);
try {
inputPointer.asTypedList(rgbaBytes.length).setAll(0, rgbaBytes);
final bool success = _cropIdCard(
inputPointer,
width,
height,
outputPointer,
);
if (!success) {
return null;
}
return Uint8List.fromList(outputPointer.asTypedList(outputLength));
} finally {
malloc.free(inputPointer);
malloc.free(outputPointer);
}
}