我有一个具有以下签名的C函数
bool sendFrame(int width, int height, int channelNumber, void *data, bool clone);
这里的数据是原始图像。
我的ffi函数签名是:
final int Function(int, int, int, Pointer<Void>, int) rPPGSendFrame = rPPGLib
.lookup<
NativeFunction<
Int32 Function(
Int32, Int32, Int32, Pointer<Void>, Int32)>>("sendFrame")
.asFunction();
( bools必须转换为int,因为bool类型还不支持(对吗?)
我试图用来自照相机流https://pub.dev/documentation/camera/latest/camera/Plane-class.html帧的一个https://pub.dev/documentation/camera/latest/camera/Plane-class.html调用这个方法,但是我不知道如何将我的Uint8List
转换/分配给void *
有什么想法吗?
干杯!
发布于 2019-12-12 23:04:24
我不确定您是否还存在这个问题,但我最近找到了一种将相机数据从图像流api传递到c++的方法。
2020/01/08更新
在这里可以找到一个有用的例子,正在处理中。警告:这里有一个问题正在被调查,https://github.com/flutter/flutter/issues/48360。
初始答案
我的设置:颤振(频道测试版,v1.12.13+hotfix.6)·颤振版本1.12.13+hotfix.6·框架修订版18cd7a3601 (30小时前),2019-12-11 06:35:39-0800·引擎修订版2994f7e1e6·Dart版本2.7.0 ffi版本0.1.3 (https://pub.dev/packages/ffi)
在颤振代码中,使用以下内容准备图像数据:
import "dart:ffi" as ffi;
// 'data' is a Uint8List created by concatenating the planes received from the CameraImage the camera puts out.
// Based on the code found here https://github.com/renancaraujo/bitmap/blob/master/lib/ffi.dart in the execute function
// https://groups.google.com/forum/#!searchin/dart-ffi/list%7Csort:date/dart-ffi/V_6g5hpABec/U9we6UyvBAAJ
final ffi.Pointer<ffi.Uint8> frameData = allocate<ffi.Uint8>(count: data.length); // Allocate a pointer large enough.
final pointerList = frameData.asTypedList(data.length); // Create a list that uses our pointer and copy in the image data.
pointerList.setAll(0, data);
这使用了在allocation.dart
中找到的ffi示例存储库文件。
这是我在颤振中使用的绑定:
final int Function(ffi.Pointer<ffi.Uint8>, int, int, int) cppFunc = dynamicLibrary
.lookup<ffi.NativeFunction<ffi.Int32 Function(ffi.Pointer<ffi.Uint8>, ffi.Int32, ffi.Int32, ffi.Int32)>>("cppFunc")
.asFunction();
c++函数如下所示:
extern "C" {
__attribute__((visibility("default"))) __attribute__((used))
int cppFunc(unsigned char *data, int width, int height, int scanline) {
.
.
.
我不知道这是否会继续工作,因为飞镖:ffi进展到1.0,但我将努力保持这个答案最新。
https://stackoverflow.com/questions/58838193
复制相似问题