I am trying to send an image to my Custom C++ code which I am planning to run using dart:ffi. I have successfully run the hello world problem where I send two integers and get the some of them as another intiger.
Now I want to send a whole image to it and process it on my C++ code. I am able to get Uint8List from the CameraImage using the below code
Future<ui.Image> convertCameraImageToUiImage(CameraImage image) async {
imglib.Image libImage = imglib.Image.fromBytes(
image.width,
image.height,
image.planes[0].bytes,
format: imglib.Format.bgra,
);
final c = Completer<ui.Image>();
ui.decodeImageFromPixels(
libImage.getBytes(),
image.width,
image.height,
ui.PixelFormat.rgba8888,
c.complete,
);
return c.future;
}
Then I converted it to Uint8List
ByteData data = await image.toByteData();
Uint8List bytes = data.buffer.asUint8List();
My problem is, how should I define lookup function to send a Uint8List to the C++ code and get List<bool>, my function over C++ expects cv::mat (I can tweak it to receive array of integers) as a parameter and sends a Vector of boolean.
This is what I have tried
final List<bool> Function(Uint8List image) _imageToCode = nativeAddLib
.lookup<NativeFunction<List<bool> Function(List<Uint8List>)>>("imageToCode")
.asFunction();
The problem is, the bool and Uint8List are not a type supported by C++ so the function doesn't recognize them. How should I send it over the channel.