react-native-yolo 0.0.3 → 0.0.5

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 (50) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +51 -51
  3. package/Yolo.podspec +31 -31
  4. package/android/CMakeLists.txt +35 -32
  5. package/android/build.gradle +154 -152
  6. package/android/fix-prefab.gradle +50 -50
  7. package/android/gradle.properties +5 -5
  8. package/android/src/main/AndroidManifest.xml +3 -2
  9. package/android/src/main/cpp/cpp-adapter.cpp +8 -8
  10. package/android/src/main/java/com/yolo/HybridYolo.kt +265 -42
  11. package/android/src/main/java/com/yolo/YoloPackage.kt +20 -20
  12. package/android/src/main/java/com/yolo/loader/YoloModelLoader.kt +31 -0
  13. package/android/src/main/java/com/yolo/utils/BitmapOrientationFixer.kt +56 -0
  14. package/android/src/main/java/com/yolo/utils/FrameJpegConverter.kt +27 -0
  15. package/android/src/main/java/com/yolo/utils/FrameValidator.kt +29 -0
  16. package/android/src/main/java/com/yolo/utils/Nv21JpegEncoder.kt +34 -0
  17. package/android/src/main/java/com/yolo/utils/Yuv420ToNv21Converter.kt +62 -0
  18. package/ios/Bridge.h +8 -8
  19. package/ios/HybridYolo.swift +14 -14
  20. package/lib/commonjs/index.js +10 -1
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/module/index.js +10 -1
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/typescript/src/index.d.ts +3 -1
  25. package/lib/typescript/src/index.d.ts.map +1 -1
  26. package/lib/typescript/src/specs/yolo.nitro.d.ts +15 -0
  27. package/lib/typescript/src/specs/yolo.nitro.d.ts.map +1 -1
  28. package/nitro.json +29 -29
  29. package/nitrogen/generated/android/c++/JBoundingBox.hpp +69 -0
  30. package/nitrogen/generated/android/c++/JDetection.hpp +66 -0
  31. package/nitrogen/generated/android/c++/JHybridYoloSpec.cpp +33 -1
  32. package/nitrogen/generated/android/c++/JHybridYoloSpec.hpp +2 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/BoundingBox.kt +66 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/Detection.kt +61 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/HybridYoloSpec.kt +9 -0
  36. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.cpp +11 -0
  37. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.hpp +54 -0
  38. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Umbrella.hpp +12 -0
  39. package/nitrogen/generated/ios/c++/HybridYoloSpecSwift.hpp +27 -1
  40. package/nitrogen/generated/ios/swift/BoundingBox.swift +44 -0
  41. package/nitrogen/generated/ios/swift/Detection.swift +39 -0
  42. package/nitrogen/generated/ios/swift/HybridYoloSpec.swift +3 -0
  43. package/nitrogen/generated/ios/swift/HybridYoloSpec_cxx.swift +39 -0
  44. package/nitrogen/generated/shared/c++/BoundingBox.hpp +95 -0
  45. package/nitrogen/generated/shared/c++/Detection.hpp +92 -0
  46. package/nitrogen/generated/shared/c++/HybridYoloSpec.cpp +2 -0
  47. package/nitrogen/generated/shared/c++/HybridYoloSpec.hpp +10 -1
  48. package/package.json +127 -122
  49. package/src/index.ts +11 -11
  50. package/src/specs/yolo.nitro.ts +24 -7
@@ -8,18 +8,31 @@
8
8
  #pragma once
9
9
 
10
10
  // Forward declarations of C++ defined types
11
+ // Forward declaration of `BoundingBox` to properly resolve imports.
12
+ namespace margelo::nitro::yolo { struct BoundingBox; }
13
+ // Forward declaration of `Detection` to properly resolve imports.
14
+ namespace margelo::nitro::yolo { struct Detection; }
15
+ // Forward declaration of `HybridFrameSpec` to properly resolve imports.
16
+ namespace margelo::nitro::camera { class HybridFrameSpec; }
11
17
  // Forward declaration of `HybridYoloSpec` to properly resolve imports.
12
18
  namespace margelo::nitro::yolo { class HybridYoloSpec; }
13
19
 
14
20
  // Forward declarations of Swift defined types
21
+ // Forward declaration of `HybridFrameSpec_cxx` to properly resolve imports.
22
+ namespace VisionCamera { class HybridFrameSpec_cxx; }
15
23
  // Forward declaration of `HybridYoloSpec_cxx` to properly resolve imports.
16
24
  namespace Yolo { class HybridYoloSpec_cxx; }
17
25
 
18
26
  // Include C++ defined types
27
+ #include "BoundingBox.hpp"
28
+ #include "Detection.hpp"
19
29
  #include "HybridYoloSpec.hpp"
20
30
  #include <NitroModules/Result.hpp>
31
+ #include <VisionCamera/HybridFrameSpec.hpp>
21
32
  #include <exception>
22
33
  #include <memory>
34
+ #include <string>
35
+ #include <vector>
23
36
 
24
37
  /**
25
38
  * Contains specialized versions of C++ templated types so they can be accessed from Swift,
@@ -27,6 +40,29 @@ namespace Yolo { class HybridYoloSpec_cxx; }
27
40
  */
28
41
  namespace margelo::nitro::yolo::bridge::swift {
29
42
 
43
+ // pragma MARK: std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>
44
+ /**
45
+ * Specialized version of `std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>`.
46
+ */
47
+ using std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_ = std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>;
48
+ std::shared_ptr<margelo::nitro::camera::HybridFrameSpec> create_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
49
+ void* NON_NULL get_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_ cppType);
50
+
51
+ // pragma MARK: std::weak_ptr<margelo::nitro::camera::HybridFrameSpec>
52
+ using std__weak_ptr_margelo__nitro__camera__HybridFrameSpec_ = std::weak_ptr<margelo::nitro::camera::HybridFrameSpec>;
53
+ inline std__weak_ptr_margelo__nitro__camera__HybridFrameSpec_ weakify_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& strong) noexcept { return strong; }
54
+
55
+ // pragma MARK: std::vector<Detection>
56
+ /**
57
+ * Specialized version of `std::vector<Detection>`.
58
+ */
59
+ using std__vector_Detection_ = std::vector<Detection>;
60
+ inline std::vector<Detection> create_std__vector_Detection_(size_t size) noexcept {
61
+ std::vector<Detection> vector;
62
+ vector.reserve(size);
63
+ return vector;
64
+ }
65
+
30
66
  // pragma MARK: std::shared_ptr<HybridYoloSpec>
31
67
  /**
32
68
  * Specialized version of `std::shared_ptr<HybridYoloSpec>`.
@@ -56,5 +92,23 @@ namespace margelo::nitro::yolo::bridge::swift {
56
92
  inline Result_void_ create_Result_void_(const std::exception_ptr& error) noexcept {
57
93
  return Result<void>::withError(error);
58
94
  }
95
+
96
+ // pragma MARK: Result<std::string>
97
+ using Result_std__string_ = Result<std::string>;
98
+ inline Result_std__string_ create_Result_std__string_(const std::string& value) noexcept {
99
+ return Result<std::string>::withValue(value);
100
+ }
101
+ inline Result_std__string_ create_Result_std__string_(const std::exception_ptr& error) noexcept {
102
+ return Result<std::string>::withError(error);
103
+ }
104
+
105
+ // pragma MARK: Result<std::vector<Detection>>
106
+ using Result_std__vector_Detection__ = Result<std::vector<Detection>>;
107
+ inline Result_std__vector_Detection__ create_Result_std__vector_Detection__(const std::vector<Detection>& value) noexcept {
108
+ return Result<std::vector<Detection>>::withValue(value);
109
+ }
110
+ inline Result_std__vector_Detection__ create_Result_std__vector_Detection__(const std::exception_ptr& error) noexcept {
111
+ return Result<std::vector<Detection>>::withError(error);
112
+ }
59
113
 
60
114
  } // namespace margelo::nitro::yolo::bridge::swift
@@ -8,15 +8,25 @@
8
8
  #pragma once
9
9
 
10
10
  // Forward declarations of C++ defined types
11
+ // Forward declaration of `BoundingBox` to properly resolve imports.
12
+ namespace margelo::nitro::yolo { struct BoundingBox; }
13
+ // Forward declaration of `Detection` to properly resolve imports.
14
+ namespace margelo::nitro::yolo { struct Detection; }
15
+ // Forward declaration of `HybridFrameSpec` to properly resolve imports.
16
+ namespace margelo::nitro::camera { class HybridFrameSpec; }
11
17
  // Forward declaration of `HybridYoloSpec` to properly resolve imports.
12
18
  namespace margelo::nitro::yolo { class HybridYoloSpec; }
13
19
 
14
20
  // Include C++ defined types
21
+ #include "BoundingBox.hpp"
22
+ #include "Detection.hpp"
15
23
  #include "HybridYoloSpec.hpp"
16
24
  #include <NitroModules/Result.hpp>
25
+ #include <VisionCamera/HybridFrameSpec.hpp>
17
26
  #include <exception>
18
27
  #include <memory>
19
28
  #include <string>
29
+ #include <vector>
20
30
 
21
31
  // C++ helpers for Swift
22
32
  #include "Yolo-Swift-Cxx-Bridge.hpp"
@@ -28,6 +38,8 @@ namespace margelo::nitro::yolo { class HybridYoloSpec; }
28
38
  #include <NitroModules/DateToChronoDate.hpp>
29
39
 
30
40
  // Forward declarations of Swift defined types
41
+ // Forward declaration of `HybridFrameSpec_cxx` to properly resolve imports.
42
+ namespace VisionCamera { class HybridFrameSpec_cxx; }
31
43
  // Forward declaration of `HybridYoloSpec_cxx` to properly resolve imports.
32
44
  namespace Yolo { class HybridYoloSpec_cxx; }
33
45
 
@@ -12,9 +12,19 @@
12
12
  // Forward declaration of `HybridYoloSpec_cxx` to properly resolve imports.
13
13
  namespace Yolo { class HybridYoloSpec_cxx; }
14
14
 
15
-
15
+ // Forward declaration of `HybridFrameSpec` to properly resolve imports.
16
+ namespace margelo::nitro::camera { class HybridFrameSpec; }
17
+ // Forward declaration of `Detection` to properly resolve imports.
18
+ namespace margelo::nitro::yolo { struct Detection; }
19
+ // Forward declaration of `BoundingBox` to properly resolve imports.
20
+ namespace margelo::nitro::yolo { struct BoundingBox; }
16
21
 
17
22
  #include <string>
23
+ #include <memory>
24
+ #include <VisionCamera/HybridFrameSpec.hpp>
25
+ #include "Detection.hpp"
26
+ #include <vector>
27
+ #include "BoundingBox.hpp"
18
28
 
19
29
  #include "Yolo-Swift-Cxx-Umbrella.hpp"
20
30
 
@@ -80,6 +90,22 @@ namespace margelo::nitro::yolo {
80
90
  std::rethrow_exception(__result.error());
81
91
  }
82
92
  }
93
+ inline std::string frameToBase64(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) override {
94
+ auto __result = _swiftPart.frameToBase64(frame);
95
+ if (__result.hasError()) [[unlikely]] {
96
+ std::rethrow_exception(__result.error());
97
+ }
98
+ auto __value = std::move(__result.value());
99
+ return __value;
100
+ }
101
+ inline std::vector<Detection> detect(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) override {
102
+ auto __result = _swiftPart.detect(frame);
103
+ if (__result.hasError()) [[unlikely]] {
104
+ std::rethrow_exception(__result.error());
105
+ }
106
+ auto __value = std::move(__result.value());
107
+ return __value;
108
+ }
83
109
 
84
110
  private:
85
111
  Yolo::HybridYoloSpec_cxx _swiftPart;
@@ -0,0 +1,44 @@
1
+ ///
2
+ /// BoundingBox.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `BoundingBox`, backed by a C++ struct.
12
+ */
13
+ public typealias BoundingBox = margelo.nitro.yolo.BoundingBox
14
+
15
+ public extension BoundingBox {
16
+ private typealias bridge = margelo.nitro.yolo.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `BoundingBox`.
20
+ */
21
+ init(x1: Double, y1: Double, x2: Double, y2: Double) {
22
+ self.init(x1, y1, x2, y2)
23
+ }
24
+
25
+ @inline(__always)
26
+ var x1: Double {
27
+ return self.__x1
28
+ }
29
+
30
+ @inline(__always)
31
+ var y1: Double {
32
+ return self.__y1
33
+ }
34
+
35
+ @inline(__always)
36
+ var x2: Double {
37
+ return self.__x2
38
+ }
39
+
40
+ @inline(__always)
41
+ var y2: Double {
42
+ return self.__y2
43
+ }
44
+ }
@@ -0,0 +1,39 @@
1
+ ///
2
+ /// Detection.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `Detection`, backed by a C++ struct.
12
+ */
13
+ public typealias Detection = margelo.nitro.yolo.Detection
14
+
15
+ public extension Detection {
16
+ private typealias bridge = margelo.nitro.yolo.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `Detection`.
20
+ */
21
+ init(classId: Double, score: Double, boundingBox: BoundingBox) {
22
+ self.init(classId, score, boundingBox)
23
+ }
24
+
25
+ @inline(__always)
26
+ var classId: Double {
27
+ return self.__classId
28
+ }
29
+
30
+ @inline(__always)
31
+ var score: Double {
32
+ return self.__score
33
+ }
34
+
35
+ @inline(__always)
36
+ var boundingBox: BoundingBox {
37
+ return self.__boundingBox
38
+ }
39
+ }
@@ -5,6 +5,7 @@
5
5
  /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
8
+ import VisionCamera
8
9
  import NitroModules
9
10
 
10
11
  /// See ``HybridYoloSpec``
@@ -15,6 +16,8 @@ public protocol HybridYoloSpec_protocol: HybridObject {
15
16
  // Methods
16
17
  func sum(num1: Double, num2: Double) throws -> Double
17
18
  func loadModel(modelPath: String) throws -> Void
19
+ func frameToBase64(frame: (any HybridFrameSpec)) throws -> String
20
+ func detect(frame: (any HybridFrameSpec)) throws -> [Detection]
18
21
  }
19
22
 
20
23
  public extension HybridYoloSpec_protocol {
@@ -6,6 +6,7 @@
6
6
  ///
7
7
 
8
8
  import NitroModules
9
+ import VisionCamera
9
10
 
10
11
  /**
11
12
  * A class implementation that bridges HybridYoloSpec over to C++.
@@ -146,4 +147,42 @@ open class HybridYoloSpec_cxx {
146
147
  return bridge.create_Result_void_(__exceptionPtr)
147
148
  }
148
149
  }
150
+
151
+ @inline(__always)
152
+ public final func frameToBase64(frame: bridge.std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_) -> bridge.Result_std__string_ {
153
+ do {
154
+ let __result = try self.__implementation.frameToBase64(frame: { () -> any HybridFrameSpec in
155
+ let __unsafePointer = bridge.get_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(frame)
156
+ let __instance = HybridFrameSpec_cxx.fromUnsafe(__unsafePointer)
157
+ return __instance.getHybridFrameSpec()
158
+ }())
159
+ let __resultCpp = std.string(__result)
160
+ return bridge.create_Result_std__string_(__resultCpp)
161
+ } catch (let __error) {
162
+ let __exceptionPtr = __error.toCpp()
163
+ return bridge.create_Result_std__string_(__exceptionPtr)
164
+ }
165
+ }
166
+
167
+ @inline(__always)
168
+ public final func detect(frame: bridge.std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_) -> bridge.Result_std__vector_Detection__ {
169
+ do {
170
+ let __result = try self.__implementation.detect(frame: { () -> any HybridFrameSpec in
171
+ let __unsafePointer = bridge.get_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(frame)
172
+ let __instance = HybridFrameSpec_cxx.fromUnsafe(__unsafePointer)
173
+ return __instance.getHybridFrameSpec()
174
+ }())
175
+ let __resultCpp = { () -> bridge.std__vector_Detection_ in
176
+ var __vector = bridge.create_std__vector_Detection_(__result.count)
177
+ for __item in __result {
178
+ __vector.push_back(__item)
179
+ }
180
+ return __vector
181
+ }()
182
+ return bridge.create_Result_std__vector_Detection__(__resultCpp)
183
+ } catch (let __error) {
184
+ let __exceptionPtr = __error.toCpp()
185
+ return bridge.create_Result_std__vector_Detection__(__exceptionPtr)
186
+ }
187
+ }
149
188
  }
@@ -0,0 +1,95 @@
1
+ ///
2
+ /// BoundingBox.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+
34
+
35
+ namespace margelo::nitro::yolo {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (BoundingBox).
39
+ */
40
+ struct BoundingBox final {
41
+ public:
42
+ double x1 SWIFT_PRIVATE;
43
+ double y1 SWIFT_PRIVATE;
44
+ double x2 SWIFT_PRIVATE;
45
+ double y2 SWIFT_PRIVATE;
46
+
47
+ public:
48
+ BoundingBox() = default;
49
+ explicit BoundingBox(double x1, double y1, double x2, double y2): x1(x1), y1(y1), x2(x2), y2(y2) {}
50
+
51
+ public:
52
+ friend bool operator==(const BoundingBox& lhs, const BoundingBox& rhs) = default;
53
+ };
54
+
55
+ } // namespace margelo::nitro::yolo
56
+
57
+ namespace margelo::nitro {
58
+
59
+ // C++ BoundingBox <> JS BoundingBox (object)
60
+ template <>
61
+ struct JSIConverter<margelo::nitro::yolo::BoundingBox> final {
62
+ static inline margelo::nitro::yolo::BoundingBox fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
63
+ jsi::Object obj = arg.asObject(runtime);
64
+ return margelo::nitro::yolo::BoundingBox(
65
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x1"))),
66
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y1"))),
67
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x2"))),
68
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y2")))
69
+ );
70
+ }
71
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::yolo::BoundingBox& arg) {
72
+ jsi::Object obj(runtime);
73
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "x1"), JSIConverter<double>::toJSI(runtime, arg.x1));
74
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "y1"), JSIConverter<double>::toJSI(runtime, arg.y1));
75
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "x2"), JSIConverter<double>::toJSI(runtime, arg.x2));
76
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "y2"), JSIConverter<double>::toJSI(runtime, arg.y2));
77
+ return obj;
78
+ }
79
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
80
+ if (!value.isObject()) {
81
+ return false;
82
+ }
83
+ jsi::Object obj = value.getObject(runtime);
84
+ if (!nitro::isPlainObject(runtime, obj)) {
85
+ return false;
86
+ }
87
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x1")))) return false;
88
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y1")))) return false;
89
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x2")))) return false;
90
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y2")))) return false;
91
+ return true;
92
+ }
93
+ };
94
+
95
+ } // namespace margelo::nitro
@@ -0,0 +1,92 @@
1
+ ///
2
+ /// Detection.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `BoundingBox` to properly resolve imports.
32
+ namespace margelo::nitro::yolo { struct BoundingBox; }
33
+
34
+ #include "BoundingBox.hpp"
35
+
36
+ namespace margelo::nitro::yolo {
37
+
38
+ /**
39
+ * A struct which can be represented as a JavaScript object (Detection).
40
+ */
41
+ struct Detection final {
42
+ public:
43
+ double classId SWIFT_PRIVATE;
44
+ double score SWIFT_PRIVATE;
45
+ BoundingBox boundingBox SWIFT_PRIVATE;
46
+
47
+ public:
48
+ Detection() = default;
49
+ explicit Detection(double classId, double score, BoundingBox boundingBox): classId(classId), score(score), boundingBox(boundingBox) {}
50
+
51
+ public:
52
+ friend bool operator==(const Detection& lhs, const Detection& rhs) = default;
53
+ };
54
+
55
+ } // namespace margelo::nitro::yolo
56
+
57
+ namespace margelo::nitro {
58
+
59
+ // C++ Detection <> JS Detection (object)
60
+ template <>
61
+ struct JSIConverter<margelo::nitro::yolo::Detection> final {
62
+ static inline margelo::nitro::yolo::Detection fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
63
+ jsi::Object obj = arg.asObject(runtime);
64
+ return margelo::nitro::yolo::Detection(
65
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "classId"))),
66
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "score"))),
67
+ JSIConverter<margelo::nitro::yolo::BoundingBox>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "boundingBox")))
68
+ );
69
+ }
70
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::yolo::Detection& arg) {
71
+ jsi::Object obj(runtime);
72
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "classId"), JSIConverter<double>::toJSI(runtime, arg.classId));
73
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "score"), JSIConverter<double>::toJSI(runtime, arg.score));
74
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "boundingBox"), JSIConverter<margelo::nitro::yolo::BoundingBox>::toJSI(runtime, arg.boundingBox));
75
+ return obj;
76
+ }
77
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
78
+ if (!value.isObject()) {
79
+ return false;
80
+ }
81
+ jsi::Object obj = value.getObject(runtime);
82
+ if (!nitro::isPlainObject(runtime, obj)) {
83
+ return false;
84
+ }
85
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "classId")))) return false;
86
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "score")))) return false;
87
+ if (!JSIConverter<margelo::nitro::yolo::BoundingBox>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "boundingBox")))) return false;
88
+ return true;
89
+ }
90
+ };
91
+
92
+ } // namespace margelo::nitro
@@ -16,6 +16,8 @@ namespace margelo::nitro::yolo {
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
17
  prototype.registerHybridMethod("sum", &HybridYoloSpec::sum);
18
18
  prototype.registerHybridMethod("loadModel", &HybridYoloSpec::loadModel);
19
+ prototype.registerHybridMethod("frameToBase64", &HybridYoloSpec::frameToBase64);
20
+ prototype.registerHybridMethod("detect", &HybridYoloSpec::detect);
19
21
  });
20
22
  }
21
23
 
@@ -13,9 +13,16 @@
13
13
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
14
  #endif
15
15
 
16
-
16
+ // Forward declaration of `HybridFrameSpec` to properly resolve imports.
17
+ namespace margelo::nitro::camera { class HybridFrameSpec; }
18
+ // Forward declaration of `Detection` to properly resolve imports.
19
+ namespace margelo::nitro::yolo { struct Detection; }
17
20
 
18
21
  #include <string>
22
+ #include <memory>
23
+ #include <VisionCamera/HybridFrameSpec.hpp>
24
+ #include "Detection.hpp"
25
+ #include <vector>
19
26
 
20
27
  namespace margelo::nitro::yolo {
21
28
 
@@ -50,6 +57,8 @@ namespace margelo::nitro::yolo {
50
57
  // Methods
51
58
  virtual double sum(double num1, double num2) = 0;
52
59
  virtual void loadModel(const std::string& modelPath) = 0;
60
+ virtual std::string frameToBase64(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) = 0;
61
+ virtual std::vector<Detection> detect(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) = 0;
53
62
 
54
63
  protected:
55
64
  // Hybrid Setup