Skip to content

Async photo & stitching #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ headers:
- src/objdetect/objdetect.h
- src/objdetect/objdetect_async.h
- src/photo/photo.h
- src/photo/photo_async.h
- src/stitching/stitching.h
- src/stitching/stitching_async.h
- src/video/video.h
- src/video/videoio.h
include-directives:
Expand Down Expand Up @@ -69,7 +71,9 @@ headers:
- src/objdetect/objdetect.h
- src/objdetect/objdetect_async.h
- src/photo/photo.h
- src/photo/photo_async.h
- src/stitching/stitching.h
- src/stitching/stitching_async.h
- src/video/video.h
- src/video/videoio.h
functions:
Expand Down
2 changes: 2 additions & 0 deletions lib/opencv_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export 'src/imgproc/subdiv2d_async.dart';
export 'src/objdetect/objdetect.dart';
export 'src/objdetect/objdetect_async.dart';
export 'src/photo/photo.dart';
export 'src/photo/photo_async.dart';
export 'src/stitching/stitching.dart';
export 'src/stitching/stitching_async.dart';
export 'src/svd/svd.dart';
export 'src/video/video.dart';
export 'src/video/videoio.dart';
31 changes: 27 additions & 4 deletions lib/src/core/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ ffi.DynamicLibrary loadNativeLibrary() {
"windows" => "$_libraryName.dll",
"linux" || "android" || "fuchsia" => "lib$_libraryName.so",
"macos" => "lib$_libraryName.dylib",
_ => throw UnsupportedError("Platform ${Platform.operatingSystem} not supported")
_ => throw UnsupportedError(
"Platform ${Platform.operatingSystem} not supported",
)
};
final libPath = Platform.environment["OPENCV_DART_LIB_PATH"] ?? defaultLibPath;
return ffi.DynamicLibrary.open(libPath);
Expand Down Expand Up @@ -152,7 +154,13 @@ Future<T> cvRunAsync3<T>(

Future<T> cvRunAsync4<T>(
ffi.Pointer<cvg.CvStatus> Function(cvg.CvCallback_4 callback) func,
void Function(Completer<T> completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3) onComplete,
void Function(
Completer<T> completer,
VoidPtr p,
VoidPtr p1,
VoidPtr p2,
VoidPtr p3,
) onComplete,
) {
final completer = Completer<T>();
late final NativeCallable<cvg.CvCallback_4Function> ccallback;
Expand All @@ -168,7 +176,14 @@ Future<T> cvRunAsync4<T>(

Future<T> cvRunAsync5<T>(
ffi.Pointer<cvg.CvStatus> Function(cvg.CvCallback_5 callback) func,
void Function(Completer<T> completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3, VoidPtr p4) onComplete,
void Function(
Completer<T> completer,
VoidPtr p,
VoidPtr p1,
VoidPtr p2,
VoidPtr p3,
VoidPtr p4,
) onComplete,
) {
final completer = Completer<T>();
late final NativeCallable<cvg.CvCallback_5Function> ccallback;
Expand All @@ -189,6 +204,12 @@ void intCompleter(Completer<int> completer, VoidPtr p) {
completer.complete(value);
}

void boolCompleter(Completer<bool> completer, VoidPtr p) {
final value = p.cast<ffi.Bool>().value;
calloc.free(p);
completer.complete(value);
}

void doubleCompleter(Completer<double> completer, VoidPtr p) {
final value = p.cast<ffi.Double>().value;
calloc.free(p);
Expand Down Expand Up @@ -227,7 +248,9 @@ R cvRunArena<R>(
typedef NativeFinalizerFunctionT<T extends ffi.NativeType>
= ffi.Pointer<ffi.NativeFunction<ffi.Void Function(T token)>>;

ffi.NativeFinalizer OcvFinalizer<T extends ffi.NativeType>(NativeFinalizerFunctionT<T> func) =>
ffi.NativeFinalizer OcvFinalizer<T extends ffi.NativeType>(
NativeFinalizerFunctionT<T> func,
) =>
ffi.NativeFinalizer(func.cast<ffi.NativeFinalizerFunction>());

// native types
Expand Down
Loading
Loading