@nitro-mlkit/object-detection 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/NitroMLKitObjects.podspec +34 -0
  3. package/README.md +57 -0
  4. package/android/CMakeLists.txt +12 -0
  5. package/android/build.gradle +77 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  8. package/android/src/main/kotlin/com/margelo/nitro/nitromlkit/objects/HybridObjectDetector.kt +102 -0
  9. package/android/src/main/kotlin/com/nitromlkit/objects/NitroMLKitObjectsPackage.kt +19 -0
  10. package/expo-module.config.json +9 -0
  11. package/ios/HybridObjectDetector.swift +125 -0
  12. package/nitro.json +16 -0
  13. package/nitrogen/generated/.gitattributes +1 -0
  14. package/nitrogen/generated/android/NitroMLKitObjects+autolinking.cmake +81 -0
  15. package/nitrogen/generated/android/NitroMLKitObjects+autolinking.gradle +27 -0
  16. package/nitrogen/generated/android/NitroMLKitObjectsOnLoad.cpp +54 -0
  17. package/nitrogen/generated/android/NitroMLKitObjectsOnLoad.hpp +34 -0
  18. package/nitrogen/generated/android/c++/JBatchObjectResult.hpp +95 -0
  19. package/nitrogen/generated/android/c++/JDetectedObject.hpp +88 -0
  20. package/nitrogen/generated/android/c++/JHybridObjectDetectorSpec.cpp +131 -0
  21. package/nitrogen/generated/android/c++/JHybridObjectDetectorSpec.hpp +65 -0
  22. package/nitrogen/generated/android/c++/JObjectLabel.hpp +65 -0
  23. package/nitrogen/generated/android/c++/JObjectRect.hpp +69 -0
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/BatchObjectResult.kt +66 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/DetectedObject.kt +61 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/HybridObjectDetectorSpec.kt +63 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/NitroMLKitObjectsOnLoad.kt +35 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/ObjectLabel.kt +61 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/ObjectRect.kt +66 -0
  30. package/nitrogen/generated/ios/NitroMLKitObjects+autolinking.rb +62 -0
  31. package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Bridge.cpp +57 -0
  32. package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Bridge.hpp +236 -0
  33. package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Umbrella.hpp +59 -0
  34. package/nitrogen/generated/ios/NitroMLKitObjectsAutolinking.mm +33 -0
  35. package/nitrogen/generated/ios/NitroMLKitObjectsAutolinking.swift +26 -0
  36. package/nitrogen/generated/ios/c++/HybridObjectDetectorSpecSwift.cpp +11 -0
  37. package/nitrogen/generated/ios/c++/HybridObjectDetectorSpecSwift.hpp +112 -0
  38. package/nitrogen/generated/ios/swift/BatchObjectResult.swift +63 -0
  39. package/nitrogen/generated/ios/swift/DetectedObject.swift +45 -0
  40. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  41. package/nitrogen/generated/ios/swift/Func_void_std__vector_BatchObjectResult_.swift +46 -0
  42. package/nitrogen/generated/ios/swift/Func_void_std__vector_DetectedObject_.swift +46 -0
  43. package/nitrogen/generated/ios/swift/HybridObjectDetectorSpec.swift +57 -0
  44. package/nitrogen/generated/ios/swift/HybridObjectDetectorSpec_cxx.swift +188 -0
  45. package/nitrogen/generated/ios/swift/ObjectLabel.swift +39 -0
  46. package/nitrogen/generated/ios/swift/ObjectRect.swift +44 -0
  47. package/nitrogen/generated/shared/c++/BatchObjectResult.hpp +99 -0
  48. package/nitrogen/generated/shared/c++/DetectedObject.hpp +96 -0
  49. package/nitrogen/generated/shared/c++/HybridObjectDetectorSpec.cpp +23 -0
  50. package/nitrogen/generated/shared/c++/HybridObjectDetectorSpec.hpp +71 -0
  51. package/nitrogen/generated/shared/c++/ObjectLabel.hpp +91 -0
  52. package/nitrogen/generated/shared/c++/ObjectRect.hpp +95 -0
  53. package/package.json +53 -0
  54. package/src/index.ts +20 -0
  55. package/src/specs/ObjectDetector.nitro.ts +54 -0
@@ -0,0 +1,34 @@
1
+ ///
2
+ /// NitroMLKitObjectsOnLoad.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include <jni.h>
9
+ #include <functional>
10
+ #include <NitroModules/NitroDefines.hpp>
11
+
12
+ namespace margelo::nitro::mlkit::objects {
13
+
14
+ [[deprecated("Use registerNatives() instead.")]]
15
+ int initialize(JavaVM* vm);
16
+
17
+ /**
18
+ * Register the native (C++) part of NitroMLKitObjects, and autolinks all Hybrid Objects.
19
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
20
+ * inside a `facebook::jni::initialize(vm, ...)` call.
21
+ * Example:
22
+ * ```cpp (cpp-adapter.cpp)
23
+ * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
24
+ * return facebook::jni::initialize(vm, []() {
25
+ * // register all NitroMLKitObjects HybridObjects
26
+ * margelo::nitro::mlkit::objects::registerNatives();
27
+ * // any other custom registrations go here.
28
+ * });
29
+ * }
30
+ * ```
31
+ */
32
+ void registerAllNatives();
33
+
34
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,95 @@
1
+ ///
2
+ /// JBatchObjectResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "BatchObjectResult.hpp"
12
+
13
+ #include "DetectedObject.hpp"
14
+ #include "JDetectedObject.hpp"
15
+ #include "JObjectLabel.hpp"
16
+ #include "JObjectRect.hpp"
17
+ #include "ObjectLabel.hpp"
18
+ #include "ObjectRect.hpp"
19
+ #include <optional>
20
+ #include <string>
21
+ #include <vector>
22
+
23
+ namespace margelo::nitro::mlkit::objects {
24
+
25
+ using namespace facebook;
26
+
27
+ /**
28
+ * The C++ JNI bridge between the C++ struct "BatchObjectResult" and the Kotlin data class "BatchObjectResult".
29
+ */
30
+ struct JBatchObjectResult final: public jni::JavaClass<JBatchObjectResult> {
31
+ public:
32
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/objects/BatchObjectResult;";
33
+
34
+ public:
35
+ /**
36
+ * Convert this Java/Kotlin-based struct to the C++ struct BatchObjectResult by copying all values to C++.
37
+ */
38
+ [[maybe_unused]]
39
+ [[nodiscard]]
40
+ BatchObjectResult toCpp() const {
41
+ static const auto clazz = javaClassStatic();
42
+ static const auto fieldIndex = clazz->getField<double>("index");
43
+ double index = this->getFieldValue(fieldIndex);
44
+ static const auto fieldObjects = clazz->getField<jni::JArrayClass<JDetectedObject>>("objects");
45
+ jni::local_ref<jni::JArrayClass<JDetectedObject>> objects = this->getFieldValue(fieldObjects);
46
+ static const auto fieldSuccess = clazz->getField<jboolean>("success");
47
+ jboolean success = this->getFieldValue(fieldSuccess);
48
+ static const auto fieldError = clazz->getField<jni::JString>("error");
49
+ jni::local_ref<jni::JString> error = this->getFieldValue(fieldError);
50
+ return BatchObjectResult(
51
+ index,
52
+ [&](auto&& __input) {
53
+ size_t __size = __input->size();
54
+ std::vector<DetectedObject> __vector;
55
+ __vector.reserve(__size);
56
+ for (size_t __i = 0; __i < __size; __i++) {
57
+ auto __element = __input->getElement(__i);
58
+ __vector.push_back(__element->toCpp());
59
+ }
60
+ return __vector;
61
+ }(objects),
62
+ static_cast<bool>(success),
63
+ error != nullptr ? std::make_optional(error->toStdString()) : std::nullopt
64
+ );
65
+ }
66
+
67
+ public:
68
+ /**
69
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
70
+ */
71
+ [[maybe_unused]]
72
+ static jni::local_ref<JBatchObjectResult::javaobject> fromCpp(const BatchObjectResult& value) {
73
+ using JSignature = JBatchObjectResult(double, jni::alias_ref<jni::JArrayClass<JDetectedObject>>, jboolean, jni::alias_ref<jni::JString>);
74
+ static const auto clazz = javaClassStatic();
75
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
76
+ return create(
77
+ clazz,
78
+ value.index,
79
+ [&](auto&& __input) {
80
+ size_t __size = __input.size();
81
+ jni::local_ref<jni::JArrayClass<JDetectedObject>> __array = jni::JArrayClass<JDetectedObject>::newArray(__size);
82
+ for (size_t __i = 0; __i < __size; __i++) {
83
+ const auto& __element = __input[__i];
84
+ auto __elementJni = JDetectedObject::fromCpp(__element);
85
+ __array->setElement(__i, *__elementJni);
86
+ }
87
+ return __array;
88
+ }(value.objects),
89
+ value.success,
90
+ value.error.has_value() ? jni::make_jstring(value.error.value()) : nullptr
91
+ );
92
+ }
93
+ };
94
+
95
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,88 @@
1
+ ///
2
+ /// JDetectedObject.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "DetectedObject.hpp"
12
+
13
+ #include "JObjectLabel.hpp"
14
+ #include "JObjectRect.hpp"
15
+ #include "ObjectLabel.hpp"
16
+ #include "ObjectRect.hpp"
17
+ #include <string>
18
+ #include <vector>
19
+
20
+ namespace margelo::nitro::mlkit::objects {
21
+
22
+ using namespace facebook;
23
+
24
+ /**
25
+ * The C++ JNI bridge between the C++ struct "DetectedObject" and the Kotlin data class "DetectedObject".
26
+ */
27
+ struct JDetectedObject final: public jni::JavaClass<JDetectedObject> {
28
+ public:
29
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/objects/DetectedObject;";
30
+
31
+ public:
32
+ /**
33
+ * Convert this Java/Kotlin-based struct to the C++ struct DetectedObject by copying all values to C++.
34
+ */
35
+ [[maybe_unused]]
36
+ [[nodiscard]]
37
+ DetectedObject toCpp() const {
38
+ static const auto clazz = javaClassStatic();
39
+ static const auto fieldBounds = clazz->getField<JObjectRect>("bounds");
40
+ jni::local_ref<JObjectRect> bounds = this->getFieldValue(fieldBounds);
41
+ static const auto fieldTrackingId = clazz->getField<double>("trackingId");
42
+ double trackingId = this->getFieldValue(fieldTrackingId);
43
+ static const auto fieldLabels = clazz->getField<jni::JArrayClass<JObjectLabel>>("labels");
44
+ jni::local_ref<jni::JArrayClass<JObjectLabel>> labels = this->getFieldValue(fieldLabels);
45
+ return DetectedObject(
46
+ bounds->toCpp(),
47
+ trackingId,
48
+ [&](auto&& __input) {
49
+ size_t __size = __input->size();
50
+ std::vector<ObjectLabel> __vector;
51
+ __vector.reserve(__size);
52
+ for (size_t __i = 0; __i < __size; __i++) {
53
+ auto __element = __input->getElement(__i);
54
+ __vector.push_back(__element->toCpp());
55
+ }
56
+ return __vector;
57
+ }(labels)
58
+ );
59
+ }
60
+
61
+ public:
62
+ /**
63
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
64
+ */
65
+ [[maybe_unused]]
66
+ static jni::local_ref<JDetectedObject::javaobject> fromCpp(const DetectedObject& value) {
67
+ using JSignature = JDetectedObject(jni::alias_ref<JObjectRect>, double, jni::alias_ref<jni::JArrayClass<JObjectLabel>>);
68
+ static const auto clazz = javaClassStatic();
69
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
70
+ return create(
71
+ clazz,
72
+ JObjectRect::fromCpp(value.bounds),
73
+ value.trackingId,
74
+ [&](auto&& __input) {
75
+ size_t __size = __input.size();
76
+ jni::local_ref<jni::JArrayClass<JObjectLabel>> __array = jni::JArrayClass<JObjectLabel>::newArray(__size);
77
+ for (size_t __i = 0; __i < __size; __i++) {
78
+ const auto& __element = __input[__i];
79
+ auto __elementJni = JObjectLabel::fromCpp(__element);
80
+ __array->setElement(__i, *__elementJni);
81
+ }
82
+ return __array;
83
+ }(value.labels)
84
+ );
85
+ }
86
+ };
87
+
88
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,131 @@
1
+ ///
2
+ /// JHybridObjectDetectorSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "JHybridObjectDetectorSpec.hpp"
9
+
10
+ // Forward declaration of `DetectedObject` to properly resolve imports.
11
+ namespace margelo::nitro::mlkit::objects { struct DetectedObject; }
12
+ // Forward declaration of `ObjectRect` to properly resolve imports.
13
+ namespace margelo::nitro::mlkit::objects { struct ObjectRect; }
14
+ // Forward declaration of `ObjectLabel` to properly resolve imports.
15
+ namespace margelo::nitro::mlkit::objects { struct ObjectLabel; }
16
+ // Forward declaration of `BatchObjectResult` to properly resolve imports.
17
+ namespace margelo::nitro::mlkit::objects { struct BatchObjectResult; }
18
+
19
+ #include "DetectedObject.hpp"
20
+ #include <vector>
21
+ #include <NitroModules/Promise.hpp>
22
+ #include <NitroModules/JPromise.hpp>
23
+ #include "JDetectedObject.hpp"
24
+ #include "ObjectRect.hpp"
25
+ #include "JObjectRect.hpp"
26
+ #include "ObjectLabel.hpp"
27
+ #include "JObjectLabel.hpp"
28
+ #include <string>
29
+ #include "BatchObjectResult.hpp"
30
+ #include "JBatchObjectResult.hpp"
31
+ #include <optional>
32
+
33
+ namespace margelo::nitro::mlkit::objects {
34
+
35
+ std::shared_ptr<JHybridObjectDetectorSpec> JHybridObjectDetectorSpec::JavaPart::getJHybridObjectDetectorSpec() {
36
+ auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
37
+ auto castHybridObject = std::dynamic_pointer_cast<JHybridObjectDetectorSpec>(hybridObject);
38
+ if (castHybridObject == nullptr) [[unlikely]] {
39
+ throw std::runtime_error("Failed to downcast JHybridObject to JHybridObjectDetectorSpec!");
40
+ }
41
+ return castHybridObject;
42
+ }
43
+
44
+ jni::local_ref<JHybridObjectDetectorSpec::CxxPart::jhybriddata> JHybridObjectDetectorSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
45
+ return makeCxxInstance(jThis);
46
+ }
47
+
48
+ std::shared_ptr<JHybridObject> JHybridObjectDetectorSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
49
+ auto castJavaPart = jni::dynamic_ref_cast<JHybridObjectDetectorSpec::JavaPart>(javaPart);
50
+ if (castJavaPart == nullptr) [[unlikely]] {
51
+ throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridObjectDetectorSpec::JavaPart!");
52
+ }
53
+ return std::make_shared<JHybridObjectDetectorSpec>(castJavaPart);
54
+ }
55
+
56
+ void JHybridObjectDetectorSpec::CxxPart::registerNatives() {
57
+ registerHybrid({
58
+ makeNativeMethod("initHybrid", JHybridObjectDetectorSpec::CxxPart::initHybrid),
59
+ });
60
+ }
61
+
62
+ // Properties
63
+
64
+
65
+ // Methods
66
+ std::shared_ptr<Promise<std::vector<DetectedObject>>> JHybridObjectDetectorSpec::detect(const std::string& imageUri) {
67
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* imageUri */)>("detect");
68
+ auto __result = method(_javaPart, jni::make_jstring(imageUri));
69
+ return [&]() {
70
+ auto __promise = Promise<std::vector<DetectedObject>>::create();
71
+ __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
72
+ auto __result = jni::static_ref_cast<jni::JArrayClass<JDetectedObject>>(__boxedResult);
73
+ __promise->resolve([&](auto&& __input) {
74
+ size_t __size = __input->size();
75
+ std::vector<DetectedObject> __vector;
76
+ __vector.reserve(__size);
77
+ for (size_t __i = 0; __i < __size; __i++) {
78
+ auto __element = __input->getElement(__i);
79
+ __vector.push_back(__element->toCpp());
80
+ }
81
+ return __vector;
82
+ }(__result));
83
+ });
84
+ __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
85
+ jni::JniException __jniError(__throwable);
86
+ __promise->reject(std::make_exception_ptr(__jniError));
87
+ });
88
+ return __promise;
89
+ }();
90
+ }
91
+ std::shared_ptr<Promise<std::vector<BatchObjectResult>>> JHybridObjectDetectorSpec::detectBatch(const std::vector<std::string>& imageUris, double concurrency) {
92
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JArrayClass<jni::JString>> /* imageUris */, double /* concurrency */)>("detectBatch");
93
+ auto __result = method(_javaPart, [&](auto&& __input) {
94
+ size_t __size = __input.size();
95
+ jni::local_ref<jni::JArrayClass<jni::JString>> __array = jni::JArrayClass<jni::JString>::newArray(__size);
96
+ for (size_t __i = 0; __i < __size; __i++) {
97
+ const auto& __element = __input[__i];
98
+ auto __elementJni = jni::make_jstring(__element);
99
+ __array->setElement(__i, *__elementJni);
100
+ }
101
+ return __array;
102
+ }(imageUris), concurrency);
103
+ return [&]() {
104
+ auto __promise = Promise<std::vector<BatchObjectResult>>::create();
105
+ __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
106
+ auto __result = jni::static_ref_cast<jni::JArrayClass<JBatchObjectResult>>(__boxedResult);
107
+ __promise->resolve([&](auto&& __input) {
108
+ size_t __size = __input->size();
109
+ std::vector<BatchObjectResult> __vector;
110
+ __vector.reserve(__size);
111
+ for (size_t __i = 0; __i < __size; __i++) {
112
+ auto __element = __input->getElement(__i);
113
+ __vector.push_back(__element->toCpp());
114
+ }
115
+ return __vector;
116
+ }(__result));
117
+ });
118
+ __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
119
+ jni::JniException __jniError(__throwable);
120
+ __promise->reject(std::make_exception_ptr(__jniError));
121
+ });
122
+ return __promise;
123
+ }();
124
+ }
125
+ bool JHybridObjectDetectorSpec::isAvailable() {
126
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isAvailable");
127
+ auto __result = method(_javaPart);
128
+ return static_cast<bool>(__result);
129
+ }
130
+
131
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// HybridObjectDetectorSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <NitroModules/JHybridObject.hpp>
11
+ #include <fbjni/fbjni.h>
12
+ #include "HybridObjectDetectorSpec.hpp"
13
+
14
+
15
+
16
+
17
+ namespace margelo::nitro::mlkit::objects {
18
+
19
+ using namespace facebook;
20
+
21
+ class JHybridObjectDetectorSpec: public virtual HybridObjectDetectorSpec, public virtual JHybridObject {
22
+ public:
23
+ struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/objects/HybridObjectDetectorSpec;";
25
+ std::shared_ptr<JHybridObjectDetectorSpec> getJHybridObjectDetectorSpec();
26
+ };
27
+ struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/objects/HybridObjectDetectorSpec$CxxPart;";
29
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
30
+ static void registerNatives();
31
+ using HybridBase::HybridBase;
32
+ protected:
33
+ std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
34
+ };
35
+
36
+ public:
37
+ explicit JHybridObjectDetectorSpec(const jni::local_ref<JHybridObjectDetectorSpec::JavaPart>& javaPart):
38
+ HybridObject(HybridObjectDetectorSpec::TAG),
39
+ JHybridObject(javaPart),
40
+ _javaPart(jni::make_global(javaPart)) {}
41
+ ~JHybridObjectDetectorSpec() override {
42
+ // Hermes GC can destroy JS objects on a non-JNI Thread.
43
+ jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
44
+ }
45
+
46
+ public:
47
+ inline const jni::global_ref<JHybridObjectDetectorSpec::JavaPart>& getJavaPart() const noexcept {
48
+ return _javaPart;
49
+ }
50
+
51
+ public:
52
+ // Properties
53
+
54
+
55
+ public:
56
+ // Methods
57
+ std::shared_ptr<Promise<std::vector<DetectedObject>>> detect(const std::string& imageUri) override;
58
+ std::shared_ptr<Promise<std::vector<BatchObjectResult>>> detectBatch(const std::vector<std::string>& imageUris, double concurrency) override;
59
+ bool isAvailable() override;
60
+
61
+ private:
62
+ jni::global_ref<JHybridObjectDetectorSpec::JavaPart> _javaPart;
63
+ };
64
+
65
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,65 @@
1
+ ///
2
+ /// JObjectLabel.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "ObjectLabel.hpp"
12
+
13
+ #include <string>
14
+
15
+ namespace margelo::nitro::mlkit::objects {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "ObjectLabel" and the Kotlin data class "ObjectLabel".
21
+ */
22
+ struct JObjectLabel final: public jni::JavaClass<JObjectLabel> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/objects/ObjectLabel;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct ObjectLabel by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ ObjectLabel toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldText = clazz->getField<jni::JString>("text");
35
+ jni::local_ref<jni::JString> text = this->getFieldValue(fieldText);
36
+ static const auto fieldConfidence = clazz->getField<double>("confidence");
37
+ double confidence = this->getFieldValue(fieldConfidence);
38
+ static const auto fieldIndex = clazz->getField<double>("index");
39
+ double index = this->getFieldValue(fieldIndex);
40
+ return ObjectLabel(
41
+ text->toStdString(),
42
+ confidence,
43
+ index
44
+ );
45
+ }
46
+
47
+ public:
48
+ /**
49
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
50
+ */
51
+ [[maybe_unused]]
52
+ static jni::local_ref<JObjectLabel::javaobject> fromCpp(const ObjectLabel& value) {
53
+ using JSignature = JObjectLabel(jni::alias_ref<jni::JString>, double, double);
54
+ static const auto clazz = javaClassStatic();
55
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
56
+ return create(
57
+ clazz,
58
+ jni::make_jstring(value.text),
59
+ value.confidence,
60
+ value.index
61
+ );
62
+ }
63
+ };
64
+
65
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,69 @@
1
+ ///
2
+ /// JObjectRect.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "ObjectRect.hpp"
12
+
13
+
14
+
15
+ namespace margelo::nitro::mlkit::objects {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "ObjectRect" and the Kotlin data class "ObjectRect".
21
+ */
22
+ struct JObjectRect final: public jni::JavaClass<JObjectRect> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitromlkit/objects/ObjectRect;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct ObjectRect by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ ObjectRect toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldX = clazz->getField<double>("x");
35
+ double x = this->getFieldValue(fieldX);
36
+ static const auto fieldY = clazz->getField<double>("y");
37
+ double y = this->getFieldValue(fieldY);
38
+ static const auto fieldWidth = clazz->getField<double>("width");
39
+ double width = this->getFieldValue(fieldWidth);
40
+ static const auto fieldHeight = clazz->getField<double>("height");
41
+ double height = this->getFieldValue(fieldHeight);
42
+ return ObjectRect(
43
+ x,
44
+ y,
45
+ width,
46
+ height
47
+ );
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
53
+ */
54
+ [[maybe_unused]]
55
+ static jni::local_ref<JObjectRect::javaobject> fromCpp(const ObjectRect& value) {
56
+ using JSignature = JObjectRect(double, double, double, double);
57
+ static const auto clazz = javaClassStatic();
58
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
59
+ return create(
60
+ clazz,
61
+ value.x,
62
+ value.y,
63
+ value.width,
64
+ value.height
65
+ );
66
+ }
67
+ };
68
+
69
+ } // namespace margelo::nitro::mlkit::objects
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// BatchObjectResult.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.nitromlkit.objects
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "BatchObjectResult".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class BatchObjectResult(
21
+ @DoNotStrip
22
+ @Keep
23
+ val index: Double,
24
+ @DoNotStrip
25
+ @Keep
26
+ val objects: Array<DetectedObject>,
27
+ @DoNotStrip
28
+ @Keep
29
+ val success: Boolean,
30
+ @DoNotStrip
31
+ @Keep
32
+ val error: String?
33
+ ) {
34
+ /* primary constructor */
35
+
36
+ override fun equals(other: Any?): Boolean {
37
+ if (this === other) return true
38
+ if (other !is BatchObjectResult) return false
39
+ return Objects.deepEquals(this.index, other.index)
40
+ && Objects.deepEquals(this.objects, other.objects)
41
+ && Objects.deepEquals(this.success, other.success)
42
+ && Objects.deepEquals(this.error, other.error)
43
+ }
44
+
45
+ override fun hashCode(): Int {
46
+ return arrayOf<Any?>(
47
+ index,
48
+ objects,
49
+ success,
50
+ error
51
+ ).contentDeepHashCode()
52
+ }
53
+
54
+ companion object {
55
+ /**
56
+ * Constructor called from C++
57
+ */
58
+ @DoNotStrip
59
+ @Keep
60
+ @Suppress("unused")
61
+ @JvmStatic
62
+ private fun fromCpp(index: Double, objects: Array<DetectedObject>, success: Boolean, error: String?): BatchObjectResult {
63
+ return BatchObjectResult(index, objects, success, error)
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// DetectedObject.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.nitromlkit.objects
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "DetectedObject".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class DetectedObject(
21
+ @DoNotStrip
22
+ @Keep
23
+ val bounds: ObjectRect,
24
+ @DoNotStrip
25
+ @Keep
26
+ val trackingId: Double,
27
+ @DoNotStrip
28
+ @Keep
29
+ val labels: Array<ObjectLabel>
30
+ ) {
31
+ /* primary constructor */
32
+
33
+ override fun equals(other: Any?): Boolean {
34
+ if (this === other) return true
35
+ if (other !is DetectedObject) return false
36
+ return Objects.deepEquals(this.bounds, other.bounds)
37
+ && Objects.deepEquals(this.trackingId, other.trackingId)
38
+ && Objects.deepEquals(this.labels, other.labels)
39
+ }
40
+
41
+ override fun hashCode(): Int {
42
+ return arrayOf<Any?>(
43
+ bounds,
44
+ trackingId,
45
+ labels
46
+ ).contentDeepHashCode()
47
+ }
48
+
49
+ companion object {
50
+ /**
51
+ * Constructor called from C++
52
+ */
53
+ @DoNotStrip
54
+ @Keep
55
+ @Suppress("unused")
56
+ @JvmStatic
57
+ private fun fromCpp(bounds: ObjectRect, trackingId: Double, labels: Array<ObjectLabel>): DetectedObject {
58
+ return DetectedObject(bounds, trackingId, labels)
59
+ }
60
+ }
61
+ }