react-native-yolo 0.0.4 → 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 +15 -38
- package/android/src/main/java/com/yolo/HybridYoloModel.kt +212 -0
- package/android/src/main/java/com/yolo/loader/YoloModelLoader.kt +31 -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 +19 -2
- 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++/JBoundingBox.hpp +69 -0
- package/nitrogen/generated/android/c++/JDetection.hpp +66 -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 -9
- package/nitrogen/generated/android/c++/JHybridYoloSpec.hpp +1 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/BoundingBox.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/Detection.kt +61 -0
- 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 -5
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.hpp +58 -14
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Umbrella.hpp +12 -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 -9
- package/nitrogen/generated/ios/swift/BoundingBox.swift +44 -0
- package/nitrogen/generated/ios/swift/Detection.swift +39 -0
- 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 -2
- package/nitrogen/generated/ios/swift/HybridYoloSpec_cxx.swift +8 -16
- package/nitrogen/generated/shared/c++/BoundingBox.hpp +95 -0
- package/nitrogen/generated/shared/c++/Detection.hpp +92 -0
- 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 -1
- package/nitrogen/generated/shared/c++/HybridYoloSpec.hpp +5 -3
- package/package.json +1 -1
- package/src/index.ts +14 -4
- package/src/specs/yolo.nitro.ts +29 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridYoloModelSpecSwift.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 "HybridYoloModelSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridYoloModelSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace Yolo { class HybridYoloModelSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
// Forward declaration of `Detection` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::yolo { struct Detection; }
|
|
17
|
+
// Forward declaration of `BoundingBox` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::yolo { struct BoundingBox; }
|
|
19
|
+
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
20
|
+
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
21
|
+
|
|
22
|
+
#include "Detection.hpp"
|
|
23
|
+
#include <vector>
|
|
24
|
+
#include "BoundingBox.hpp"
|
|
25
|
+
#include <memory>
|
|
26
|
+
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
27
|
+
|
|
28
|
+
#include "Yolo-Swift-Cxx-Umbrella.hpp"
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::yolo {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The C++ part of HybridYoloModelSpec_cxx.swift.
|
|
34
|
+
*
|
|
35
|
+
* HybridYoloModelSpecSwift (C++) accesses HybridYoloModelSpec_cxx (Swift), and might
|
|
36
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
37
|
+
*
|
|
38
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
39
|
+
* the future, HybridYoloModelSpec_cxx can directly inherit from the C++ class HybridYoloModelSpec
|
|
40
|
+
* to simplify the whole structure and memory management.
|
|
41
|
+
*/
|
|
42
|
+
class HybridYoloModelSpecSwift: public virtual HybridYoloModelSpec {
|
|
43
|
+
public:
|
|
44
|
+
// Constructor from a Swift instance
|
|
45
|
+
explicit HybridYoloModelSpecSwift(const Yolo::HybridYoloModelSpec_cxx& swiftPart):
|
|
46
|
+
HybridObject(HybridYoloModelSpec::TAG),
|
|
47
|
+
_swiftPart(swiftPart) { }
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
// Get the Swift part
|
|
51
|
+
inline Yolo::HybridYoloModelSpec_cxx& getSwiftPart() noexcept {
|
|
52
|
+
return _swiftPart;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
57
|
+
return _swiftPart.getMemorySize();
|
|
58
|
+
}
|
|
59
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override {
|
|
60
|
+
if (auto otherCast = std::dynamic_pointer_cast<HybridYoloModelSpecSwift>(other)) {
|
|
61
|
+
return _swiftPart.equals(otherCast->_swiftPart);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
void dispose() noexcept override {
|
|
66
|
+
_swiftPart.dispose();
|
|
67
|
+
}
|
|
68
|
+
std::string toString() override {
|
|
69
|
+
return _swiftPart.toString();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public:
|
|
73
|
+
// Properties
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
public:
|
|
77
|
+
// Methods
|
|
78
|
+
inline std::vector<Detection> detect(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) override {
|
|
79
|
+
auto __result = _swiftPart.detect(frame);
|
|
80
|
+
if (__result.hasError()) [[unlikely]] {
|
|
81
|
+
std::rethrow_exception(__result.error());
|
|
82
|
+
}
|
|
83
|
+
auto __value = std::move(__result.value());
|
|
84
|
+
return __value;
|
|
85
|
+
}
|
|
86
|
+
inline void close() override {
|
|
87
|
+
auto __result = _swiftPart.close();
|
|
88
|
+
if (__result.hasError()) [[unlikely]] {
|
|
89
|
+
std::rethrow_exception(__result.error());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private:
|
|
94
|
+
Yolo::HybridYoloModelSpec_cxx _swiftPart;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
} // namespace margelo::nitro::yolo
|
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
// Forward declaration of `HybridYoloSpec_cxx` to properly resolve imports.
|
|
13
13
|
namespace Yolo { class HybridYoloSpec_cxx; }
|
|
14
14
|
|
|
15
|
+
// Forward declaration of `HybridYoloModelSpec` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::yolo { class HybridYoloModelSpec; }
|
|
15
17
|
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
16
18
|
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
17
19
|
|
|
18
|
-
#include <string>
|
|
19
20
|
#include <memory>
|
|
21
|
+
#include "HybridYoloModelSpec.hpp"
|
|
22
|
+
#include <string>
|
|
20
23
|
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
21
24
|
|
|
22
25
|
#include "Yolo-Swift-Cxx-Umbrella.hpp"
|
|
@@ -69,20 +72,14 @@ namespace margelo::nitro::yolo {
|
|
|
69
72
|
|
|
70
73
|
public:
|
|
71
74
|
// Methods
|
|
72
|
-
inline
|
|
73
|
-
auto __result = _swiftPart.
|
|
75
|
+
inline std::shared_ptr<HybridYoloModelSpec> loadModel(const std::string& modelPath) override {
|
|
76
|
+
auto __result = _swiftPart.loadModel(modelPath);
|
|
74
77
|
if (__result.hasError()) [[unlikely]] {
|
|
75
78
|
std::rethrow_exception(__result.error());
|
|
76
79
|
}
|
|
77
80
|
auto __value = std::move(__result.value());
|
|
78
81
|
return __value;
|
|
79
82
|
}
|
|
80
|
-
inline void loadModel(const std::string& modelPath) override {
|
|
81
|
-
auto __result = _swiftPart.loadModel(modelPath);
|
|
82
|
-
if (__result.hasError()) [[unlikely]] {
|
|
83
|
-
std::rethrow_exception(__result.error());
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
83
|
inline std::string frameToBase64(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) override {
|
|
87
84
|
auto __result = _swiftPart.frameToBase64(frame);
|
|
88
85
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -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
|
+
}
|
|
@@ -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,8 +14,7 @@ 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
19
|
}
|
|
21
20
|
|
|
@@ -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
|
-
|
|
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)
|
|
134
137
|
} catch (let __error) {
|
|
135
138
|
let __exceptionPtr = __error.toCpp()
|
|
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_()
|
|
145
|
-
} catch (let __error) {
|
|
146
|
-
let __exceptionPtr = __error.toCpp()
|
|
147
|
-
return bridge.create_Result_void_(__exceptionPtr)
|
|
139
|
+
return bridge.create_Result_std__shared_ptr_HybridYoloModelSpec__(__exceptionPtr)
|
|
148
140
|
}
|
|
149
141
|
}
|
|
150
142
|
|
|
@@ -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
|