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
|
@@ -1,65 +1,42 @@
|
|
|
1
1
|
package com.yolo
|
|
2
2
|
|
|
3
|
-
import android.
|
|
3
|
+
import android.util.Base64
|
|
4
4
|
import android.util.Log
|
|
5
|
-
|
|
6
|
-
import com.margelo.nitro.yolo.HybridYoloSpec
|
|
7
|
-
import java.io.File
|
|
8
|
-
import java.io.RandomAccessFile
|
|
9
|
-
import java.net.URL
|
|
10
|
-
import java.nio.MappedByteBuffer
|
|
11
|
-
import java.nio.channels.FileChannel
|
|
12
|
-
import org.tensorflow.lite.Interpreter
|
|
13
|
-
import org.tensorflow.lite.support.common.FileUtil
|
|
14
|
-
import yolo.com.loader.YoloModelLoader
|
|
5
|
+
|
|
15
6
|
import com.margelo.nitro.camera.HybridFrameSpec
|
|
7
|
+
import com.margelo.nitro.yolo.HybridYoloModelSpec
|
|
8
|
+
import com.margelo.nitro.yolo.HybridYoloSpec
|
|
16
9
|
|
|
17
|
-
import android.util.Base64
|
|
18
10
|
import com.yolo.utils.FrameJpegConverter
|
|
19
11
|
import com.yolo.utils.FrameValidator
|
|
20
12
|
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
14
|
class HybridYolo : HybridYoloSpec() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
override fun sum(num1: Double, num2: Double): Double {
|
|
29
|
-
return num1 + num2
|
|
15
|
+
companion object {
|
|
16
|
+
private const val TAG = "YOLO_TAG"
|
|
30
17
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
NitroModules.applicationContext ?: throw IllegalStateException("Context is null")
|
|
35
|
-
|
|
36
|
-
Log.d("YOLO_TAG", "Trying to load: $modelPath")
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
val modelBuffer = modelLoader.load(modelPath)
|
|
40
|
-
|
|
41
|
-
interpreter?.close()
|
|
42
|
-
interpreter = Interpreter(modelBuffer)
|
|
43
|
-
|
|
44
|
-
Log.d("YOLO_TAG", "✅ Model loaded successfully!")
|
|
45
|
-
} catch (e: Exception) {
|
|
46
|
-
Log.e("YOLO_TAG", "❌ Failed to load model: ${e.message}", e)
|
|
47
|
-
}
|
|
18
|
+
override fun loadModel(modelPath: String): HybridYoloModelSpec {
|
|
19
|
+
Log.d(TAG, "Trying to load model object: $modelPath")
|
|
20
|
+
return HybridYoloModel(modelPath)
|
|
48
21
|
}
|
|
49
22
|
override fun frameToBase64(frame: HybridFrameSpec): String {
|
|
23
|
+
Log.d(TAG, "Trying to convert frame to base64")
|
|
50
24
|
return try {
|
|
25
|
+
Log.d(TAG, "frameToBase64: frame: $frame")
|
|
51
26
|
if (!FrameValidator.isValidYuv(frame)) return ""
|
|
27
|
+
Log.d(TAG, "frameToBase64: frame is valid YUV")
|
|
52
28
|
|
|
53
29
|
val jpegBytes = FrameJpegConverter.toJpegBytes(
|
|
54
30
|
frame = frame,
|
|
55
31
|
quality = 80
|
|
56
32
|
)
|
|
33
|
+
Log.d(TAG, "frameToBase64: jpegBytes size: ${jpegBytes.size}")
|
|
57
34
|
|
|
58
35
|
Base64.encodeToString(jpegBytes, Base64.NO_WRAP)
|
|
36
|
+
|
|
59
37
|
} catch (e: Exception) {
|
|
60
|
-
Log.e(
|
|
38
|
+
Log.e(TAG, "❌ frameToBase64 failed", e)
|
|
61
39
|
""
|
|
62
40
|
}
|
|
63
41
|
}
|
|
64
|
-
|
|
65
42
|
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
package com.yolo
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.margelo.nitro.yolo.HybridYoloModelSpec
|
|
5
|
+
import com.margelo.nitro.yolo.Detection
|
|
6
|
+
import com.margelo.nitro.yolo.BoundingBox
|
|
7
|
+
import com.margelo.nitro.camera.HybridFrameSpec
|
|
8
|
+
import com.yolo.utils.FrameValidator
|
|
9
|
+
import java.nio.ByteBuffer
|
|
10
|
+
import org.tensorflow.lite.DataType
|
|
11
|
+
import org.tensorflow.lite.Interpreter
|
|
12
|
+
import yolo.com.loader.YoloModelLoader
|
|
13
|
+
import kotlin.math.roundToInt
|
|
14
|
+
|
|
15
|
+
class HybridYoloModel(
|
|
16
|
+
modelPath: String
|
|
17
|
+
) : HybridYoloModelSpec() {
|
|
18
|
+
|
|
19
|
+
companion object {
|
|
20
|
+
private const val TAG = "YOLO_MODEL_TAG"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private val modelLoader = YoloModelLoader()
|
|
24
|
+
|
|
25
|
+
private var interpreter: Interpreter? = null
|
|
26
|
+
private var inputBuffer: ByteBuffer? = null
|
|
27
|
+
private var inputWidth = 0
|
|
28
|
+
private var inputHeight = 0
|
|
29
|
+
private var inputDataType: DataType? = null
|
|
30
|
+
|
|
31
|
+
private val lock = Any()
|
|
32
|
+
|
|
33
|
+
init {
|
|
34
|
+
load(modelPath)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private fun load(modelPath: String) {
|
|
38
|
+
try {
|
|
39
|
+
val modelBuffer = modelLoader.load(modelPath)
|
|
40
|
+
|
|
41
|
+
interpreter = Interpreter(modelBuffer)
|
|
42
|
+
|
|
43
|
+
val localInterpreter = interpreter!!
|
|
44
|
+
|
|
45
|
+
val inputTensor = localInterpreter.getInputTensor(0)
|
|
46
|
+
val outputTensor = localInterpreter.getOutputTensor(0)
|
|
47
|
+
|
|
48
|
+
val shape = inputTensor.shape()
|
|
49
|
+
|
|
50
|
+
inputHeight = shape[1]
|
|
51
|
+
inputWidth = shape[2]
|
|
52
|
+
inputDataType = inputTensor.dataType()
|
|
53
|
+
inputBuffer = modelLoader.makeInputBuffer(localInterpreter)
|
|
54
|
+
|
|
55
|
+
Log.d(TAG, "✅ YOLO model instance loaded")
|
|
56
|
+
Log.d(TAG, "📥 Input shape: ${inputTensor.shape().contentToString()}")
|
|
57
|
+
Log.d(TAG, "📤 Output shape: ${outputTensor.shape().contentToString()}")
|
|
58
|
+
Log.d(TAG, "📥 Input type: ${inputTensor.dataType()}")
|
|
59
|
+
Log.d(TAG, "📤 Output type: ${outputTensor.dataType()}")
|
|
60
|
+
} catch (e: Exception) {
|
|
61
|
+
Log.e(TAG, "❌ Failed to load model instance", e)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun detect(frame: HybridFrameSpec): Array<Detection> {
|
|
66
|
+
val localInterpreter = interpreter ?: run {
|
|
67
|
+
Log.e(TAG, "❌ This model instance is not loaded.")
|
|
68
|
+
return emptyArray()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!FrameValidator.isValidYuv(frame)) {
|
|
72
|
+
Log.e(TAG, "❌ Invalid frame provided for detection.")
|
|
73
|
+
return emptyArray()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
val input = inputBuffer ?: return emptyArray()
|
|
77
|
+
|
|
78
|
+
synchronized(lock) {
|
|
79
|
+
input.rewind()
|
|
80
|
+
|
|
81
|
+
fillInputFromYuvFrame(
|
|
82
|
+
frame = frame,
|
|
83
|
+
input = input,
|
|
84
|
+
dstWidth = inputWidth,
|
|
85
|
+
dstHeight = inputHeight,
|
|
86
|
+
dataType = inputDataType ?: DataType.FLOAT32
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
val output = Array(1) { Array(300) { FloatArray(6) } }
|
|
90
|
+
|
|
91
|
+
localInterpreter.run(input, output)
|
|
92
|
+
|
|
93
|
+
val detections = parseNmsOutput(output, confidenceThreshold = 0.5f)
|
|
94
|
+
|
|
95
|
+
return detections.toTypedArray()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override fun close() {
|
|
100
|
+
interpreter?.close()
|
|
101
|
+
interpreter = null
|
|
102
|
+
inputBuffer = null
|
|
103
|
+
Log.d(TAG, "🧹 YOLO model disposed")
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private fun parseNmsOutput(
|
|
107
|
+
output: Array<Array<FloatArray>>,
|
|
108
|
+
confidenceThreshold: Float = 0.5f
|
|
109
|
+
): List<Detection> {
|
|
110
|
+
val detections = mutableListOf<Detection>()
|
|
111
|
+
|
|
112
|
+
for (row in output[0]) {
|
|
113
|
+
val score = row[4]
|
|
114
|
+
if (score < confidenceThreshold) continue
|
|
115
|
+
|
|
116
|
+
detections.add(
|
|
117
|
+
Detection(
|
|
118
|
+
boundingBox = BoundingBox(
|
|
119
|
+
x1 = row[0].toDouble(),
|
|
120
|
+
y1 = row[1].toDouble(),
|
|
121
|
+
x2 = row[2].toDouble(),
|
|
122
|
+
y2 = row[3].toDouble()
|
|
123
|
+
),
|
|
124
|
+
score = score.toDouble(),
|
|
125
|
+
classId = row[5].toDouble()
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return detections
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fun fillInputFromYuvFrame(
|
|
134
|
+
frame: HybridFrameSpec,
|
|
135
|
+
input: ByteBuffer,
|
|
136
|
+
dstWidth: Int,
|
|
137
|
+
dstHeight: Int,
|
|
138
|
+
dataType: DataType
|
|
139
|
+
) {
|
|
140
|
+
val srcWidth = frame.width.toInt()
|
|
141
|
+
val srcHeight = frame.height.toInt()
|
|
142
|
+
|
|
143
|
+
val planes = frame.getPlanes()
|
|
144
|
+
|
|
145
|
+
val yPlane = planes[0]
|
|
146
|
+
val uPlane = planes[1]
|
|
147
|
+
val vPlane = planes[2]
|
|
148
|
+
|
|
149
|
+
val yBytes = yPlane.getPixelBuffer().toByteArray()
|
|
150
|
+
val uBytes = uPlane.getPixelBuffer().toByteArray()
|
|
151
|
+
val vBytes = vPlane.getPixelBuffer().toByteArray()
|
|
152
|
+
|
|
153
|
+
val yRowStride = yPlane.bytesPerRow.roundToInt()
|
|
154
|
+
val uRowStride = uPlane.bytesPerRow.roundToInt()
|
|
155
|
+
val vRowStride = vPlane.bytesPerRow.roundToInt()
|
|
156
|
+
|
|
157
|
+
input.rewind()
|
|
158
|
+
|
|
159
|
+
for (dy in 0 until dstHeight) {
|
|
160
|
+
for (dx in 0 until dstWidth) {
|
|
161
|
+
val srcX = dy * srcWidth / dstHeight
|
|
162
|
+
val srcY = srcHeight - 1 - (dx * srcHeight / dstWidth)
|
|
163
|
+
|
|
164
|
+
val yIndex = srcY * yRowStride + srcX
|
|
165
|
+
|
|
166
|
+
val uvX = srcX / 2
|
|
167
|
+
val uvY = srcY / 2
|
|
168
|
+
|
|
169
|
+
val uIndex = uvY * uRowStride + uvX * 2
|
|
170
|
+
val vIndex = uvY * vRowStride + uvX * 2
|
|
171
|
+
|
|
172
|
+
if (
|
|
173
|
+
yIndex >= yBytes.size ||
|
|
174
|
+
uIndex >= uBytes.size ||
|
|
175
|
+
vIndex >= vBytes.size
|
|
176
|
+
) {
|
|
177
|
+
continue
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
val y = yBytes[yIndex].toInt() and 0xFF
|
|
181
|
+
val u = uBytes[uIndex].toInt() and 0xFF
|
|
182
|
+
val v = vBytes[vIndex].toInt() and 0xFF
|
|
183
|
+
|
|
184
|
+
val rFloat = y + 1.402f * (v - 128)
|
|
185
|
+
val gFloat = y - 0.344136f * (u - 128) - 0.714136f * (v - 128)
|
|
186
|
+
val bFloat = y + 1.772f * (u - 128)
|
|
187
|
+
|
|
188
|
+
val r = rFloat.roundToInt().coerceIn(0, 255)
|
|
189
|
+
val g = gFloat.roundToInt().coerceIn(0, 255)
|
|
190
|
+
val b = bFloat.roundToInt().coerceIn(0, 255)
|
|
191
|
+
|
|
192
|
+
when (dataType) {
|
|
193
|
+
DataType.FLOAT32 -> {
|
|
194
|
+
input.putFloat(r / 255f)
|
|
195
|
+
input.putFloat(g / 255f)
|
|
196
|
+
input.putFloat(b / 255f)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
DataType.UINT8 -> {
|
|
200
|
+
input.put(r.toByte())
|
|
201
|
+
input.put(g.toByte())
|
|
202
|
+
input.put(b.toByte())
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
else -> error("Unsupported input type: $dataType")
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
input.rewind()
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -10,6 +10,12 @@ import java.nio.MappedByteBuffer
|
|
|
10
10
|
import java.nio.channels.FileChannel
|
|
11
11
|
import org.tensorflow.lite.support.common.FileUtil
|
|
12
12
|
|
|
13
|
+
import org.tensorflow.lite.DataType
|
|
14
|
+
import java.nio.ByteBuffer
|
|
15
|
+
import java.nio.ByteOrder
|
|
16
|
+
import kotlin.math.roundToInt
|
|
17
|
+
import org.tensorflow.lite.Interpreter
|
|
18
|
+
|
|
13
19
|
|
|
14
20
|
|
|
15
21
|
/**
|
|
@@ -127,4 +133,29 @@ class YoloModelLoader {
|
|
|
127
133
|
|
|
128
134
|
return file
|
|
129
135
|
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
fun makeInputBuffer(interpreter: Interpreter): ByteBuffer {
|
|
139
|
+
val inputTensor = interpreter.getInputTensor(0)
|
|
140
|
+
val shape = inputTensor.shape() // usually [1, 640, 640, 3]
|
|
141
|
+
val dataType = inputTensor.dataType()
|
|
142
|
+
|
|
143
|
+
val batch = shape[0]
|
|
144
|
+
val height = shape[1]
|
|
145
|
+
val width = shape[2]
|
|
146
|
+
val channels = shape[3]
|
|
147
|
+
|
|
148
|
+
require(batch == 1)
|
|
149
|
+
require(channels == 3)
|
|
150
|
+
|
|
151
|
+
val bytesPerValue = when (dataType) {
|
|
152
|
+
DataType.FLOAT32 -> 4
|
|
153
|
+
DataType.UINT8 -> 1
|
|
154
|
+
else -> error("Unsupported input type: $dataType")
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return ByteBuffer
|
|
158
|
+
.allocateDirect(batch * width * height * channels * bytesPerValue)
|
|
159
|
+
.order(ByteOrder.nativeOrder())
|
|
160
|
+
}
|
|
130
161
|
}
|
|
@@ -4,6 +4,7 @@ import android.graphics.Bitmap
|
|
|
4
4
|
import android.graphics.BitmapFactory
|
|
5
5
|
import android.graphics.Matrix
|
|
6
6
|
import com.margelo.nitro.camera.HybridFrameSpec
|
|
7
|
+
import com.margelo.nitro.camera.CameraOrientation
|
|
7
8
|
import java.io.ByteArrayOutputStream
|
|
8
9
|
|
|
9
10
|
|
|
@@ -20,7 +21,13 @@ object BitmapOrientationFixer {
|
|
|
20
21
|
jpegBytes.size
|
|
21
22
|
) ?: return jpegBytes
|
|
22
23
|
|
|
23
|
-
val rotationDegrees =
|
|
24
|
+
val rotationDegrees = when (frame.orientation) {
|
|
25
|
+
CameraOrientation.LEFT -> 90f
|
|
26
|
+
CameraOrientation.RIGHT -> 270f
|
|
27
|
+
CameraOrientation.UP -> 0f
|
|
28
|
+
CameraOrientation.DOWN -> 180f
|
|
29
|
+
else -> 0f
|
|
30
|
+
}
|
|
24
31
|
|
|
25
32
|
val matrix = Matrix().apply {
|
|
26
33
|
postRotate(rotationDegrees)
|
package/lib/commonjs/index.js
CHANGED
|
@@ -7,12 +7,13 @@ exports.Yolo = void 0;
|
|
|
7
7
|
var _reactNativeNitroModules = require("react-native-nitro-modules");
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
const NativeYolo = _reactNativeNitroModules.NitroModules.createHybridObject('Yolo');
|
|
10
|
-
const Yolo = exports.Yolo =
|
|
11
|
-
|
|
10
|
+
const Yolo = exports.Yolo = {
|
|
11
|
+
...NativeYolo,
|
|
12
|
+
loadModel(modelAssetId) {
|
|
12
13
|
const {
|
|
13
14
|
uri
|
|
14
15
|
} = _reactNative.Image.resolveAssetSource(modelAssetId);
|
|
15
16
|
return NativeYolo.loadModel(uri);
|
|
16
17
|
}
|
|
17
|
-
}
|
|
18
|
+
};
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","_reactNative","NativeYolo","NitroModules","createHybridObject","Yolo","exports","
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","_reactNative","NativeYolo","NitroModules","createHybridObject","Yolo","exports","loadModel","modelAssetId","uri","Image","resolveAssetSource"],"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;AAG7D,MAAMC,IAAI,GAAAC,OAAA,CAAAD,IAAA,GAAG;EAClB,GAAGH,UAAU;EAEbK,SAASA,CAACC,YAAoB,EAAE;IAC9B,MAAM;MAAEC;IAAI,CAAC,GAAGC,kBAAK,CAACC,kBAAkB,CAACH,YAAY,CAAC;IACtD,OAAON,UAAU,CAACK,SAAS,CAACE,GAAG,CAAC;EAClC;AACF,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
4
|
import { Image } from 'react-native';
|
|
5
5
|
const NativeYolo = NitroModules.createHybridObject('Yolo');
|
|
6
|
-
export const Yolo =
|
|
7
|
-
|
|
6
|
+
export const Yolo = {
|
|
7
|
+
...NativeYolo,
|
|
8
|
+
loadModel(modelAssetId) {
|
|
8
9
|
const {
|
|
9
10
|
uri
|
|
10
11
|
} = Image.resolveAssetSource(modelAssetId);
|
|
11
12
|
return NativeYolo.loadModel(uri);
|
|
12
13
|
}
|
|
13
|
-
}
|
|
14
|
+
};
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroModules","Image","NativeYolo","createHybridObject","Yolo","
|
|
1
|
+
{"version":3,"names":["NitroModules","Image","NativeYolo","createHybridObject","Yolo","loadModel","modelAssetId","uri","resolveAssetSource"],"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;AAGpE,OAAO,MAAMC,IAAI,GAAG;EAClB,GAAGF,UAAU;EAEbG,SAASA,CAACC,YAAoB,EAAE;IAC9B,MAAM;MAAEC;IAAI,CAAC,GAAGN,KAAK,CAACO,kBAAkB,CAACF,YAAY,CAAC;IACtD,OAAOJ,UAAU,CAACG,SAAS,CAACE,GAAG,CAAC;EAClC;AACF,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare const Yolo: {
|
|
2
|
+
loadModel(modelAssetId: number): import("./specs/yolo.nitro").YoloModel;
|
|
3
|
+
frameToBase64(frame: import("react-native-vision-camera").Frame): string;
|
|
4
|
+
__type?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
toString(): string;
|
|
7
|
+
equals(other: import("react-native-nitro-modules").HybridObject<{
|
|
8
|
+
ios: "swift";
|
|
9
|
+
android: "kotlin";
|
|
10
|
+
}>): boolean;
|
|
11
|
+
dispose(): void;
|
|
4
12
|
};
|
|
13
|
+
export type { Detection, BoundingBox, YoloModel, } from './specs/yolo.nitro';
|
|
5
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,IAAI;4BAGS,MAAM;;;;;;;;;;CAI/B,CAAA;AACD,YAAY,EACV,SAAS,EACT,WAAW,EACX,SAAS,GACV,MAAM,oBAAoB,CAAA"}
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
2
|
import type { Frame } from 'react-native-vision-camera';
|
|
3
|
+
export type Detection = {
|
|
4
|
+
classId: number;
|
|
5
|
+
score: number;
|
|
6
|
+
boundingBox: BoundingBox;
|
|
7
|
+
};
|
|
8
|
+
export type BoundingBox = {
|
|
9
|
+
x1: number;
|
|
10
|
+
y1: number;
|
|
11
|
+
x2: number;
|
|
12
|
+
y2: number;
|
|
13
|
+
};
|
|
14
|
+
export interface YoloModel extends HybridObject<{
|
|
15
|
+
ios: 'swift';
|
|
16
|
+
android: 'kotlin';
|
|
17
|
+
}> {
|
|
18
|
+
detect(frame: Frame): Detection[];
|
|
19
|
+
close(): void;
|
|
20
|
+
}
|
|
3
21
|
export interface Yolo extends HybridObject<{
|
|
4
22
|
ios: 'swift';
|
|
5
23
|
android: 'kotlin';
|
|
6
24
|
}> {
|
|
7
|
-
|
|
8
|
-
loadModel(modelPath: string): void;
|
|
25
|
+
loadModel(modelPath: string): YoloModel;
|
|
9
26
|
frameToBase64(frame: Frame): string;
|
|
10
27
|
}
|
|
11
28
|
//# 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;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAEvD,MAAM,WAAW,
|
|
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,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,WAAW,CAAA;CACzB,CAAA;AACD,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,WAAW,SAAU,SAAQ,YAAY,CAAC;IAC9C,GAAG,EAAE,OAAO,CAAA;IACZ,OAAO,EAAE,QAAQ,CAAA;CAClB,CAAC;IACA,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,CAAA;IACjC,KAAK,IAAI,IAAI,CAAA;CAEd;AAED,MAAM,WAAW,IAAK,SAAQ,YAAY,CAAC;IACzC,GAAG,EAAE,OAAO,CAAA;IACZ,OAAO,EAAE,QAAQ,CAAA;CAClB,CAAC;IACA,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAA;CACpC"}
|
|
@@ -33,8 +33,10 @@ target_sources(
|
|
|
33
33
|
# Autolinking Setup
|
|
34
34
|
../nitrogen/generated/android/YoloOnLoad.cpp
|
|
35
35
|
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridYoloModelSpec.cpp
|
|
36
37
|
../nitrogen/generated/shared/c++/HybridYoloSpec.cpp
|
|
37
38
|
# Android-specific Nitrogen C++ sources
|
|
39
|
+
../nitrogen/generated/android/c++/JHybridYoloModelSpec.cpp
|
|
38
40
|
../nitrogen/generated/android/c++/JHybridYoloSpec.cpp
|
|
39
41
|
)
|
|
40
42
|
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
#include <fbjni/fbjni.h>
|
|
16
16
|
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
17
|
|
|
18
|
+
#include "JHybridYoloModelSpec.hpp"
|
|
18
19
|
#include "JHybridYoloSpec.hpp"
|
|
19
20
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
21
|
|
|
@@ -40,6 +41,7 @@ void registerAllNatives() {
|
|
|
40
41
|
using namespace margelo::nitro::yolo;
|
|
41
42
|
|
|
42
43
|
// Register native JNI methods
|
|
44
|
+
margelo::nitro::yolo::JHybridYoloModelSpec::CxxPart::registerNatives();
|
|
43
45
|
margelo::nitro::yolo::JHybridYoloSpec::CxxPart::registerNatives();
|
|
44
46
|
|
|
45
47
|
// Register Nitro Hybrid Objects
|
|
@@ -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
|