react-native-yolo 0.0.3 → 0.0.5

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.
Files changed (50) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +51 -51
  3. package/Yolo.podspec +31 -31
  4. package/android/CMakeLists.txt +35 -32
  5. package/android/build.gradle +154 -152
  6. package/android/fix-prefab.gradle +50 -50
  7. package/android/gradle.properties +5 -5
  8. package/android/src/main/AndroidManifest.xml +3 -2
  9. package/android/src/main/cpp/cpp-adapter.cpp +8 -8
  10. package/android/src/main/java/com/yolo/HybridYolo.kt +265 -42
  11. package/android/src/main/java/com/yolo/YoloPackage.kt +20 -20
  12. package/android/src/main/java/com/yolo/loader/YoloModelLoader.kt +31 -0
  13. package/android/src/main/java/com/yolo/utils/BitmapOrientationFixer.kt +56 -0
  14. package/android/src/main/java/com/yolo/utils/FrameJpegConverter.kt +27 -0
  15. package/android/src/main/java/com/yolo/utils/FrameValidator.kt +29 -0
  16. package/android/src/main/java/com/yolo/utils/Nv21JpegEncoder.kt +34 -0
  17. package/android/src/main/java/com/yolo/utils/Yuv420ToNv21Converter.kt +62 -0
  18. package/ios/Bridge.h +8 -8
  19. package/ios/HybridYolo.swift +14 -14
  20. package/lib/commonjs/index.js +10 -1
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/module/index.js +10 -1
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/typescript/src/index.d.ts +3 -1
  25. package/lib/typescript/src/index.d.ts.map +1 -1
  26. package/lib/typescript/src/specs/yolo.nitro.d.ts +15 -0
  27. package/lib/typescript/src/specs/yolo.nitro.d.ts.map +1 -1
  28. package/nitro.json +29 -29
  29. package/nitrogen/generated/android/c++/JBoundingBox.hpp +69 -0
  30. package/nitrogen/generated/android/c++/JDetection.hpp +66 -0
  31. package/nitrogen/generated/android/c++/JHybridYoloSpec.cpp +33 -1
  32. package/nitrogen/generated/android/c++/JHybridYoloSpec.hpp +2 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/BoundingBox.kt +66 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/Detection.kt +61 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/HybridYoloSpec.kt +9 -0
  36. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.cpp +11 -0
  37. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.hpp +54 -0
  38. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Umbrella.hpp +12 -0
  39. package/nitrogen/generated/ios/c++/HybridYoloSpecSwift.hpp +27 -1
  40. package/nitrogen/generated/ios/swift/BoundingBox.swift +44 -0
  41. package/nitrogen/generated/ios/swift/Detection.swift +39 -0
  42. package/nitrogen/generated/ios/swift/HybridYoloSpec.swift +3 -0
  43. package/nitrogen/generated/ios/swift/HybridYoloSpec_cxx.swift +39 -0
  44. package/nitrogen/generated/shared/c++/BoundingBox.hpp +95 -0
  45. package/nitrogen/generated/shared/c++/Detection.hpp +92 -0
  46. package/nitrogen/generated/shared/c++/HybridYoloSpec.cpp +2 -0
  47. package/nitrogen/generated/shared/c++/HybridYoloSpec.hpp +10 -1
  48. package/package.json +127 -122
  49. package/src/index.ts +11 -11
  50. package/src/specs/yolo.nitro.ts +24 -7
@@ -0,0 +1,62 @@
1
+ package com.yolo.utils
2
+
3
+ import com.margelo.nitro.camera.HybridFrameSpec
4
+ import kotlin.math.roundToInt
5
+ import android.util.Log
6
+
7
+ object Yuv420ToNv21Converter {
8
+ fun convert(frame: HybridFrameSpec, width: Int, height: Int): ByteArray {
9
+
10
+ val planes = frame.getPlanes()
11
+
12
+ val yPlane = planes[0]
13
+ val uPlane = planes[1]
14
+ val vPlane = planes[2]
15
+
16
+ val yBytes = yPlane.getPixelBuffer().toByteArray()
17
+ val uBytes = uPlane.getPixelBuffer().toByteArray()
18
+ val vBytes = vPlane.getPixelBuffer().toByteArray()
19
+
20
+ val yRowStride = yPlane.bytesPerRow.roundToInt()
21
+ val uRowStride = uPlane.bytesPerRow.roundToInt()
22
+ val vRowStride = vPlane.bytesPerRow.roundToInt()
23
+
24
+ val ySize = width * height
25
+ val uvSize = width * height / 2
26
+ val nv21 = ByteArray(ySize + uvSize)
27
+
28
+ var dst = 0
29
+
30
+ for (row in 0 until height) {
31
+ val src = row * yRowStride
32
+ if (src + width > yBytes.size) break
33
+
34
+ System.arraycopy(yBytes, src, nv21, dst, width)
35
+ dst += width
36
+ }
37
+
38
+ val chromaWidth = width / 2
39
+ val chromaHeight = height / 2
40
+
41
+ var uvDst = ySize
42
+
43
+ for (row in 0 until chromaHeight) {
44
+ for (col in 0 until chromaWidth) {
45
+ val uIndex = row * uRowStride + col * 2
46
+ val vIndex = row * vRowStride + col * 2
47
+
48
+ if (
49
+ uIndex >= uBytes.size ||
50
+ vIndex >= vBytes.size ||
51
+ uvDst + 1 >= nv21.size
52
+ ) {
53
+ return nv21
54
+ }
55
+
56
+ nv21[uvDst++] = vBytes[vIndex]
57
+ nv21[uvDst++] = uBytes[uIndex]
58
+ }
59
+ }
60
+ return nv21
61
+ }
62
+ }
package/ios/Bridge.h CHANGED
@@ -1,8 +1,8 @@
1
- //
2
- // Bridge.h
3
- // yolo
4
- //
5
- // Created by Khaoula-Ghalimi on 22/06/2026
6
- //
7
-
8
- #pragma once
1
+ //
2
+ // Bridge.h
3
+ // yolo
4
+ //
5
+ // Created by Khaoula-Ghalimi on 22/06/2026
6
+ //
7
+
8
+ #pragma once
@@ -1,14 +1,14 @@
1
- //
2
- // HybridYolo.swift
3
- // Pods
4
- //
5
- // Created by Khaoula-Ghalimi on 22/06/2026.
6
- //
7
-
8
- import Foundation
9
-
10
- class HybridYolo: HybridYoloSpec {
11
- func sum(num1: Double, num2: Double) throws -> Double {
12
- return num1 + num2
13
- }
14
- }
1
+ //
2
+ // HybridYolo.swift
3
+ // Pods
4
+ //
5
+ // Created by Khaoula-Ghalimi on 22/06/2026.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ class HybridYolo: HybridYoloSpec {
11
+ func sum(num1: Double, num2: Double) throws -> Double {
12
+ return num1 + num2
13
+ }
14
+ }
@@ -5,5 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Yolo = void 0;
7
7
  var _reactNativeNitroModules = require("react-native-nitro-modules");
8
- const Yolo = exports.Yolo = _reactNativeNitroModules.NitroModules.createHybridObject('Yolo');
8
+ var _reactNative = require("react-native");
9
+ const NativeYolo = _reactNativeNitroModules.NitroModules.createHybridObject('Yolo');
10
+ const Yolo = exports.Yolo = Object.assign(NativeYolo, {
11
+ loadModelTest(modelAssetId) {
12
+ const {
13
+ uri
14
+ } = _reactNative.Image.resolveAssetSource(modelAssetId);
15
+ return NativeYolo.loadModel(uri);
16
+ }
17
+ });
9
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNativeNitroModules","require","Yolo","exports","NitroModules","createHybridObject"],"sourceRoot":"..\\..\\src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAGO,MAAMC,IAAI,GAAAC,OAAA,CAAAD,IAAA,GACfE,qCAAY,CAACC,kBAAkB,CAAW,MAAM,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNativeNitroModules","require","_reactNative","NativeYolo","NitroModules","createHybridObject","Yolo","exports","Object","assign","loadModelTest","modelAssetId","uri","Image","resolveAssetSource","loadModel"],"sourceRoot":"..\\..\\src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAEA,MAAME,UAAU,GAAGC,qCAAY,CAACC,kBAAkB,CAAW,MAAM,CAAC;AAE7D,MAAMC,IAAI,GAAAC,OAAA,CAAAD,IAAA,GAAGE,MAAM,CAACC,MAAM,CAACN,UAAU,EAAE;EAC5CO,aAAaA,CAACC,YAAoB,EAAC;IACjC,MAAM;MAAEC;IAAI,CAAC,GAAGC,kBAAK,CAACC,kBAAkB,CAACH,YAAY,CAAC;IACtD,OAAOR,UAAU,CAACY,SAAS,CAACH,GAAG,CAAC;EAClC;AACF,CAAC,CAAC","ignoreList":[]}
@@ -1,5 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  import { NitroModules } from 'react-native-nitro-modules';
4
- export const Yolo = NitroModules.createHybridObject('Yolo');
4
+ import { Image } from 'react-native';
5
+ const NativeYolo = NitroModules.createHybridObject('Yolo');
6
+ export const Yolo = Object.assign(NativeYolo, {
7
+ loadModelTest(modelAssetId) {
8
+ const {
9
+ uri
10
+ } = Image.resolveAssetSource(modelAssetId);
11
+ return NativeYolo.loadModel(uri);
12
+ }
13
+ });
5
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NitroModules","Yolo","createHybridObject"],"sourceRoot":"..\\..\\src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,OAAO,MAAMC,IAAI,GACfD,YAAY,CAACE,kBAAkB,CAAW,MAAM,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NitroModules","Image","NativeYolo","createHybridObject","Yolo","Object","assign","loadModelTest","modelAssetId","uri","resolveAssetSource","loadModel"],"sourceRoot":"..\\..\\src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAEzD,SAASC,KAAK,QAAQ,cAAc;AAEpC,MAAMC,UAAU,GAAGF,YAAY,CAACG,kBAAkB,CAAW,MAAM,CAAC;AAEpE,OAAO,MAAMC,IAAI,GAAGC,MAAM,CAACC,MAAM,CAACJ,UAAU,EAAE;EAC5CK,aAAaA,CAACC,YAAoB,EAAC;IACjC,MAAM;MAAEC;IAAI,CAAC,GAAGR,KAAK,CAACS,kBAAkB,CAACF,YAAY,CAAC;IACtD,OAAON,UAAU,CAACS,SAAS,CAACF,GAAG,CAAC;EAClC;AACF,CAAC,CAAC","ignoreList":[]}
@@ -1,3 +1,5 @@
1
1
  import type { Yolo as YoloSpec } from './specs/yolo.nitro';
2
- export declare const Yolo: YoloSpec;
2
+ export declare const Yolo: YoloSpec & {
3
+ loadModelTest(modelAssetId: number): void;
4
+ };
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE1D,eAAO,MAAM,IAAI,UACkC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAK1D,eAAO,MAAM,IAAI;gCACa,MAAM;CAIlC,CAAA"}
@@ -1,9 +1,24 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { Frame } from 'react-native-vision-camera';
3
+ type Detection = {
4
+ classId: number;
5
+ score: number;
6
+ boundingBox: BoundingBox;
7
+ };
8
+ type BoundingBox = {
9
+ x1: number;
10
+ y1: number;
11
+ x2: number;
12
+ y2: number;
13
+ };
2
14
  export interface Yolo extends HybridObject<{
3
15
  ios: 'swift';
4
16
  android: 'kotlin';
5
17
  }> {
6
18
  sum(num1: number, num2: number): number;
7
19
  loadModel(modelPath: string): void;
20
+ frameToBase64(frame: Frame): string;
21
+ detect(frame: Frame): Detection[];
8
22
  }
23
+ export {};
9
24
  //# sourceMappingURL=yolo.nitro.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"yolo.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/yolo.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,WAAW,IAAK,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IAC7E,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACvC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CACnC"}
1
+ {"version":3,"file":"yolo.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/yolo.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAEvD,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AACD,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,WAAW,IAAK,SAAQ,YAAY,CAAC;IACzC,GAAG,EAAE,OAAO,CAAA;IACZ,OAAO,EAAE,QAAQ,CAAA;CAClB,CAAC;IACA,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACvC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAA;IACnC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,CAAA;CAClC"}
package/nitro.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "$schema": "https://nitro.margelo.com/nitro.schema.json",
3
- "cxxNamespace": [
4
- "yolo"
5
- ],
6
- "ios": {
7
- "iosModuleName": "Yolo"
8
- },
9
- "android": {
10
- "androidNamespace": [
11
- "yolo"
12
- ],
13
- "androidCxxLibName": "Yolo"
14
- },
15
- "autolinking": {
16
- "Yolo": {
17
- "ios": {
18
- "language": "swift",
19
- "implementationClassName": "HybridYolo"
20
- },
21
- "android": {
22
- "language": "kotlin",
23
- "implementationClassName": "HybridYolo"
24
- }
25
- }
26
- },
27
- "ignorePaths": [
28
- "**/node_modules"
29
- ]
1
+ {
2
+ "$schema": "https://nitro.margelo.com/nitro.schema.json",
3
+ "cxxNamespace": [
4
+ "yolo"
5
+ ],
6
+ "ios": {
7
+ "iosModuleName": "Yolo"
8
+ },
9
+ "android": {
10
+ "androidNamespace": [
11
+ "yolo"
12
+ ],
13
+ "androidCxxLibName": "Yolo"
14
+ },
15
+ "autolinking": {
16
+ "Yolo": {
17
+ "ios": {
18
+ "language": "swift",
19
+ "implementationClassName": "HybridYolo"
20
+ },
21
+ "android": {
22
+ "language": "kotlin",
23
+ "implementationClassName": "HybridYolo"
24
+ }
25
+ }
26
+ },
27
+ "ignorePaths": [
28
+ "**/node_modules"
29
+ ]
30
30
  }
@@ -0,0 +1,69 @@
1
+ ///
2
+ /// JBoundingBox.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 <fbjni/fbjni.h>
11
+ #include "BoundingBox.hpp"
12
+
13
+
14
+
15
+ namespace margelo::nitro::yolo {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "BoundingBox" and the the Kotlin data class "BoundingBox".
21
+ */
22
+ struct JBoundingBox final: public jni::JavaClass<JBoundingBox> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/yolo/BoundingBox;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct BoundingBox by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ BoundingBox toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldX1 = clazz->getField<double>("x1");
35
+ double x1 = this->getFieldValue(fieldX1);
36
+ static const auto fieldY1 = clazz->getField<double>("y1");
37
+ double y1 = this->getFieldValue(fieldY1);
38
+ static const auto fieldX2 = clazz->getField<double>("x2");
39
+ double x2 = this->getFieldValue(fieldX2);
40
+ static const auto fieldY2 = clazz->getField<double>("y2");
41
+ double y2 = this->getFieldValue(fieldY2);
42
+ return BoundingBox(
43
+ x1,
44
+ y1,
45
+ x2,
46
+ y2
47
+ );
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
53
+ */
54
+ [[maybe_unused]]
55
+ static jni::local_ref<JBoundingBox::javaobject> fromCpp(const BoundingBox& value) {
56
+ using JSignature = JBoundingBox(double, double, double, double);
57
+ static const auto clazz = javaClassStatic();
58
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
59
+ return create(
60
+ clazz,
61
+ value.x1,
62
+ value.y1,
63
+ value.x2,
64
+ value.y2
65
+ );
66
+ }
67
+ };
68
+
69
+ } // namespace margelo::nitro::yolo
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// JDetection.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 <fbjni/fbjni.h>
11
+ #include "Detection.hpp"
12
+
13
+ #include "BoundingBox.hpp"
14
+ #include "JBoundingBox.hpp"
15
+
16
+ namespace margelo::nitro::yolo {
17
+
18
+ using namespace facebook;
19
+
20
+ /**
21
+ * The C++ JNI bridge between the C++ struct "Detection" and the the Kotlin data class "Detection".
22
+ */
23
+ struct JDetection final: public jni::JavaClass<JDetection> {
24
+ public:
25
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/yolo/Detection;";
26
+
27
+ public:
28
+ /**
29
+ * Convert this Java/Kotlin-based struct to the C++ struct Detection by copying all values to C++.
30
+ */
31
+ [[maybe_unused]]
32
+ [[nodiscard]]
33
+ Detection toCpp() const {
34
+ static const auto clazz = javaClassStatic();
35
+ static const auto fieldClassId = clazz->getField<double>("classId");
36
+ double classId = this->getFieldValue(fieldClassId);
37
+ static const auto fieldScore = clazz->getField<double>("score");
38
+ double score = this->getFieldValue(fieldScore);
39
+ static const auto fieldBoundingBox = clazz->getField<JBoundingBox>("boundingBox");
40
+ jni::local_ref<JBoundingBox> boundingBox = this->getFieldValue(fieldBoundingBox);
41
+ return Detection(
42
+ classId,
43
+ score,
44
+ boundingBox->toCpp()
45
+ );
46
+ }
47
+
48
+ public:
49
+ /**
50
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
51
+ */
52
+ [[maybe_unused]]
53
+ static jni::local_ref<JDetection::javaobject> fromCpp(const Detection& value) {
54
+ using JSignature = JDetection(double, double, jni::alias_ref<JBoundingBox>);
55
+ static const auto clazz = javaClassStatic();
56
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
57
+ return create(
58
+ clazz,
59
+ value.classId,
60
+ value.score,
61
+ JBoundingBox::fromCpp(value.boundingBox)
62
+ );
63
+ }
64
+ };
65
+
66
+ } // namespace margelo::nitro::yolo
@@ -7,9 +7,22 @@
7
7
 
8
8
  #include "JHybridYoloSpec.hpp"
9
9
 
10
-
10
+ // Forward declaration of `Detection` to properly resolve imports.
11
+ namespace margelo::nitro::yolo { struct Detection; }
12
+ // Forward declaration of `BoundingBox` to properly resolve imports.
13
+ namespace margelo::nitro::yolo { struct BoundingBox; }
14
+ // Forward declaration of `HybridFrameSpec` to properly resolve imports.
15
+ namespace margelo::nitro::camera { class HybridFrameSpec; }
11
16
 
12
17
  #include <string>
18
+ #include "Detection.hpp"
19
+ #include <vector>
20
+ #include "JDetection.hpp"
21
+ #include "BoundingBox.hpp"
22
+ #include "JBoundingBox.hpp"
23
+ #include <memory>
24
+ #include <VisionCamera/HybridFrameSpec.hpp>
25
+ #include <VisionCamera/JHybridFrameSpec.hpp>
13
26
 
14
27
  namespace margelo::nitro::yolo {
15
28
 
@@ -53,5 +66,24 @@ namespace margelo::nitro::yolo {
53
66
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* modelPath */)>("loadModel");
54
67
  method(_javaPart, jni::make_jstring(modelPath));
55
68
  }
69
+ std::string JHybridYoloSpec::frameToBase64(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) {
70
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>(jni::alias_ref<margelo::nitro::camera::JHybridFrameSpec::JavaPart> /* frame */)>("frameToBase64");
71
+ auto __result = method(_javaPart, std::dynamic_pointer_cast<margelo::nitro::camera::JHybridFrameSpec>(frame)->getJavaPart());
72
+ return __result->toStdString();
73
+ }
74
+ std::vector<Detection> JHybridYoloSpec::detect(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) {
75
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JDetection>>(jni::alias_ref<margelo::nitro::camera::JHybridFrameSpec::JavaPart> /* frame */)>("detect");
76
+ auto __result = method(_javaPart, std::dynamic_pointer_cast<margelo::nitro::camera::JHybridFrameSpec>(frame)->getJavaPart());
77
+ return [&](auto&& __input) {
78
+ size_t __size = __input->size();
79
+ std::vector<Detection> __vector;
80
+ __vector.reserve(__size);
81
+ for (size_t __i = 0; __i < __size; __i++) {
82
+ auto __element = __input->getElement(__i);
83
+ __vector.push_back(__element->toCpp());
84
+ }
85
+ return __vector;
86
+ }(__result);
87
+ }
56
88
 
57
89
  } // namespace margelo::nitro::yolo
@@ -56,6 +56,8 @@ namespace margelo::nitro::yolo {
56
56
  // Methods
57
57
  double sum(double num1, double num2) override;
58
58
  void loadModel(const std::string& modelPath) override;
59
+ std::string frameToBase64(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) override;
60
+ std::vector<Detection> detect(const std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>& frame) override;
59
61
 
60
62
  private:
61
63
  jni::global_ref<JHybridYoloSpec::JavaPart> _javaPart;
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// BoundingBox.kt
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
+ package com.margelo.nitro.yolo
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "BoundingBox".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class BoundingBox(
21
+ @DoNotStrip
22
+ @Keep
23
+ val x1: Double,
24
+ @DoNotStrip
25
+ @Keep
26
+ val y1: Double,
27
+ @DoNotStrip
28
+ @Keep
29
+ val x2: Double,
30
+ @DoNotStrip
31
+ @Keep
32
+ val y2: Double
33
+ ) {
34
+ /* primary constructor */
35
+
36
+ override fun equals(other: Any?): Boolean {
37
+ if (this === other) return true
38
+ if (other !is BoundingBox) return false
39
+ return Objects.deepEquals(this.x1, other.x1)
40
+ && Objects.deepEquals(this.y1, other.y1)
41
+ && Objects.deepEquals(this.x2, other.x2)
42
+ && Objects.deepEquals(this.y2, other.y2)
43
+ }
44
+
45
+ override fun hashCode(): Int {
46
+ return arrayOf<Any?>(
47
+ x1,
48
+ y1,
49
+ x2,
50
+ y2
51
+ ).contentDeepHashCode()
52
+ }
53
+
54
+ companion object {
55
+ /**
56
+ * Constructor called from C++
57
+ */
58
+ @DoNotStrip
59
+ @Keep
60
+ @Suppress("unused")
61
+ @JvmStatic
62
+ private fun fromCpp(x1: Double, y1: Double, x2: Double, y2: Double): BoundingBox {
63
+ return BoundingBox(x1, y1, x2, y2)
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// Detection.kt
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
+ package com.margelo.nitro.yolo
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "Detection".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class Detection(
21
+ @DoNotStrip
22
+ @Keep
23
+ val classId: Double,
24
+ @DoNotStrip
25
+ @Keep
26
+ val score: Double,
27
+ @DoNotStrip
28
+ @Keep
29
+ val boundingBox: BoundingBox
30
+ ) {
31
+ /* primary constructor */
32
+
33
+ override fun equals(other: Any?): Boolean {
34
+ if (this === other) return true
35
+ if (other !is Detection) return false
36
+ return Objects.deepEquals(this.classId, other.classId)
37
+ && Objects.deepEquals(this.score, other.score)
38
+ && Objects.deepEquals(this.boundingBox, other.boundingBox)
39
+ }
40
+
41
+ override fun hashCode(): Int {
42
+ return arrayOf<Any?>(
43
+ classId,
44
+ score,
45
+ boundingBox
46
+ ).contentDeepHashCode()
47
+ }
48
+
49
+ companion object {
50
+ /**
51
+ * Constructor called from C++
52
+ */
53
+ @DoNotStrip
54
+ @Keep
55
+ @Suppress("unused")
56
+ @JvmStatic
57
+ private fun fromCpp(classId: Double, score: Double, boundingBox: BoundingBox): Detection {
58
+ return Detection(classId, score, boundingBox)
59
+ }
60
+ }
61
+ }
@@ -10,6 +10,7 @@ package com.margelo.nitro.yolo
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.jni.HybridData
12
12
  import com.facebook.proguard.annotations.DoNotStrip
13
+ import com.margelo.nitro.camera.HybridFrameSpec
13
14
  import com.margelo.nitro.core.HybridObject
14
15
 
15
16
  /**
@@ -35,6 +36,14 @@ abstract class HybridYoloSpec: HybridObject() {
35
36
  @DoNotStrip
36
37
  @Keep
37
38
  abstract fun loadModel(modelPath: String): Unit
39
+
40
+ @DoNotStrip
41
+ @Keep
42
+ abstract fun frameToBase64(frame: com.margelo.nitro.camera.HybridFrameSpec): String
43
+
44
+ @DoNotStrip
45
+ @Keep
46
+ abstract fun detect(frame: com.margelo.nitro.camera.HybridFrameSpec): Array<Detection>
38
47
 
39
48
  // Default implementation of `HybridObject.toString()`
40
49
  override fun toString(): String {
@@ -11,9 +11,20 @@
11
11
  #include "HybridYoloSpecSwift.hpp"
12
12
  #include "Yolo-Swift-Cxx-Umbrella.hpp"
13
13
  #include <NitroModules/NitroDefines.hpp>
14
+ #include <VisionCamera/VisionCamera-Swift-Cxx-Bridge.hpp>
14
15
 
15
16
  namespace margelo::nitro::yolo::bridge::swift {
16
17
 
18
+ // pragma MARK: std::shared_ptr<margelo::nitro::camera::HybridFrameSpec>
19
+ std::shared_ptr<margelo::nitro::camera::HybridFrameSpec> create_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
20
+ // Implemented in VisionCamera
21
+ return margelo::nitro::camera::bridge::swift::create_std__shared_ptr_HybridFrameSpec_(swiftUnsafePointer);
22
+ }
23
+ void* NON_NULL get_std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_(std__shared_ptr_margelo__nitro__camera__HybridFrameSpec_ cppType) {
24
+ // Implemented in VisionCamera
25
+ return margelo::nitro::camera::bridge::swift::get_std__shared_ptr_HybridFrameSpec_(cppType);
26
+ }
27
+
17
28
  // pragma MARK: std::shared_ptr<HybridYoloSpec>
18
29
  std::shared_ptr<HybridYoloSpec> create_std__shared_ptr_HybridYoloSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
19
30
  Yolo::HybridYoloSpec_cxx swiftPart = Yolo::HybridYoloSpec_cxx::fromUnsafe(swiftUnsafePointer);