libdart_openmvg/README.md
2024-03-13 10:29:23 -07:00

192 lines
5.1 KiB
Markdown

# libdart_openmvg
OpenMVG bindings for dart.
[OpenMVG](https://openmvg.readthedocs.io/) is an AI graphics application that supports
feature detection and surface-from-motion capabilities
If you'd like to contribute, financially, please visit https://ko-fi.com/damngood and
mention "libdart_openmvg" in your message.
## Getting Started
This project is a starting point for a Flutter
[FFI plugin](https://docs.flutter.dev/development/platform-integration/c-interop),
a specialized package that includes native code directly invoked with Dart FFI.
## Building dependencies.
My current project structure is as follows:
```
+- main_project
+- libdart_openmvg (this project)
+- libffmpeg
+- cwalk (git clone https://github.com/likle/cwalk.git)
+- openMVG (git clone https://github.com/openMVG/openMVG.git)
```
The install prefix for openMVG is expected to be `openMVG/build/_install`. I'll
fix this at some point, but I hard-coded it to get the project built.
To build libdart_openmvg...
```
$ mkdir build && cd build
$ cmake -DCMAKE_INSTALL_PREFIX=_install ../src
```
## The C/C++ Bindings
To run cunit tests...
```
$ cd build
$ ./test_image
```
Or to auto-build & run cunit tests...
```
$ # in the libdart_openmvg project root
$ ./scripts/watch_compilelib.sh # in one terminal
$ ./scripts/watch_test.sh # in another terminal
```
Ensure you have the `entr` command installed.
Now anytime you save a `.c/.cxx/.h/CMakeLists.txt` file, the program will be
recompiled and retested.
## The Dart Tests
To run the dart tests ensure that the C bindings are built.
```
$ dart --define=CURRENT_EXEC_DIR="${ROOT_DIR}" test ${TEST_DIR}
```
Or if you want to rerun the tests every time the C or dart files are changed:
```
$ ./scripts/watch_darttest.sh
```
## Project structure
This template uses the following structure:
* `src`: Contains the native source code, and a CmakeFile.txt file for building
that source code into a dynamic library.
* `lib`: Contains the Dart code that defines the API of the plugin, and which
calls into the native code using `dart:ffi`.
* platform folders (`android`, `ios`, `windows`, etc.): Contains the build files
for building and bundling the native code library with the platform application.
## Building and bundling native code
The `pubspec.yaml` specifies FFI plugins as follows:
```yaml
plugin:
platforms:
some_platform:
ffiPlugin: true
```
This configuration invokes the native build for the various target platforms
and bundles the binaries in Flutter applications using these FFI plugins.
This can be combined with dartPluginClass, such as when FFI is used for the
implementation of one platform in a federated plugin:
```yaml
plugin:
implements: some_other_plugin
platforms:
some_platform:
dartPluginClass: SomeClass
ffiPlugin: true
```
A plugin can have both FFI and method channels:
```yaml
plugin:
platforms:
some_platform:
pluginClass: SomeName
ffiPlugin: true
```
The native build systems that are invoked by FFI (and method channel) plugins are:
* For Android: Gradle, which invokes the Android NDK for native builds.
* See the documentation in android/build.gradle.
* For iOS and MacOS: Xcode, via CocoaPods.
* See the documentation in ios/archimedes_mobile_lib.podspec.
* See the documentation in macos/archimedes_mobile_lib.podspec.
* For Linux and Windows: CMake.
* See the documentation in linux/CMakeLists.txt.
* See the documentation in windows/CMakeLists.txt.
## Binding to native code
To use the native code, bindings in Dart are needed.
To avoid writing these by hand, they are generated from the header file
(`src/archimedes_mobile_lib.h`) by `package:ffigen`.
Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`.
## Invoking native code
Very short-running native functions can be directly invoked from any isolate.
For example, see `sum` in `lib/archimedes_mobile_lib.dart`.
Longer-running functions should be invoked on a helper isolate to avoid
dropping frames in Flutter applications.
For example, see `sumAsync` in `lib/archimedes_mobile_lib.dart`.
## Flutter help
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
# Developer Notes
You'll get an error with Eiger, so watch out.
```
$ make
finition.hpp:17:10: fatal error: Eigen/Dense: No such file or directory
17 | #include <Eigen/Dense>
| ^~~~~~~~~~~~~
compilation terminated.
```
```shell
$ sudo at install -y libeigen3-dev
$ sudo ln -sf /usr/include/eigen3/Eigen /usr/include/Eigen
```
git clone --single-branch --branch n6.1 https://git.ffmpeg.org/ffmpeg.git
Can I expose `FILE` in dart?
Yea...no! https://github.com/dart-lang/sdk/issues/4160
Instead, I'll have to load the data in directly.
buliding open mvg needs to be done with the PIC flag
```shell
$ cmake ../src -DCMAKE_INSTALL_PREFIX="../../openMVG/build/_install" -DCMAKE_POSITION_INDEPENDENT_CODE=ON
```
A good SFM example (that I'm basically ripping from) can be found here:
./openMVG/src/software/SfM/main_SfM.cpp