react-native-yolo 0.0.5 → 0.0.8
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/Yolo.podspec +3 -0
- package/android/src/main/java/com/yolo/HybridYolo.kt +12 -235
- package/android/src/main/java/com/yolo/HybridYoloModel.kt +259 -0
- package/android/src/main/java/com/yolo/utils/BitmapOrientationFixer.kt +8 -1
- package/ios/HybridYolo.swift +52 -10
- package/ios/HybridYoloModel.swift +250 -0
- package/ios/Loader/YoloModelLoader.swift +139 -0
- package/ios/Utils/BitmapOrientationFixer.swift +64 -0
- package/ios/Utils/ContextProvider.swift +45 -0
- package/ios/Utils/FrameJpegConverter.swift +41 -0
- package/ios/Utils/FrameValidator.swift +40 -0
- package/ios/Utils/Nv12JpegEncoder.swift +58 -0
- package/ios/Utils/Yuv420ToNv12Converter.swift +71 -0
- 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
|
@@ -14,18 +14,23 @@ namespace margelo::nitro::yolo { struct BoundingBox; }
|
|
|
14
14
|
namespace margelo::nitro::yolo { struct Detection; }
|
|
15
15
|
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
16
16
|
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
17
|
+
// Forward declaration of `HybridYoloModelSpec` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::yolo { class HybridYoloModelSpec; }
|
|
17
19
|
// Forward declaration of `HybridYoloSpec` to properly resolve imports.
|
|
18
20
|
namespace margelo::nitro::yolo { class HybridYoloSpec; }
|
|
19
21
|
|
|
20
22
|
// Forward declarations of Swift defined types
|
|
21
23
|
// Forward declaration of `HybridFrameSpec_cxx` to properly resolve imports.
|
|
22
24
|
namespace VisionCamera { class HybridFrameSpec_cxx; }
|
|
25
|
+
// Forward declaration of `HybridYoloModelSpec_cxx` to properly resolve imports.
|
|
26
|
+
namespace Yolo { class HybridYoloModelSpec_cxx; }
|
|
23
27
|
// Forward declaration of `HybridYoloSpec_cxx` to properly resolve imports.
|
|
24
28
|
namespace Yolo { class HybridYoloSpec_cxx; }
|
|
25
29
|
|
|
26
30
|
// Include C++ defined types
|
|
27
31
|
#include "BoundingBox.hpp"
|
|
28
32
|
#include "Detection.hpp"
|
|
33
|
+
#include "HybridYoloModelSpec.hpp"
|
|
29
34
|
#include "HybridYoloSpec.hpp"
|
|
30
35
|
#include <NitroModules/Result.hpp>
|
|
31
36
|
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
@@ -40,6 +45,17 @@ namespace Yolo { class HybridYoloSpec_cxx; }
|
|
|
40
45
|
*/
|
|
41
46
|
namespace margelo::nitro::yolo::bridge::swift {
|
|
42
47
|
|
|
48
|
+
// pragma MARK: std::vector<Detection>
|
|
49
|
+
/**
|
|
50
|
+
* Specialized version of `std::vector<Detection>`.
|
|
51
|
+
*/
|
|
52
|
+
using std__vector_Detection_ = std::vector<Detection>;
|
|
53
|
+
inline std::vector<Detection> create_std__vector_Detection_(size_t size) noexcept {
|
|
54
|
+
std::vector<Detection> vector;
|
|
55
|
+
vector.reserve(size);
|
|
56
|
+
return vector;
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
// pragma MARK: std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>
|
|
44
60
|
/**
|
|
45
61
|
* Specialized version of `std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>`.
|
|
@@ -52,15 +68,34 @@ namespace margelo::nitro::yolo::bridge::swift {
|
|
|
52
68
|
using std__weak_ptr_margelo__nitro__camera__HybridFrameSpec_ = std::weak_ptr<margelo::nitro::camera::HybridFrameSpec>;
|
|
53
69
|
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
70
|
|
|
55
|
-
// pragma MARK: std::
|
|
71
|
+
// pragma MARK: std::shared_ptr<HybridYoloModelSpec>
|
|
56
72
|
/**
|
|
57
|
-
* Specialized version of `std::
|
|
73
|
+
* Specialized version of `std::shared_ptr<HybridYoloModelSpec>`.
|
|
58
74
|
*/
|
|
59
|
-
using
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
using std__shared_ptr_HybridYoloModelSpec_ = std::shared_ptr<HybridYoloModelSpec>;
|
|
76
|
+
std::shared_ptr<HybridYoloModelSpec> create_std__shared_ptr_HybridYoloModelSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
|
|
77
|
+
void* NON_NULL get_std__shared_ptr_HybridYoloModelSpec_(std__shared_ptr_HybridYoloModelSpec_ cppType);
|
|
78
|
+
|
|
79
|
+
// pragma MARK: std::weak_ptr<HybridYoloModelSpec>
|
|
80
|
+
using std__weak_ptr_HybridYoloModelSpec_ = std::weak_ptr<HybridYoloModelSpec>;
|
|
81
|
+
inline std__weak_ptr_HybridYoloModelSpec_ weakify_std__shared_ptr_HybridYoloModelSpec_(const std::shared_ptr<HybridYoloModelSpec>& strong) noexcept { return strong; }
|
|
82
|
+
|
|
83
|
+
// pragma MARK: Result<std::vector<Detection>>
|
|
84
|
+
using Result_std__vector_Detection__ = Result<std::vector<Detection>>;
|
|
85
|
+
inline Result_std__vector_Detection__ create_Result_std__vector_Detection__(const std::vector<Detection>& value) noexcept {
|
|
86
|
+
return Result<std::vector<Detection>>::withValue(value);
|
|
87
|
+
}
|
|
88
|
+
inline Result_std__vector_Detection__ create_Result_std__vector_Detection__(const std::exception_ptr& error) noexcept {
|
|
89
|
+
return Result<std::vector<Detection>>::withError(error);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// pragma MARK: Result<void>
|
|
93
|
+
using Result_void_ = Result<void>;
|
|
94
|
+
inline Result_void_ create_Result_void_() noexcept {
|
|
95
|
+
return Result<void>::withValue();
|
|
96
|
+
}
|
|
97
|
+
inline Result_void_ create_Result_void_(const std::exception_ptr& error) noexcept {
|
|
98
|
+
return Result<void>::withError(error);
|
|
64
99
|
}
|
|
65
100
|
|
|
66
101
|
// pragma MARK: std::shared_ptr<HybridYoloSpec>
|
|
@@ -75,22 +110,13 @@ namespace margelo::nitro::yolo::bridge::swift {
|
|
|
75
110
|
using std__weak_ptr_HybridYoloSpec_ = std::weak_ptr<HybridYoloSpec>;
|
|
76
111
|
inline std__weak_ptr_HybridYoloSpec_ weakify_std__shared_ptr_HybridYoloSpec_(const std::shared_ptr<HybridYoloSpec>& strong) noexcept { return strong; }
|
|
77
112
|
|
|
78
|
-
// pragma MARK: Result<
|
|
79
|
-
using
|
|
80
|
-
inline
|
|
81
|
-
return Result<
|
|
113
|
+
// pragma MARK: Result<std::shared_ptr<HybridYoloModelSpec>>
|
|
114
|
+
using Result_std__shared_ptr_HybridYoloModelSpec__ = Result<std::shared_ptr<HybridYoloModelSpec>>;
|
|
115
|
+
inline Result_std__shared_ptr_HybridYoloModelSpec__ create_Result_std__shared_ptr_HybridYoloModelSpec__(const std::shared_ptr<HybridYoloModelSpec>& value) noexcept {
|
|
116
|
+
return Result<std::shared_ptr<HybridYoloModelSpec>>::withValue(value);
|
|
82
117
|
}
|
|
83
|
-
inline
|
|
84
|
-
return Result<
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// pragma MARK: Result<void>
|
|
88
|
-
using Result_void_ = Result<void>;
|
|
89
|
-
inline Result_void_ create_Result_void_() noexcept {
|
|
90
|
-
return Result<void>::withValue();
|
|
91
|
-
}
|
|
92
|
-
inline Result_void_ create_Result_void_(const std::exception_ptr& error) noexcept {
|
|
93
|
-
return Result<void>::withError(error);
|
|
118
|
+
inline Result_std__shared_ptr_HybridYoloModelSpec__ create_Result_std__shared_ptr_HybridYoloModelSpec__(const std::exception_ptr& error) noexcept {
|
|
119
|
+
return Result<std::shared_ptr<HybridYoloModelSpec>>::withError(error);
|
|
94
120
|
}
|
|
95
121
|
|
|
96
122
|
// pragma MARK: Result<std::string>
|
|
@@ -101,14 +127,5 @@ namespace margelo::nitro::yolo::bridge::swift {
|
|
|
101
127
|
inline Result_std__string_ create_Result_std__string_(const std::exception_ptr& error) noexcept {
|
|
102
128
|
return Result<std::string>::withError(error);
|
|
103
129
|
}
|
|
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
|
-
}
|
|
113
130
|
|
|
114
131
|
} // namespace margelo::nitro::yolo::bridge::swift
|
|
@@ -14,12 +14,15 @@ namespace margelo::nitro::yolo { struct BoundingBox; }
|
|
|
14
14
|
namespace margelo::nitro::yolo { struct Detection; }
|
|
15
15
|
// Forward declaration of `HybridFrameSpec` to properly resolve imports.
|
|
16
16
|
namespace margelo::nitro::camera { class HybridFrameSpec; }
|
|
17
|
+
// Forward declaration of `HybridYoloModelSpec` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::yolo { class HybridYoloModelSpec; }
|
|
17
19
|
// Forward declaration of `HybridYoloSpec` to properly resolve imports.
|
|
18
20
|
namespace margelo::nitro::yolo { class HybridYoloSpec; }
|
|
19
21
|
|
|
20
22
|
// Include C++ defined types
|
|
21
23
|
#include "BoundingBox.hpp"
|
|
22
24
|
#include "Detection.hpp"
|
|
25
|
+
#include "HybridYoloModelSpec.hpp"
|
|
23
26
|
#include "HybridYoloSpec.hpp"
|
|
24
27
|
#include <NitroModules/Result.hpp>
|
|
25
28
|
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
@@ -40,6 +43,8 @@ namespace margelo::nitro::yolo { class HybridYoloSpec; }
|
|
|
40
43
|
// Forward declarations of Swift defined types
|
|
41
44
|
// Forward declaration of `HybridFrameSpec_cxx` to properly resolve imports.
|
|
42
45
|
namespace VisionCamera { class HybridFrameSpec_cxx; }
|
|
46
|
+
// Forward declaration of `HybridYoloModelSpec_cxx` to properly resolve imports.
|
|
47
|
+
namespace Yolo { class HybridYoloModelSpec_cxx; }
|
|
43
48
|
// Forward declaration of `HybridYoloSpec_cxx` to properly resolve imports.
|
|
44
49
|
namespace Yolo { class HybridYoloSpec_cxx; }
|
|
45
50
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridYoloModelSpecSwift.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 "HybridYoloModelSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::yolo {
|
|
11
|
+
} // namespace margelo::nitro::yolo
|
|
@@ -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,19 +12,15 @@
|
|
|
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
|
-
// 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; }
|
|
21
19
|
|
|
22
|
-
#include <string>
|
|
23
20
|
#include <memory>
|
|
21
|
+
#include "HybridYoloModelSpec.hpp"
|
|
22
|
+
#include <string>
|
|
24
23
|
#include <VisionCamera/HybridFrameSpec.hpp>
|
|
25
|
-
#include "Detection.hpp"
|
|
26
|
-
#include <vector>
|
|
27
|
-
#include "BoundingBox.hpp"
|
|
28
24
|
|
|
29
25
|
#include "Yolo-Swift-Cxx-Umbrella.hpp"
|
|
30
26
|
|
|
@@ -76,20 +72,14 @@ namespace margelo::nitro::yolo {
|
|
|
76
72
|
|
|
77
73
|
public:
|
|
78
74
|
// Methods
|
|
79
|
-
inline
|
|
80
|
-
auto __result = _swiftPart.
|
|
75
|
+
inline std::shared_ptr<HybridYoloModelSpec> loadModel(const std::string& modelPath) override {
|
|
76
|
+
auto __result = _swiftPart.loadModel(modelPath);
|
|
81
77
|
if (__result.hasError()) [[unlikely]] {
|
|
82
78
|
std::rethrow_exception(__result.error());
|
|
83
79
|
}
|
|
84
80
|
auto __value = std::move(__result.value());
|
|
85
81
|
return __value;
|
|
86
82
|
}
|
|
87
|
-
inline void loadModel(const std::string& modelPath) override {
|
|
88
|
-
auto __result = _swiftPart.loadModel(modelPath);
|
|
89
|
-
if (__result.hasError()) [[unlikely]] {
|
|
90
|
-
std::rethrow_exception(__result.error());
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
83
|
inline std::string frameToBase64(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) override {
|
|
94
84
|
auto __result = _swiftPart.frameToBase64(frame);
|
|
95
85
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -98,14 +88,6 @@ namespace margelo::nitro::yolo {
|
|
|
98
88
|
auto __value = std::move(__result.value());
|
|
99
89
|
return __value;
|
|
100
90
|
}
|
|
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
|
-
}
|
|
109
91
|
|
|
110
92
|
private:
|
|
111
93
|
Yolo::HybridYoloSpec_cxx _swiftPart;
|
|
@@ -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
|