react-native-yolo 0.0.5 → 0.0.7
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.
- package/android/src/main/java/com/yolo/HybridYolo.kt +12 -235
- package/android/src/main/java/com/yolo/HybridYoloModel.kt +212 -0
- package/android/src/main/java/com/yolo/utils/BitmapOrientationFixer.kt +8 -1
- package/lib/commonjs/index.js +4 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +4 -3
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +12 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/yolo.nitro.d.ts +10 -6
- package/lib/typescript/src/specs/yolo.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/Yolo+autolinking.cmake +2 -0
- package/nitrogen/generated/android/YoloOnLoad.cpp +2 -0
- package/nitrogen/generated/android/c++/JHybridYoloModelSpec.cpp +78 -0
- package/nitrogen/generated/android/c++/JHybridYoloModelSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JHybridYoloSpec.cpp +9 -32
- package/nitrogen/generated/android/c++/JHybridYoloSpec.hpp +1 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/HybridYoloModelSpec.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/HybridYoloSpec.kt +1 -9
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.hpp +48 -31
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Umbrella.hpp +5 -0
- package/nitrogen/generated/ios/c++/HybridYoloModelSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridYoloModelSpecSwift.hpp +97 -0
- package/nitrogen/generated/ios/c++/HybridYoloSpecSwift.hpp +6 -24
- package/nitrogen/generated/ios/swift/HybridYoloModelSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridYoloModelSpec_cxx.swift +160 -0
- package/nitrogen/generated/ios/swift/HybridYoloSpec.swift +1 -3
- package/nitrogen/generated/ios/swift/HybridYoloSpec_cxx.swift +8 -38
- package/nitrogen/generated/shared/c++/HybridYoloModelSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridYoloModelSpec.hpp +69 -0
- package/nitrogen/generated/shared/c++/HybridYoloSpec.cpp +0 -2
- package/nitrogen/generated/shared/c++/HybridYoloSpec.hpp +5 -8
- package/package.json +1 -1
- package/src/index.ts +14 -4
- package/src/specs/yolo.nitro.ts +12 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridYoloModelSpec.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 VisionCamera
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/// See ``HybridYoloModelSpec``
|
|
12
|
+
public protocol HybridYoloModelSpec_protocol: HybridObject {
|
|
13
|
+
// Properties
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// Methods
|
|
17
|
+
func detect(frame: (any HybridFrameSpec)) throws -> [Detection]
|
|
18
|
+
func close() throws -> Void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public extension HybridYoloModelSpec_protocol {
|
|
22
|
+
/// Default implementation of ``HybridObject.toString``
|
|
23
|
+
func toString() -> String {
|
|
24
|
+
return "[HybridObject YoloModel]"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// See ``HybridYoloModelSpec``
|
|
29
|
+
open class HybridYoloModelSpec_base {
|
|
30
|
+
private weak var cxxWrapper: HybridYoloModelSpec_cxx? = nil
|
|
31
|
+
public init() { }
|
|
32
|
+
public func getCxxWrapper() -> HybridYoloModelSpec_cxx {
|
|
33
|
+
#if DEBUG
|
|
34
|
+
guard self is any HybridYoloModelSpec else {
|
|
35
|
+
fatalError("`self` is not a `HybridYoloModelSpec`! Did you accidentally inherit from `HybridYoloModelSpec_base` instead of `HybridYoloModelSpec`?")
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
39
|
+
return cxxWrapper
|
|
40
|
+
} else {
|
|
41
|
+
let cxxWrapper = HybridYoloModelSpec_cxx(self as! any HybridYoloModelSpec)
|
|
42
|
+
self.cxxWrapper = cxxWrapper
|
|
43
|
+
return cxxWrapper
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A Swift base-protocol representing the YoloModel HybridObject.
|
|
50
|
+
* Implement this protocol to create Swift-based instances of YoloModel.
|
|
51
|
+
* ```swift
|
|
52
|
+
* class HybridYoloModel : HybridYoloModelSpec {
|
|
53
|
+
* // ...
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
public typealias HybridYoloModelSpec = HybridYoloModelSpec_protocol & HybridYoloModelSpec_base
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridYoloModelSpec_cxx.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
|
+
import VisionCamera
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridYoloModelSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridYoloModelSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::yolo::bridge::swift`)
|
|
23
|
+
* from `Yolo-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.yolo.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridYoloModelSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridYoloModelSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridYoloModelSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridYoloModelSpec_cxx` that wraps the given `HybridYoloModelSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridYoloModelSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridYoloModelSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridYoloModelSpec() -> any HybridYoloModelSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridYoloModelSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridYoloModelSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridYoloModelSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridYoloModelSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridYoloModelSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridYoloModelSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridYoloModelSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridYoloModelSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compares this object with the given [other] object for reference equality.
|
|
101
|
+
*/
|
|
102
|
+
@inline(__always)
|
|
103
|
+
public func equals(other: HybridYoloModelSpec_cxx) -> Bool {
|
|
104
|
+
return self.__implementation === other.__implementation
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Call dispose() on the Swift class.
|
|
109
|
+
* This _may_ be called manually from JS.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func dispose() {
|
|
113
|
+
self.__implementation.dispose()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Call toString() on the Swift class.
|
|
118
|
+
*/
|
|
119
|
+
@inline(__always)
|
|
120
|
+
public func toString() -> String {
|
|
121
|
+
return self.__implementation.toString()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Properties
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
// Methods
|
|
128
|
+
@inline(__always)
|
|
129
|
+
public final func detect(frame: bridge.std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_) -> bridge.Result_std__vector_Detection__ {
|
|
130
|
+
do {
|
|
131
|
+
let __result = try self.__implementation.detect(frame: { () -> any HybridFrameSpec in
|
|
132
|
+
let __unsafePointer = bridge.get_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(frame)
|
|
133
|
+
let __instance = HybridFrameSpec_cxx.fromUnsafe(__unsafePointer)
|
|
134
|
+
return __instance.getHybridFrameSpec()
|
|
135
|
+
}())
|
|
136
|
+
let __resultCpp = { () -> bridge.std__vector_Detection_ in
|
|
137
|
+
var __vector = bridge.create_std__vector_Detection_(__result.count)
|
|
138
|
+
for __item in __result {
|
|
139
|
+
__vector.push_back(__item)
|
|
140
|
+
}
|
|
141
|
+
return __vector
|
|
142
|
+
}()
|
|
143
|
+
return bridge.create_Result_std__vector_Detection__(__resultCpp)
|
|
144
|
+
} catch (let __error) {
|
|
145
|
+
let __exceptionPtr = __error.toCpp()
|
|
146
|
+
return bridge.create_Result_std__vector_Detection__(__exceptionPtr)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@inline(__always)
|
|
151
|
+
public final func close() -> bridge.Result_void_ {
|
|
152
|
+
do {
|
|
153
|
+
try self.__implementation.close()
|
|
154
|
+
return bridge.create_Result_void_()
|
|
155
|
+
} catch (let __error) {
|
|
156
|
+
let __exceptionPtr = __error.toCpp()
|
|
157
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -14,10 +14,8 @@ public protocol HybridYoloSpec_protocol: HybridObject {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
// Methods
|
|
17
|
-
func
|
|
18
|
-
func loadModel(modelPath: String) throws -> Void
|
|
17
|
+
func loadModel(modelPath: String) throws -> (any HybridYoloModelSpec)
|
|
19
18
|
func frameToBase64(frame: (any HybridFrameSpec)) throws -> String
|
|
20
|
-
func detect(frame: (any HybridFrameSpec)) throws -> [Detection]
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
public extension HybridYoloSpec_protocol {
|
|
@@ -126,25 +126,17 @@ open class HybridYoloSpec_cxx {
|
|
|
126
126
|
|
|
127
127
|
// Methods
|
|
128
128
|
@inline(__always)
|
|
129
|
-
public final func
|
|
129
|
+
public final func loadModel(modelPath: std.string) -> bridge.Result_std__shared_ptr_HybridYoloModelSpec__ {
|
|
130
130
|
do {
|
|
131
|
-
let __result = try self.__implementation.
|
|
132
|
-
let __resultCpp =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return bridge.
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@inline(__always)
|
|
141
|
-
public final func loadModel(modelPath: std.string) -> bridge.Result_void_ {
|
|
142
|
-
do {
|
|
143
|
-
try self.__implementation.loadModel(modelPath: String(modelPath))
|
|
144
|
-
return bridge.create_Result_void_()
|
|
131
|
+
let __result = try self.__implementation.loadModel(modelPath: String(modelPath))
|
|
132
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_HybridYoloModelSpec_ in
|
|
133
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
134
|
+
return __cxxWrapped.getCxxPart()
|
|
135
|
+
}()
|
|
136
|
+
return bridge.create_Result_std__shared_ptr_HybridYoloModelSpec__(__resultCpp)
|
|
145
137
|
} catch (let __error) {
|
|
146
138
|
let __exceptionPtr = __error.toCpp()
|
|
147
|
-
return bridge.
|
|
139
|
+
return bridge.create_Result_std__shared_ptr_HybridYoloModelSpec__(__exceptionPtr)
|
|
148
140
|
}
|
|
149
141
|
}
|
|
150
142
|
|
|
@@ -163,26 +155,4 @@ open class HybridYoloSpec_cxx {
|
|
|
163
155
|
return bridge.create_Result_std__string_(__exceptionPtr)
|
|
164
156
|
}
|
|
165
157
|
}
|
|
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
|
-
}
|
|
188
158
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridYoloModelSpec.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 "HybridYoloModelSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::yolo {
|
|
11
|
+
|
|
12
|
+
void HybridYoloModelSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("detect", &HybridYoloModelSpec::detect);
|
|
18
|
+
prototype.registerHybridMethod("close", &HybridYoloModelSpec::close);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace margelo::nitro::yolo
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridYoloModelSpec.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/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `Detection` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::yolo { struct Detection; }
|
|
18
|
+
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
20
|
+
|
|
21
|
+
#include "Detection.hpp"
|
|
22
|
+
#include <vector>
|
|
23
|
+
#include <memory>
|
|
24
|
+
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::yolo {
|
|
27
|
+
|
|
28
|
+
using namespace margelo::nitro;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An abstract base class for `YoloModel`
|
|
32
|
+
* Inherit this class to create instances of `HybridYoloModelSpec` in C++.
|
|
33
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
34
|
+
* @example
|
|
35
|
+
* ```cpp
|
|
36
|
+
* class HybridYoloModel: public HybridYoloModelSpec {
|
|
37
|
+
* public:
|
|
38
|
+
* HybridYoloModel(...): HybridObject(TAG) { ... }
|
|
39
|
+
* // ...
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class HybridYoloModelSpec: public virtual HybridObject {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor
|
|
46
|
+
explicit HybridYoloModelSpec(): HybridObject(TAG) { }
|
|
47
|
+
|
|
48
|
+
// Destructor
|
|
49
|
+
~HybridYoloModelSpec() override = default;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
virtual std::vector<Detection> detect(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) = 0;
|
|
58
|
+
virtual void close() = 0;
|
|
59
|
+
|
|
60
|
+
protected:
|
|
61
|
+
// Hybrid Setup
|
|
62
|
+
void loadHybridMethods() override;
|
|
63
|
+
|
|
64
|
+
protected:
|
|
65
|
+
// Tag for logging
|
|
66
|
+
static constexpr auto TAG = "YoloModel";
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace margelo::nitro::yolo
|
|
@@ -14,10 +14,8 @@ namespace margelo::nitro::yolo {
|
|
|
14
14
|
HybridObject::loadHybridMethods();
|
|
15
15
|
// load custom methods/properties
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
-
prototype.registerHybridMethod("sum", &HybridYoloSpec::sum);
|
|
18
17
|
prototype.registerHybridMethod("loadModel", &HybridYoloSpec::loadModel);
|
|
19
18
|
prototype.registerHybridMethod("frameToBase64", &HybridYoloSpec::frameToBase64);
|
|
20
|
-
prototype.registerHybridMethod("detect", &HybridYoloSpec::detect);
|
|
21
19
|
});
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -13,16 +13,15 @@
|
|
|
13
13
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
+
// Forward declaration of `HybridYoloModelSpec` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::yolo { class HybridYoloModelSpec; }
|
|
16
18
|
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
17
19
|
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
18
|
-
// Forward declaration of `Detection` to properly resolve imports.
|
|
19
|
-
namespace margelo::nitro::yolo { struct Detection; }
|
|
20
20
|
|
|
21
|
-
#include <string>
|
|
22
21
|
#include <memory>
|
|
22
|
+
#include "HybridYoloModelSpec.hpp"
|
|
23
|
+
#include <string>
|
|
23
24
|
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
24
|
-
#include "Detection.hpp"
|
|
25
|
-
#include <vector>
|
|
26
25
|
|
|
27
26
|
namespace margelo::nitro::yolo {
|
|
28
27
|
|
|
@@ -55,10 +54,8 @@ namespace margelo::nitro::yolo {
|
|
|
55
54
|
|
|
56
55
|
public:
|
|
57
56
|
// Methods
|
|
58
|
-
virtual
|
|
59
|
-
virtual void loadModel(const std::string& modelPath) = 0;
|
|
57
|
+
virtual std::shared_ptr<HybridYoloModelSpec> loadModel(const std::string& modelPath) = 0;
|
|
60
58
|
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;
|
|
62
59
|
|
|
63
60
|
protected:
|
|
64
61
|
// Hybrid Setup
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
2
|
import type { Yolo as YoloSpec } from './specs/yolo.nitro'
|
|
3
3
|
import { Image } from 'react-native'
|
|
4
|
+
import type { Frame } from 'react-native-vision-camera';
|
|
4
5
|
|
|
5
6
|
const NativeYolo = NitroModules.createHybridObject<YoloSpec>('Yolo')
|
|
6
7
|
|
|
7
|
-
export const Yolo =
|
|
8
|
-
|
|
9
|
-
const { uri } = Image.resolveAssetSource(modelAssetId)
|
|
8
|
+
export const Yolo = {
|
|
9
|
+
loadModel(modelAssetId: number) {
|
|
10
|
+
const { uri } = Image.resolveAssetSource(modelAssetId)
|
|
10
11
|
return NativeYolo.loadModel(uri)
|
|
11
12
|
},
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
frameToBase64(frame: Frame) {
|
|
15
|
+
return NativeYolo.frameToBase64(frame)
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
export type {
|
|
19
|
+
Detection,
|
|
20
|
+
BoundingBox,
|
|
21
|
+
YoloModel,
|
|
22
|
+
} from './specs/yolo.nitro'
|
package/src/specs/yolo.nitro.ts
CHANGED
|
@@ -13,12 +13,21 @@ export type BoundingBox = {
|
|
|
13
13
|
y2: number
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export interface YoloModel extends HybridObject<{
|
|
17
|
+
ios: 'swift'
|
|
18
|
+
android: 'kotlin'
|
|
19
|
+
}> {
|
|
20
|
+
detect(frame: Frame): Detection[]
|
|
21
|
+
close(): void
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
export interface Yolo extends HybridObject<{
|
|
17
26
|
ios: 'swift'
|
|
18
27
|
android: 'kotlin'
|
|
19
28
|
}> {
|
|
20
|
-
|
|
21
|
-
loadModel(modelPath: string): void
|
|
29
|
+
loadModel(modelPath: string): YoloModel
|
|
22
30
|
frameToBase64(frame: Frame): string
|
|
23
|
-
detect(frame: Frame): Detection[]
|
|
24
31
|
}
|
|
32
|
+
|
|
33
|
+
|