50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
import 'dart:ffi' as ffi;
|
|
import 'dart:io';
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
// C function signatures
|
|
typedef _CVersionFunc = ffi.Pointer<Utf8> Function();
|
|
typedef _CProcessImageFunc = ffi.Void Function(
|
|
ffi.Pointer<Utf8>, ffi.Pointer<Utf8>, ffi.Double);
|
|
|
|
// Dart function signatures
|
|
typedef _VersionFunc = ffi.Pointer<Utf8> Function();
|
|
typedef _ProcessImageFunc = void Function(
|
|
ffi.Pointer<Utf8>, ffi.Pointer<Utf8>, double);
|
|
|
|
// Getting a library that holds needed symbols
|
|
ffi.DynamicLibrary _openDynamicLibrary() {
|
|
if (Platform.isAndroid) {
|
|
return ffi.DynamicLibrary.open('libnative_opencv.so');
|
|
} else if (Platform.isWindows) {
|
|
return ffi.DynamicLibrary.open("native_opencv_windows_plugin.dll");
|
|
}
|
|
|
|
return ffi.DynamicLibrary.process();
|
|
}
|
|
|
|
ffi.DynamicLibrary _lib = _openDynamicLibrary();
|
|
|
|
// Looking for the functions
|
|
final _VersionFunc _version =
|
|
_lib.lookup<ffi.NativeFunction<_CVersionFunc>>('version').asFunction();
|
|
final _ProcessImageFunc _processImage = _lib
|
|
.lookup<ffi.NativeFunction<_CProcessImageFunc>>('process_image')
|
|
.asFunction();
|
|
|
|
String opencvVersion() {
|
|
return _version().toDartString();
|
|
}
|
|
|
|
void processImage(ProcessImageArguments args) {
|
|
_processImage(args.inputPath.toNativeUtf8(), args.outputPath.toNativeUtf8(),
|
|
args.frameRate);
|
|
}
|
|
|
|
class ProcessImageArguments {
|
|
final String inputPath;
|
|
final String outputPath;
|
|
final double frameRate;
|
|
ProcessImageArguments(this.inputPath, this.outputPath, this.frameRate);
|
|
}
|