@nitro-mlkit/pose-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.
- package/LICENSE +21 -0
- package/NitroMLKitPose.podspec +34 -0
- package/README.md +57 -0
- package/android/CMakeLists.txt +12 -0
- package/android/build.gradle +77 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/kotlin/com/margelo/nitro/nitromlkit/pose/HybridPoseDetector.kt +93 -0
- package/android/src/main/kotlin/com/nitromlkit/pose/NitroMLKitPosePackage.kt +19 -0
- package/expo-module.config.json +9 -0
- package/ios/HybridPoseDetector.swift +146 -0
- package/nitro.json +16 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroMLKitPose+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroMLKitPose+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroMLKitPoseOnLoad.cpp +54 -0
- package/nitrogen/generated/android/NitroMLKitPoseOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JBatchPoseResult.hpp +91 -0
- package/nitrogen/generated/android/c++/JHybridPoseDetectorSpec.cpp +123 -0
- package/nitrogen/generated/android/c++/JHybridPoseDetectorSpec.hpp +65 -0
- package/nitrogen/generated/android/c++/JPoseLandmark.hpp +73 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/pose/BatchPoseResult.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/pose/HybridPoseDetectorSpec.kt +63 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/pose/NitroMLKitPoseOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/pose/PoseLandmark.kt +71 -0
- package/nitrogen/generated/ios/NitroMLKitPose+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroMLKitPose-Swift-Cxx-Bridge.cpp +57 -0
- package/nitrogen/generated/ios/NitroMLKitPose-Swift-Cxx-Bridge.hpp +219 -0
- package/nitrogen/generated/ios/NitroMLKitPose-Swift-Cxx-Umbrella.hpp +53 -0
- package/nitrogen/generated/ios/NitroMLKitPoseAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroMLKitPoseAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridPoseDetectorSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridPoseDetectorSpecSwift.hpp +106 -0
- package/nitrogen/generated/ios/swift/BatchPoseResult.swift +63 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_BatchPoseResult_.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_PoseLandmark_.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridPoseDetectorSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridPoseDetectorSpec_cxx.swift +188 -0
- package/nitrogen/generated/ios/swift/PoseLandmark.swift +49 -0
- package/nitrogen/generated/shared/c++/BatchPoseResult.hpp +99 -0
- package/nitrogen/generated/shared/c++/HybridPoseDetectorSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridPoseDetectorSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/PoseLandmark.hpp +99 -0
- package/package.json +54 -0
- package/src/index.ts +18 -0
- package/src/specs/PoseDetector.nitro.ts +47 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__vector_PoseLandmark_.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
|
+
* Wraps a Swift `(_ value: [PoseLandmark]) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__vector_PoseLandmark_ {
|
|
15
|
+
public typealias bridge = margelo.nitro.mlkit.pose.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ value: [PoseLandmark]) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ value: [PoseLandmark]) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(value: bridge.std__vector_PoseLandmark_) -> Void {
|
|
25
|
+
self.closure(value.map({ __item in __item }))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_std__vector_PoseLandmark_`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__vector_PoseLandmark_>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_PoseLandmark_ {
|
|
44
|
+
return Unmanaged<Func_void_std__vector_PoseLandmark_>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPoseDetectorSpec.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
|
+
/// See ``HybridPoseDetectorSpec``
|
|
11
|
+
public protocol HybridPoseDetectorSpec_protocol: HybridObject {
|
|
12
|
+
// Properties
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// Methods
|
|
16
|
+
func detect(imageUri: String) throws -> Promise<[PoseLandmark]>
|
|
17
|
+
func detectBatch(imageUris: [String], concurrency: Double) throws -> Promise<[BatchPoseResult]>
|
|
18
|
+
func isAvailable() throws -> Bool
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public extension HybridPoseDetectorSpec_protocol {
|
|
22
|
+
/// Default implementation of ``HybridObject.toString``
|
|
23
|
+
func toString() -> String {
|
|
24
|
+
return "[HybridObject PoseDetector]"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// See ``HybridPoseDetectorSpec``
|
|
29
|
+
open class HybridPoseDetectorSpec_base {
|
|
30
|
+
private weak var cxxWrapper: HybridPoseDetectorSpec_cxx? = nil
|
|
31
|
+
public init() { }
|
|
32
|
+
public func getCxxWrapper() -> HybridPoseDetectorSpec_cxx {
|
|
33
|
+
#if DEBUG
|
|
34
|
+
guard self is any HybridPoseDetectorSpec else {
|
|
35
|
+
fatalError("`self` is not a `HybridPoseDetectorSpec`! Did you accidentally inherit from `HybridPoseDetectorSpec_base` instead of `HybridPoseDetectorSpec`?")
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
39
|
+
return cxxWrapper
|
|
40
|
+
} else {
|
|
41
|
+
let cxxWrapper = HybridPoseDetectorSpec_cxx(self as! any HybridPoseDetectorSpec)
|
|
42
|
+
self.cxxWrapper = cxxWrapper
|
|
43
|
+
return cxxWrapper
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A Swift base-protocol representing the PoseDetector HybridObject.
|
|
50
|
+
* Implement this protocol to create Swift-based instances of PoseDetector.
|
|
51
|
+
* ```swift
|
|
52
|
+
* class HybridPoseDetector : HybridPoseDetectorSpec {
|
|
53
|
+
* // ...
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
public typealias HybridPoseDetectorSpec = HybridPoseDetectorSpec_protocol & HybridPoseDetectorSpec_base
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPoseDetectorSpec_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
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A class implementation that bridges HybridPoseDetectorSpec over to C++.
|
|
12
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
13
|
+
*
|
|
14
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
15
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
16
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
17
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
18
|
+
*/
|
|
19
|
+
open class HybridPoseDetectorSpec_cxx {
|
|
20
|
+
/**
|
|
21
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::mlkit::pose::bridge::swift`)
|
|
22
|
+
* from `NitroMLKitPose-Swift-Cxx-Bridge.hpp`.
|
|
23
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
24
|
+
*/
|
|
25
|
+
public typealias bridge = margelo.nitro.mlkit.pose.bridge.swift
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Holds an instance of the `HybridPoseDetectorSpec` Swift protocol.
|
|
29
|
+
*/
|
|
30
|
+
private var __implementation: any HybridPoseDetectorSpec
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
34
|
+
*/
|
|
35
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridPoseDetectorSpec_
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a new `HybridPoseDetectorSpec_cxx` that wraps the given `HybridPoseDetectorSpec`.
|
|
39
|
+
* All properties and methods bridge to C++ types.
|
|
40
|
+
*/
|
|
41
|
+
public init(_ implementation: any HybridPoseDetectorSpec) {
|
|
42
|
+
self.__implementation = implementation
|
|
43
|
+
self.__cxxPart = .init()
|
|
44
|
+
/* no base class */
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the actual `HybridPoseDetectorSpec` instance this class wraps.
|
|
49
|
+
*/
|
|
50
|
+
@inline(__always)
|
|
51
|
+
public func getHybridPoseDetectorSpec() -> any HybridPoseDetectorSpec {
|
|
52
|
+
return __implementation
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
57
|
+
* This acquires one additional strong reference on the object!
|
|
58
|
+
*/
|
|
59
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
60
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Casts an unsafe pointer to a `HybridPoseDetectorSpec_cxx`.
|
|
65
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridPoseDetectorSpec_cxx>`.
|
|
66
|
+
* This removes one strong reference from the object!
|
|
67
|
+
*/
|
|
68
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridPoseDetectorSpec_cxx {
|
|
69
|
+
return Unmanaged<HybridPoseDetectorSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
74
|
+
* The C++ part is a `std::shared_ptr<HybridPoseDetectorSpec>`.
|
|
75
|
+
*/
|
|
76
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridPoseDetectorSpec_ {
|
|
77
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
78
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
79
|
+
return cachedCxxPart
|
|
80
|
+
} else {
|
|
81
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridPoseDetectorSpec_(self.toUnsafe())
|
|
82
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridPoseDetectorSpec_(newCxxPart)
|
|
83
|
+
return newCxxPart
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
91
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
92
|
+
*/
|
|
93
|
+
@inline(__always)
|
|
94
|
+
public var memorySize: Int {
|
|
95
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Compares this object with the given [other] object for reference equality.
|
|
100
|
+
*/
|
|
101
|
+
@inline(__always)
|
|
102
|
+
public func equals(other: HybridPoseDetectorSpec_cxx) -> Bool {
|
|
103
|
+
return self.__implementation === other.__implementation
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Call dispose() on the Swift class.
|
|
108
|
+
* This _may_ be called manually from JS.
|
|
109
|
+
*/
|
|
110
|
+
@inline(__always)
|
|
111
|
+
public func dispose() {
|
|
112
|
+
self.__implementation.dispose()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Call toString() on the Swift class.
|
|
117
|
+
*/
|
|
118
|
+
@inline(__always)
|
|
119
|
+
public func toString() -> String {
|
|
120
|
+
return self.__implementation.toString()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Properties
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// Methods
|
|
127
|
+
@inline(__always)
|
|
128
|
+
public final func detect(imageUri: std.string) -> bridge.Result_std__shared_ptr_Promise_std__vector_PoseLandmark____ {
|
|
129
|
+
do {
|
|
130
|
+
let __result = try self.__implementation.detect(imageUri: String(imageUri))
|
|
131
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__vector_PoseLandmark___ in
|
|
132
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__vector_PoseLandmark___()
|
|
133
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__vector_PoseLandmark___(__promise)
|
|
134
|
+
__result
|
|
135
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__vector_PoseLandmark_ in
|
|
136
|
+
var __vector = bridge.create_std__vector_PoseLandmark_(__result.count)
|
|
137
|
+
for __item in __result {
|
|
138
|
+
__vector.push_back(__item)
|
|
139
|
+
}
|
|
140
|
+
return __vector
|
|
141
|
+
}()) })
|
|
142
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
143
|
+
return __promise
|
|
144
|
+
}()
|
|
145
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__vector_PoseLandmark____(__resultCpp)
|
|
146
|
+
} catch (let __error) {
|
|
147
|
+
let __exceptionPtr = __error.toCpp()
|
|
148
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__vector_PoseLandmark____(__exceptionPtr)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@inline(__always)
|
|
153
|
+
public final func detectBatch(imageUris: bridge.std__vector_std__string_, concurrency: Double) -> bridge.Result_std__shared_ptr_Promise_std__vector_BatchPoseResult____ {
|
|
154
|
+
do {
|
|
155
|
+
let __result = try self.__implementation.detectBatch(imageUris: imageUris.map({ __item in String(__item) }), concurrency: concurrency)
|
|
156
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__vector_BatchPoseResult___ in
|
|
157
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__vector_BatchPoseResult___()
|
|
158
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__vector_BatchPoseResult___(__promise)
|
|
159
|
+
__result
|
|
160
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__vector_BatchPoseResult_ in
|
|
161
|
+
var __vector = bridge.create_std__vector_BatchPoseResult_(__result.count)
|
|
162
|
+
for __item in __result {
|
|
163
|
+
__vector.push_back(__item)
|
|
164
|
+
}
|
|
165
|
+
return __vector
|
|
166
|
+
}()) })
|
|
167
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
168
|
+
return __promise
|
|
169
|
+
}()
|
|
170
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__vector_BatchPoseResult____(__resultCpp)
|
|
171
|
+
} catch (let __error) {
|
|
172
|
+
let __exceptionPtr = __error.toCpp()
|
|
173
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__vector_BatchPoseResult____(__exceptionPtr)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@inline(__always)
|
|
178
|
+
public final func isAvailable() -> bridge.Result_bool_ {
|
|
179
|
+
do {
|
|
180
|
+
let __result = try self.__implementation.isAvailable()
|
|
181
|
+
let __resultCpp = __result
|
|
182
|
+
return bridge.create_Result_bool_(__resultCpp)
|
|
183
|
+
} catch (let __error) {
|
|
184
|
+
let __exceptionPtr = __error.toCpp()
|
|
185
|
+
return bridge.create_Result_bool_(__exceptionPtr)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PoseLandmark.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 `PoseLandmark`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias PoseLandmark = margelo.nitro.mlkit.pose.PoseLandmark
|
|
14
|
+
|
|
15
|
+
public extension PoseLandmark {
|
|
16
|
+
private typealias bridge = margelo.nitro.mlkit.pose.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `PoseLandmark`.
|
|
20
|
+
*/
|
|
21
|
+
init(type: Double, x: Double, y: Double, z: Double, inFrameLikelihood: Double) {
|
|
22
|
+
self.init(type, x, y, z, inFrameLikelihood)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@inline(__always)
|
|
26
|
+
var type: Double {
|
|
27
|
+
return self.__type
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@inline(__always)
|
|
31
|
+
var x: Double {
|
|
32
|
+
return self.__x
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@inline(__always)
|
|
36
|
+
var y: Double {
|
|
37
|
+
return self.__y
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@inline(__always)
|
|
41
|
+
var z: Double {
|
|
42
|
+
return self.__z
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@inline(__always)
|
|
46
|
+
var inFrameLikelihood: Double {
|
|
47
|
+
return self.__inFrameLikelihood
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// BatchPoseResult.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 `PoseLandmark` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::mlkit::pose { struct PoseLandmark; }
|
|
33
|
+
|
|
34
|
+
#include "PoseLandmark.hpp"
|
|
35
|
+
#include <vector>
|
|
36
|
+
#include <string>
|
|
37
|
+
#include <optional>
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::mlkit::pose {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (BatchPoseResult).
|
|
43
|
+
*/
|
|
44
|
+
struct BatchPoseResult final {
|
|
45
|
+
public:
|
|
46
|
+
double index SWIFT_PRIVATE;
|
|
47
|
+
std::vector<PoseLandmark> landmarks SWIFT_PRIVATE;
|
|
48
|
+
bool success SWIFT_PRIVATE;
|
|
49
|
+
std::optional<std::string> error SWIFT_PRIVATE;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
BatchPoseResult() = default;
|
|
53
|
+
explicit BatchPoseResult(double index, std::vector<PoseLandmark> landmarks, bool success, std::optional<std::string> error): index(index), landmarks(landmarks), success(success), error(error) {}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
friend bool operator==(const BatchPoseResult& lhs, const BatchPoseResult& rhs) = default;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace margelo::nitro::mlkit::pose
|
|
60
|
+
|
|
61
|
+
namespace margelo::nitro {
|
|
62
|
+
|
|
63
|
+
// C++ BatchPoseResult <> JS BatchPoseResult (object)
|
|
64
|
+
template <>
|
|
65
|
+
struct JSIConverter<margelo::nitro::mlkit::pose::BatchPoseResult> final {
|
|
66
|
+
static inline margelo::nitro::mlkit::pose::BatchPoseResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
67
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
68
|
+
return margelo::nitro::mlkit::pose::BatchPoseResult(
|
|
69
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index"))),
|
|
70
|
+
JSIConverter<std::vector<margelo::nitro::mlkit::pose::PoseLandmark>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "landmarks"))),
|
|
71
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "success"))),
|
|
72
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "error")))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::pose::BatchPoseResult& arg) {
|
|
76
|
+
jsi::Object obj(runtime);
|
|
77
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "index"), JSIConverter<double>::toJSI(runtime, arg.index));
|
|
78
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "landmarks"), JSIConverter<std::vector<margelo::nitro::mlkit::pose::PoseLandmark>>::toJSI(runtime, arg.landmarks));
|
|
79
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "success"), JSIConverter<bool>::toJSI(runtime, arg.success));
|
|
80
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "error"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.error));
|
|
81
|
+
return obj;
|
|
82
|
+
}
|
|
83
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
84
|
+
if (!value.isObject()) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
jsi::Object obj = value.getObject(runtime);
|
|
88
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index")))) return false;
|
|
92
|
+
if (!JSIConverter<std::vector<margelo::nitro::mlkit::pose::PoseLandmark>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "landmarks")))) return false;
|
|
93
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "success")))) return false;
|
|
94
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "error")))) return false;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPoseDetectorSpec.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 "HybridPoseDetectorSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlkit::pose {
|
|
11
|
+
|
|
12
|
+
void HybridPoseDetectorSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("detect", &HybridPoseDetectorSpec::detect);
|
|
18
|
+
prototype.registerHybridMethod("detectBatch", &HybridPoseDetectorSpec::detectBatch);
|
|
19
|
+
prototype.registerHybridMethod("isAvailable", &HybridPoseDetectorSpec::isAvailable);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace margelo::nitro::mlkit::pose
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPoseDetectorSpec.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 `PoseLandmark` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::mlkit::pose { struct PoseLandmark; }
|
|
18
|
+
// Forward declaration of `BatchPoseResult` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::mlkit::pose { struct BatchPoseResult; }
|
|
20
|
+
|
|
21
|
+
#include "PoseLandmark.hpp"
|
|
22
|
+
#include <vector>
|
|
23
|
+
#include <NitroModules/Promise.hpp>
|
|
24
|
+
#include <string>
|
|
25
|
+
#include "BatchPoseResult.hpp"
|
|
26
|
+
|
|
27
|
+
namespace margelo::nitro::mlkit::pose {
|
|
28
|
+
|
|
29
|
+
using namespace margelo::nitro;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An abstract base class for `PoseDetector`
|
|
33
|
+
* Inherit this class to create instances of `HybridPoseDetectorSpec` in C++.
|
|
34
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
35
|
+
* @example
|
|
36
|
+
* ```cpp
|
|
37
|
+
* class HybridPoseDetector: public HybridPoseDetectorSpec {
|
|
38
|
+
* public:
|
|
39
|
+
* HybridPoseDetector(...): HybridObject(TAG) { ... }
|
|
40
|
+
* // ...
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
class HybridPoseDetectorSpec: public virtual HybridObject {
|
|
45
|
+
public:
|
|
46
|
+
// Constructor
|
|
47
|
+
explicit HybridPoseDetectorSpec(): HybridObject(TAG) { }
|
|
48
|
+
|
|
49
|
+
// Destructor
|
|
50
|
+
~HybridPoseDetectorSpec() override = default;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Properties
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
// Methods
|
|
58
|
+
virtual std::shared_ptr<Promise<std::vector<PoseLandmark>>> detect(const std::string& imageUri) = 0;
|
|
59
|
+
virtual std::shared_ptr<Promise<std::vector<BatchPoseResult>>> detectBatch(const std::vector<std::string>& imageUris, double concurrency) = 0;
|
|
60
|
+
virtual bool isAvailable() = 0;
|
|
61
|
+
|
|
62
|
+
protected:
|
|
63
|
+
// Hybrid Setup
|
|
64
|
+
void loadHybridMethods() override;
|
|
65
|
+
|
|
66
|
+
protected:
|
|
67
|
+
// Tag for logging
|
|
68
|
+
static constexpr auto TAG = "PoseDetector";
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace margelo::nitro::mlkit::pose
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PoseLandmark.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::mlkit::pose {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (PoseLandmark).
|
|
39
|
+
*/
|
|
40
|
+
struct PoseLandmark final {
|
|
41
|
+
public:
|
|
42
|
+
double type SWIFT_PRIVATE;
|
|
43
|
+
double x SWIFT_PRIVATE;
|
|
44
|
+
double y SWIFT_PRIVATE;
|
|
45
|
+
double z SWIFT_PRIVATE;
|
|
46
|
+
double inFrameLikelihood SWIFT_PRIVATE;
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
PoseLandmark() = default;
|
|
50
|
+
explicit PoseLandmark(double type, double x, double y, double z, double inFrameLikelihood): type(type), x(x), y(y), z(z), inFrameLikelihood(inFrameLikelihood) {}
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
friend bool operator==(const PoseLandmark& lhs, const PoseLandmark& rhs) = default;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
} // namespace margelo::nitro::mlkit::pose
|
|
57
|
+
|
|
58
|
+
namespace margelo::nitro {
|
|
59
|
+
|
|
60
|
+
// C++ PoseLandmark <> JS PoseLandmark (object)
|
|
61
|
+
template <>
|
|
62
|
+
struct JSIConverter<margelo::nitro::mlkit::pose::PoseLandmark> final {
|
|
63
|
+
static inline margelo::nitro::mlkit::pose::PoseLandmark fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
64
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
65
|
+
return margelo::nitro::mlkit::pose::PoseLandmark(
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))),
|
|
68
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))),
|
|
69
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "z"))),
|
|
70
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "inFrameLikelihood")))
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::pose::PoseLandmark& arg) {
|
|
74
|
+
jsi::Object obj(runtime);
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "type"), JSIConverter<double>::toJSI(runtime, arg.type));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter<double>::toJSI(runtime, arg.x));
|
|
77
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter<double>::toJSI(runtime, arg.y));
|
|
78
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "z"), JSIConverter<double>::toJSI(runtime, arg.z));
|
|
79
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "inFrameLikelihood"), JSIConverter<double>::toJSI(runtime, arg.inFrameLikelihood));
|
|
80
|
+
return obj;
|
|
81
|
+
}
|
|
82
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
83
|
+
if (!value.isObject()) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
jsi::Object obj = value.getObject(runtime);
|
|
87
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type")))) return false;
|
|
91
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x")))) return false;
|
|
92
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y")))) return false;
|
|
93
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "z")))) return false;
|
|
94
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "inFrameLikelihood")))) return false;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
} // namespace margelo::nitro
|