react-native-yolo 0.0.12 → 0.0.13
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/ios/HybridYoloModel.swift +27 -14
- package/package.json +1 -1
|
@@ -121,9 +121,9 @@ public class HybridYoloModel: HybridYoloModelSpec {
|
|
|
121
121
|
|
|
122
122
|
detections.append(
|
|
123
123
|
Detection(
|
|
124
|
-
|
|
124
|
+
classId: Double(outputArray[offset + 5]),
|
|
125
125
|
score: Double(score),
|
|
126
|
-
|
|
126
|
+
boundingBox: box
|
|
127
127
|
)
|
|
128
128
|
)
|
|
129
129
|
}
|
|
@@ -143,8 +143,13 @@ public class HybridYoloModel: HybridYoloModelSpec {
|
|
|
143
143
|
|
|
144
144
|
// Extraction du CVPixelBuffer matériel pour un accès direct ultra-rapide
|
|
145
145
|
let nativeBuffer = try frame.getNativeBuffer()
|
|
146
|
-
guard let rawPointer = nativeBuffer.pointer else {
|
|
147
|
-
|
|
146
|
+
guard let rawPointer = UnsafeRawPointer(bitPattern: UInt(nativeBuffer.pointer)) else {
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let pixelBuffer = Unmanaged<CVPixelBuffer>
|
|
151
|
+
.fromOpaque(rawPointer)
|
|
152
|
+
.takeUnretainedValue()
|
|
148
153
|
|
|
149
154
|
CVPixelBufferLockBaseAddress(pixelBuffer, .readOnly)
|
|
150
155
|
defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, .readOnly) }
|
|
@@ -184,13 +189,17 @@ public class HybridYoloModel: HybridYoloModelSpec {
|
|
|
184
189
|
let v = Int(uvPtr[uvIndex + 1]) // V se trouve juste à côté
|
|
185
190
|
|
|
186
191
|
// Formule standard de conversion YUV en RGB
|
|
187
|
-
let
|
|
188
|
-
let
|
|
189
|
-
let
|
|
192
|
+
let yf = Float(y)
|
|
193
|
+
let uf = Float(u - 128)
|
|
194
|
+
let vf = Float(v - 128)
|
|
195
|
+
|
|
196
|
+
let rFloat = yf + (1.402 * vf)
|
|
197
|
+
let gFloat = yf - (0.344136 * uf) - (0.714136 * vf)
|
|
198
|
+
let bFloat = yf + (1.772 * uf)
|
|
190
199
|
|
|
191
|
-
let r = Int(rFloat.rounded())
|
|
192
|
-
let g = Int(gFloat.rounded())
|
|
193
|
-
let b = Int(bFloat.rounded())
|
|
200
|
+
let r = clampInt(Int(rFloat.rounded()), 0, 255)
|
|
201
|
+
let g = clampInt(Int(gFloat.rounded()), 0, 255)
|
|
202
|
+
let b = clampInt(Int(bFloat.rounded()), 0, 255)
|
|
194
203
|
|
|
195
204
|
if dataType == .float32 {
|
|
196
205
|
let rNorm = Float(r) / 255.0
|
|
@@ -229,22 +238,26 @@ public class HybridYoloModel: HybridYoloModelSpec {
|
|
|
229
238
|
case .up:
|
|
230
239
|
let sx = Int(nx * Float(srcWidth))
|
|
231
240
|
let sy = Int(ny * Float(srcHeight))
|
|
232
|
-
return (sx
|
|
241
|
+
return (clampInt(sx, 0, srcWidth - 1), clampInt(sy, 0, srcHeight - 1))
|
|
233
242
|
case .down:
|
|
234
243
|
let sx = Int((1.0 - nx) * Float(srcWidth))
|
|
235
244
|
let sy = Int((1.0 - ny) * Float(srcHeight))
|
|
236
|
-
return (sx
|
|
245
|
+
return (clampInt(sx, 0, srcWidth - 1), clampInt(sy, 0, srcHeight - 1))
|
|
237
246
|
case .left:
|
|
238
247
|
let sx = Int(ny * Float(srcWidth))
|
|
239
248
|
let sy = Int((1.0 - nx) * Float(srcHeight))
|
|
240
|
-
return (sx
|
|
249
|
+
return (clampInt(sx, 0, srcWidth - 1), clampInt(sy, 0, srcHeight - 1))
|
|
241
250
|
case .right:
|
|
242
251
|
let sx = Int((1.0 - ny) * Float(srcWidth))
|
|
243
252
|
let sy = Int(nx * Float(srcHeight))
|
|
244
|
-
return (sx
|
|
253
|
+
return (clampInt(sx, 0, srcWidth - 1), clampInt(sy, 0, srcHeight - 1))
|
|
245
254
|
@unknown default:
|
|
246
255
|
return (0, 0)
|
|
247
256
|
}
|
|
248
257
|
}
|
|
258
|
+
|
|
259
|
+
private func clampInt(_ value: Int, _ minValue: Int, _ maxValue: Int) -> Int {
|
|
260
|
+
return min(max(value, minValue), maxValue)
|
|
261
|
+
}
|
|
249
262
|
}
|
|
250
263
|
|