@nitro-mlkit/object-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/NitroMLKitObjects.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/objects/HybridObjectDetector.kt +102 -0
- package/android/src/main/kotlin/com/nitromlkit/objects/NitroMLKitObjectsPackage.kt +19 -0
- package/expo-module.config.json +9 -0
- package/ios/HybridObjectDetector.swift +125 -0
- package/nitro.json +16 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroMLKitObjects+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroMLKitObjects+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroMLKitObjectsOnLoad.cpp +54 -0
- package/nitrogen/generated/android/NitroMLKitObjectsOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JBatchObjectResult.hpp +95 -0
- package/nitrogen/generated/android/c++/JDetectedObject.hpp +88 -0
- package/nitrogen/generated/android/c++/JHybridObjectDetectorSpec.cpp +131 -0
- package/nitrogen/generated/android/c++/JHybridObjectDetectorSpec.hpp +65 -0
- package/nitrogen/generated/android/c++/JObjectLabel.hpp +65 -0
- package/nitrogen/generated/android/c++/JObjectRect.hpp +69 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/BatchObjectResult.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/DetectedObject.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/HybridObjectDetectorSpec.kt +63 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/NitroMLKitObjectsOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/ObjectLabel.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitromlkit/objects/ObjectRect.kt +66 -0
- package/nitrogen/generated/ios/NitroMLKitObjects+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Bridge.cpp +57 -0
- package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Bridge.hpp +236 -0
- package/nitrogen/generated/ios/NitroMLKitObjects-Swift-Cxx-Umbrella.hpp +59 -0
- package/nitrogen/generated/ios/NitroMLKitObjectsAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroMLKitObjectsAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridObjectDetectorSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridObjectDetectorSpecSwift.hpp +112 -0
- package/nitrogen/generated/ios/swift/BatchObjectResult.swift +63 -0
- package/nitrogen/generated/ios/swift/DetectedObject.swift +45 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_BatchObjectResult_.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_DetectedObject_.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridObjectDetectorSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridObjectDetectorSpec_cxx.swift +188 -0
- package/nitrogen/generated/ios/swift/ObjectLabel.swift +39 -0
- package/nitrogen/generated/ios/swift/ObjectRect.swift +44 -0
- package/nitrogen/generated/shared/c++/BatchObjectResult.hpp +99 -0
- package/nitrogen/generated/shared/c++/DetectedObject.hpp +96 -0
- package/nitrogen/generated/shared/c++/HybridObjectDetectorSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridObjectDetectorSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/ObjectLabel.hpp +91 -0
- package/nitrogen/generated/shared/c++/ObjectRect.hpp +95 -0
- package/package.json +53 -0
- package/src/index.ts +20 -0
- package/src/specs/ObjectDetector.nitro.ts +54 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ObjectRect.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 `ObjectRect`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias ObjectRect = margelo.nitro.mlkit.objects.ObjectRect
|
|
14
|
+
|
|
15
|
+
public extension ObjectRect {
|
|
16
|
+
private typealias bridge = margelo.nitro.mlkit.objects.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `ObjectRect`.
|
|
20
|
+
*/
|
|
21
|
+
init(x: Double, y: Double, width: Double, height: Double) {
|
|
22
|
+
self.init(x, y, width, height)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@inline(__always)
|
|
26
|
+
var x: Double {
|
|
27
|
+
return self.__x
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@inline(__always)
|
|
31
|
+
var y: Double {
|
|
32
|
+
return self.__y
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@inline(__always)
|
|
36
|
+
var width: Double {
|
|
37
|
+
return self.__width
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@inline(__always)
|
|
41
|
+
var height: Double {
|
|
42
|
+
return self.__height
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// BatchObjectResult.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 `DetectedObject` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::mlkit::objects { struct DetectedObject; }
|
|
33
|
+
|
|
34
|
+
#include "DetectedObject.hpp"
|
|
35
|
+
#include <vector>
|
|
36
|
+
#include <string>
|
|
37
|
+
#include <optional>
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::mlkit::objects {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (BatchObjectResult).
|
|
43
|
+
*/
|
|
44
|
+
struct BatchObjectResult final {
|
|
45
|
+
public:
|
|
46
|
+
double index SWIFT_PRIVATE;
|
|
47
|
+
std::vector<DetectedObject> objects SWIFT_PRIVATE;
|
|
48
|
+
bool success SWIFT_PRIVATE;
|
|
49
|
+
std::optional<std::string> error SWIFT_PRIVATE;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
BatchObjectResult() = default;
|
|
53
|
+
explicit BatchObjectResult(double index, std::vector<DetectedObject> objects, bool success, std::optional<std::string> error): index(index), objects(objects), success(success), error(error) {}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
friend bool operator==(const BatchObjectResult& lhs, const BatchObjectResult& rhs) = default;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace margelo::nitro::mlkit::objects
|
|
60
|
+
|
|
61
|
+
namespace margelo::nitro {
|
|
62
|
+
|
|
63
|
+
// C++ BatchObjectResult <> JS BatchObjectResult (object)
|
|
64
|
+
template <>
|
|
65
|
+
struct JSIConverter<margelo::nitro::mlkit::objects::BatchObjectResult> final {
|
|
66
|
+
static inline margelo::nitro::mlkit::objects::BatchObjectResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
67
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
68
|
+
return margelo::nitro::mlkit::objects::BatchObjectResult(
|
|
69
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index"))),
|
|
70
|
+
JSIConverter<std::vector<margelo::nitro::mlkit::objects::DetectedObject>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "objects"))),
|
|
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::objects::BatchObjectResult& 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, "objects"), JSIConverter<std::vector<margelo::nitro::mlkit::objects::DetectedObject>>::toJSI(runtime, arg.objects));
|
|
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::objects::DetectedObject>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "objects")))) 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,96 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// DetectedObject.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 `ObjectRect` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::mlkit::objects { struct ObjectRect; }
|
|
33
|
+
// Forward declaration of `ObjectLabel` to properly resolve imports.
|
|
34
|
+
namespace margelo::nitro::mlkit::objects { struct ObjectLabel; }
|
|
35
|
+
|
|
36
|
+
#include "ObjectRect.hpp"
|
|
37
|
+
#include "ObjectLabel.hpp"
|
|
38
|
+
#include <vector>
|
|
39
|
+
|
|
40
|
+
namespace margelo::nitro::mlkit::objects {
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A struct which can be represented as a JavaScript object (DetectedObject).
|
|
44
|
+
*/
|
|
45
|
+
struct DetectedObject final {
|
|
46
|
+
public:
|
|
47
|
+
ObjectRect bounds SWIFT_PRIVATE;
|
|
48
|
+
double trackingId SWIFT_PRIVATE;
|
|
49
|
+
std::vector<ObjectLabel> labels SWIFT_PRIVATE;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
DetectedObject() = default;
|
|
53
|
+
explicit DetectedObject(ObjectRect bounds, double trackingId, std::vector<ObjectLabel> labels): bounds(bounds), trackingId(trackingId), labels(labels) {}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
friend bool operator==(const DetectedObject& lhs, const DetectedObject& rhs) = default;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace margelo::nitro::mlkit::objects
|
|
60
|
+
|
|
61
|
+
namespace margelo::nitro {
|
|
62
|
+
|
|
63
|
+
// C++ DetectedObject <> JS DetectedObject (object)
|
|
64
|
+
template <>
|
|
65
|
+
struct JSIConverter<margelo::nitro::mlkit::objects::DetectedObject> final {
|
|
66
|
+
static inline margelo::nitro::mlkit::objects::DetectedObject fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
67
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
68
|
+
return margelo::nitro::mlkit::objects::DetectedObject(
|
|
69
|
+
JSIConverter<margelo::nitro::mlkit::objects::ObjectRect>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bounds"))),
|
|
70
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "trackingId"))),
|
|
71
|
+
JSIConverter<std::vector<margelo::nitro::mlkit::objects::ObjectLabel>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "labels")))
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::objects::DetectedObject& arg) {
|
|
75
|
+
jsi::Object obj(runtime);
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "bounds"), JSIConverter<margelo::nitro::mlkit::objects::ObjectRect>::toJSI(runtime, arg.bounds));
|
|
77
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "trackingId"), JSIConverter<double>::toJSI(runtime, arg.trackingId));
|
|
78
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "labels"), JSIConverter<std::vector<margelo::nitro::mlkit::objects::ObjectLabel>>::toJSI(runtime, arg.labels));
|
|
79
|
+
return obj;
|
|
80
|
+
}
|
|
81
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
82
|
+
if (!value.isObject()) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
jsi::Object obj = value.getObject(runtime);
|
|
86
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (!JSIConverter<margelo::nitro::mlkit::objects::ObjectRect>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bounds")))) return false;
|
|
90
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "trackingId")))) return false;
|
|
91
|
+
if (!JSIConverter<std::vector<margelo::nitro::mlkit::objects::ObjectLabel>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "labels")))) return false;
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridObjectDetectorSpec.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 "HybridObjectDetectorSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::mlkit::objects {
|
|
11
|
+
|
|
12
|
+
void HybridObjectDetectorSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("detect", &HybridObjectDetectorSpec::detect);
|
|
18
|
+
prototype.registerHybridMethod("detectBatch", &HybridObjectDetectorSpec::detectBatch);
|
|
19
|
+
prototype.registerHybridMethod("isAvailable", &HybridObjectDetectorSpec::isAvailable);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace margelo::nitro::mlkit::objects
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridObjectDetectorSpec.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 `DetectedObject` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::mlkit::objects { struct DetectedObject; }
|
|
18
|
+
// Forward declaration of `BatchObjectResult` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::mlkit::objects { struct BatchObjectResult; }
|
|
20
|
+
|
|
21
|
+
#include "DetectedObject.hpp"
|
|
22
|
+
#include <vector>
|
|
23
|
+
#include <NitroModules/Promise.hpp>
|
|
24
|
+
#include <string>
|
|
25
|
+
#include "BatchObjectResult.hpp"
|
|
26
|
+
|
|
27
|
+
namespace margelo::nitro::mlkit::objects {
|
|
28
|
+
|
|
29
|
+
using namespace margelo::nitro;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An abstract base class for `ObjectDetector`
|
|
33
|
+
* Inherit this class to create instances of `HybridObjectDetectorSpec` in C++.
|
|
34
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
35
|
+
* @example
|
|
36
|
+
* ```cpp
|
|
37
|
+
* class HybridObjectDetector: public HybridObjectDetectorSpec {
|
|
38
|
+
* public:
|
|
39
|
+
* HybridObjectDetector(...): HybridObject(TAG) { ... }
|
|
40
|
+
* // ...
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
class HybridObjectDetectorSpec: public virtual HybridObject {
|
|
45
|
+
public:
|
|
46
|
+
// Constructor
|
|
47
|
+
explicit HybridObjectDetectorSpec(): HybridObject(TAG) { }
|
|
48
|
+
|
|
49
|
+
// Destructor
|
|
50
|
+
~HybridObjectDetectorSpec() override = default;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Properties
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
// Methods
|
|
58
|
+
virtual std::shared_ptr<Promise<std::vector<DetectedObject>>> detect(const std::string& imageUri) = 0;
|
|
59
|
+
virtual std::shared_ptr<Promise<std::vector<BatchObjectResult>>> 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 = "ObjectDetector";
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace margelo::nitro::mlkit::objects
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ObjectLabel.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
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::mlkit::objects {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (ObjectLabel).
|
|
39
|
+
*/
|
|
40
|
+
struct ObjectLabel final {
|
|
41
|
+
public:
|
|
42
|
+
std::string text SWIFT_PRIVATE;
|
|
43
|
+
double confidence SWIFT_PRIVATE;
|
|
44
|
+
double index SWIFT_PRIVATE;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
ObjectLabel() = default;
|
|
48
|
+
explicit ObjectLabel(std::string text, double confidence, double index): text(text), confidence(confidence), index(index) {}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
friend bool operator==(const ObjectLabel& lhs, const ObjectLabel& rhs) = default;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
} // namespace margelo::nitro::mlkit::objects
|
|
55
|
+
|
|
56
|
+
namespace margelo::nitro {
|
|
57
|
+
|
|
58
|
+
// C++ ObjectLabel <> JS ObjectLabel (object)
|
|
59
|
+
template <>
|
|
60
|
+
struct JSIConverter<margelo::nitro::mlkit::objects::ObjectLabel> final {
|
|
61
|
+
static inline margelo::nitro::mlkit::objects::ObjectLabel fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
62
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
63
|
+
return margelo::nitro::mlkit::objects::ObjectLabel(
|
|
64
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text"))),
|
|
65
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence"))),
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index")))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::objects::ObjectLabel& arg) {
|
|
70
|
+
jsi::Object obj(runtime);
|
|
71
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "text"), JSIConverter<std::string>::toJSI(runtime, arg.text));
|
|
72
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "confidence"), JSIConverter<double>::toJSI(runtime, arg.confidence));
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "index"), JSIConverter<double>::toJSI(runtime, arg.index));
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
77
|
+
if (!value.isObject()) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
jsi::Object obj = value.getObject(runtime);
|
|
81
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))) return false;
|
|
85
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confidence")))) return false;
|
|
86
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "index")))) return false;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ObjectRect.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::objects {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (ObjectRect).
|
|
39
|
+
*/
|
|
40
|
+
struct ObjectRect final {
|
|
41
|
+
public:
|
|
42
|
+
double x SWIFT_PRIVATE;
|
|
43
|
+
double y SWIFT_PRIVATE;
|
|
44
|
+
double width SWIFT_PRIVATE;
|
|
45
|
+
double height SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
ObjectRect() = default;
|
|
49
|
+
explicit ObjectRect(double x, double y, double width, double height): x(x), y(y), width(width), height(height) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const ObjectRect& lhs, const ObjectRect& rhs) = default;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::mlkit::objects
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ ObjectRect <> JS ObjectRect (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::mlkit::objects::ObjectRect> final {
|
|
62
|
+
static inline margelo::nitro::mlkit::objects::ObjectRect fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::mlkit::objects::ObjectRect(
|
|
65
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))),
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))),
|
|
67
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
|
|
68
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlkit::objects::ObjectRect& arg) {
|
|
72
|
+
jsi::Object obj(runtime);
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter<double>::toJSI(runtime, arg.x));
|
|
74
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter<double>::toJSI(runtime, arg.y));
|
|
75
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
|
|
76
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
|
|
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, "x")))) return false;
|
|
88
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y")))) return false;
|
|
89
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
|
|
90
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
} // namespace margelo::nitro
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nitro-mlkit/object-detection",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "High-performance on-device object detection & tracking for React Native — Google ML Kit + Nitro. Native batch, bounding boxes + labels, zero bridge overhead.",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"codegen": "nitrogen",
|
|
9
|
+
"build": "tsc --noEmit"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react-native",
|
|
13
|
+
"nitro",
|
|
14
|
+
"mlkit",
|
|
15
|
+
"object-detection",
|
|
16
|
+
"object-tracking",
|
|
17
|
+
"machine-learning",
|
|
18
|
+
"on-device",
|
|
19
|
+
"expo"
|
|
20
|
+
],
|
|
21
|
+
"author": "pologonzalo",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/pologonzalo/react-native-nitro-mlkit",
|
|
26
|
+
"directory": "packages/object-detection"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"expo-modules-core": "*",
|
|
30
|
+
"react": ">=18",
|
|
31
|
+
"react-native": ">=0.76",
|
|
32
|
+
"react-native-nitro-modules": ">=0.20"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"expo-modules-core": "*",
|
|
36
|
+
"nitro-codegen": "*",
|
|
37
|
+
"react-native-nitro-modules": "*",
|
|
38
|
+
"typescript": "~5.9.0"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"src",
|
|
42
|
+
"ios/**/*.swift",
|
|
43
|
+
"android/src",
|
|
44
|
+
"android/build.gradle",
|
|
45
|
+
"android/CMakeLists.txt",
|
|
46
|
+
"expo-module.config.json",
|
|
47
|
+
"nitrogen/generated",
|
|
48
|
+
"*.podspec",
|
|
49
|
+
"nitro.json",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
]
|
|
53
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { type ObjectDetector } from "./specs/ObjectDetector.nitro";
|
|
2
|
+
export type {
|
|
3
|
+
BatchObjectResult,
|
|
4
|
+
DetectedObject,
|
|
5
|
+
ObjectLabel,
|
|
6
|
+
ObjectRect,
|
|
7
|
+
} from "./specs/ObjectDetector.nitro";
|
|
8
|
+
|
|
9
|
+
import { Platform } from "react-native";
|
|
10
|
+
import { requireOptionalNativeModule } from "expo-modules-core";
|
|
11
|
+
import { NitroModules } from "react-native-nitro-modules";
|
|
12
|
+
import type { ObjectDetector } from "./specs/ObjectDetector.nitro";
|
|
13
|
+
|
|
14
|
+
if (Platform.OS === "android") {
|
|
15
|
+
requireOptionalNativeModule("NitroMLKitObjects");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Get the shared ObjectDetector instance. */
|
|
19
|
+
export const NitroObjects =
|
|
20
|
+
NitroModules.createHybridObject<ObjectDetector>("ObjectDetector");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { HybridObject } from "react-native-nitro-modules";
|
|
2
|
+
|
|
3
|
+
/** Bounding box in image pixel coordinates. */
|
|
4
|
+
export interface ObjectRect {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** A classification label for a detected object. */
|
|
12
|
+
export interface ObjectLabel {
|
|
13
|
+
text: string;
|
|
14
|
+
confidence: number;
|
|
15
|
+
index: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A single detected (and optionally tracked + classified) object. */
|
|
19
|
+
export interface DetectedObject {
|
|
20
|
+
bounds: ObjectRect;
|
|
21
|
+
/** Tracking id across frames, or -1 if tracking is off / unavailable. */
|
|
22
|
+
trackingId: number;
|
|
23
|
+
labels: ObjectLabel[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Result of detecting objects in one image within a batch. */
|
|
27
|
+
export interface BatchObjectResult {
|
|
28
|
+
index: number;
|
|
29
|
+
objects: DetectedObject[];
|
|
30
|
+
success: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* On-device object detection & classification powered by MLKit.
|
|
36
|
+
* Detects multiple objects in a still image with bounding boxes and coarse
|
|
37
|
+
* category labels — all on-device, zero bridge overhead via Nitro.
|
|
38
|
+
*/
|
|
39
|
+
export interface ObjectDetector extends HybridObject<{
|
|
40
|
+
ios: "swift";
|
|
41
|
+
android: "kotlin";
|
|
42
|
+
}> {
|
|
43
|
+
/** Detect all objects in an image. */
|
|
44
|
+
detect(imageUri: string): Promise<DetectedObject[]>;
|
|
45
|
+
|
|
46
|
+
/** Detect objects across many images in parallel (one native call). */
|
|
47
|
+
detectBatch(
|
|
48
|
+
imageUris: string[],
|
|
49
|
+
concurrency: number,
|
|
50
|
+
): Promise<BatchObjectResult[]>;
|
|
51
|
+
|
|
52
|
+
/** Whether object detection is available on this device. */
|
|
53
|
+
isAvailable(): boolean;
|
|
54
|
+
}
|