@souscheflabs/ml-vision 0.1.0 → 0.1.2

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 (149) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/LICENSE +15 -0
  3. package/README.md +50 -5
  4. package/dist/{components → cjs/components}/DetectionOverlay.js +1 -0
  5. package/dist/cjs/components/DetectionOverlay.js.map +1 -0
  6. package/dist/{components → cjs/components}/index.js +1 -0
  7. package/dist/cjs/components/index.js.map +1 -0
  8. package/dist/{core → cjs/core}/CacheManager.js +1 -0
  9. package/dist/cjs/core/CacheManager.js.map +1 -0
  10. package/dist/{core → cjs/core}/MLVisionProvider.js +4 -2
  11. package/dist/cjs/core/MLVisionProvider.js.map +1 -0
  12. package/dist/{core → cjs/core}/ServerClient.js +33 -13
  13. package/dist/cjs/core/ServerClient.js.map +1 -0
  14. package/dist/{core → cjs/core}/index.js +1 -0
  15. package/dist/cjs/core/index.js.map +1 -0
  16. package/dist/{hooks → cjs/hooks}/classLabels.js +1 -0
  17. package/dist/cjs/hooks/classLabels.js.map +1 -0
  18. package/dist/{hooks → cjs/hooks}/classLabelsCoco.js +1 -0
  19. package/dist/cjs/hooks/classLabelsCoco.js.map +1 -0
  20. package/dist/{hooks → cjs/hooks}/index.js +1 -0
  21. package/dist/cjs/hooks/index.js.map +1 -0
  22. package/dist/{hooks → cjs/hooks}/useMultiBarcodeScanner.js +6 -3
  23. package/dist/cjs/hooks/useMultiBarcodeScanner.js.map +1 -0
  24. package/dist/{hooks → cjs/hooks}/useProductDetector.js +161 -90
  25. package/dist/cjs/hooks/useProductDetector.js.map +1 -0
  26. package/dist/{hooks → cjs/hooks}/useReceiptScanner.js +60 -52
  27. package/dist/cjs/hooks/useReceiptScanner.js.map +1 -0
  28. package/dist/{hooks → cjs/hooks}/useVideoScanner.js +8 -5
  29. package/dist/cjs/hooks/useVideoScanner.js.map +1 -0
  30. package/dist/{index.js → cjs/index.js} +8 -4
  31. package/dist/cjs/index.js.map +1 -0
  32. package/dist/{processors → cjs/processors}/detectionProcessor.js +1 -0
  33. package/dist/cjs/processors/detectionProcessor.js.map +1 -0
  34. package/dist/{processors → cjs/processors}/index.js +1 -0
  35. package/dist/cjs/processors/index.js.map +1 -0
  36. package/dist/{processors → cjs/processors}/tfliteFrameProcessor.js +108 -25
  37. package/dist/cjs/processors/tfliteFrameProcessor.js.map +1 -0
  38. package/dist/{types → cjs/types}/barcode.js +1 -0
  39. package/dist/cjs/types/barcode.js.map +1 -0
  40. package/dist/{types → cjs/types}/detection.js +1 -0
  41. package/dist/cjs/types/detection.js.map +1 -0
  42. package/dist/{types → cjs/types}/index.js +1 -0
  43. package/dist/cjs/types/index.js.map +1 -0
  44. package/dist/{types → cjs/types}/ocr.js +1 -0
  45. package/dist/cjs/types/ocr.js.map +1 -0
  46. package/dist/{utils → cjs/utils}/imagePreprocessor.js +30 -25
  47. package/dist/cjs/utils/imagePreprocessor.js.map +1 -0
  48. package/dist/cjs/utils/logger.js +99 -0
  49. package/dist/cjs/utils/logger.js.map +1 -0
  50. package/dist/{utils → cjs/utils}/yoloProcessor.js +1 -0
  51. package/dist/cjs/utils/yoloProcessor.js.map +1 -0
  52. package/dist/esm/components/DetectionOverlay.js +130 -0
  53. package/dist/esm/components/DetectionOverlay.js.map +1 -0
  54. package/dist/esm/components/index.js +5 -0
  55. package/dist/esm/components/index.js.map +1 -0
  56. package/dist/esm/core/CacheManager.js +327 -0
  57. package/dist/esm/core/CacheManager.js.map +1 -0
  58. package/dist/esm/core/MLVisionProvider.js +185 -0
  59. package/dist/esm/core/MLVisionProvider.js.map +1 -0
  60. package/dist/esm/core/ServerClient.js +305 -0
  61. package/dist/esm/core/ServerClient.js.map +1 -0
  62. package/dist/esm/core/index.js +7 -0
  63. package/dist/esm/core/index.js.map +1 -0
  64. package/dist/esm/hooks/classLabels.js +436 -0
  65. package/dist/esm/hooks/classLabels.js.map +1 -0
  66. package/dist/esm/hooks/classLabelsCoco.js +98 -0
  67. package/dist/esm/hooks/classLabelsCoco.js.map +1 -0
  68. package/dist/esm/hooks/index.js +9 -0
  69. package/dist/esm/hooks/index.js.map +1 -0
  70. package/dist/esm/hooks/useMultiBarcodeScanner.js +290 -0
  71. package/dist/esm/hooks/useMultiBarcodeScanner.js.map +1 -0
  72. package/dist/esm/hooks/useProductDetector.js +714 -0
  73. package/dist/esm/hooks/useProductDetector.js.map +1 -0
  74. package/dist/esm/hooks/useReceiptScanner.js +407 -0
  75. package/dist/esm/hooks/useReceiptScanner.js.map +1 -0
  76. package/dist/esm/hooks/useVideoScanner.js +383 -0
  77. package/dist/esm/hooks/useVideoScanner.js.map +1 -0
  78. package/dist/esm/index.js +93 -0
  79. package/dist/esm/index.js.map +1 -0
  80. package/dist/esm/processors/detectionProcessor.js +121 -0
  81. package/dist/esm/processors/detectionProcessor.js.map +1 -0
  82. package/dist/esm/processors/index.js +7 -0
  83. package/dist/esm/processors/index.js.map +1 -0
  84. package/dist/esm/processors/tfliteFrameProcessor.js +292 -0
  85. package/dist/esm/processors/tfliteFrameProcessor.js.map +1 -0
  86. package/dist/esm/types/barcode.js +17 -0
  87. package/dist/esm/types/barcode.js.map +1 -0
  88. package/dist/esm/types/detection.js +8 -0
  89. package/dist/esm/types/detection.js.map +1 -0
  90. package/dist/esm/types/index.js +10 -0
  91. package/dist/esm/types/index.js.map +1 -0
  92. package/dist/esm/types/ocr.js +8 -0
  93. package/dist/esm/types/ocr.js.map +1 -0
  94. package/dist/esm/utils/imagePreprocessor.js +268 -0
  95. package/dist/esm/utils/imagePreprocessor.js.map +1 -0
  96. package/dist/esm/utils/logger.js +94 -0
  97. package/dist/esm/utils/logger.js.map +1 -0
  98. package/dist/esm/utils/yoloProcessor.js +151 -0
  99. package/dist/esm/utils/yoloProcessor.js.map +1 -0
  100. package/dist/{components → types/components}/DetectionOverlay.d.ts +1 -0
  101. package/dist/types/components/DetectionOverlay.d.ts.map +1 -0
  102. package/dist/{components → types/components}/index.d.ts +1 -0
  103. package/dist/types/components/index.d.ts.map +1 -0
  104. package/dist/{core → types/core}/CacheManager.d.ts +1 -0
  105. package/dist/types/core/CacheManager.d.ts.map +1 -0
  106. package/dist/{core → types/core}/MLVisionProvider.d.ts +1 -0
  107. package/dist/types/core/MLVisionProvider.d.ts.map +1 -0
  108. package/dist/{core → types/core}/ServerClient.d.ts +1 -0
  109. package/dist/types/core/ServerClient.d.ts.map +1 -0
  110. package/dist/{core → types/core}/index.d.ts +1 -0
  111. package/dist/types/core/index.d.ts.map +1 -0
  112. package/dist/{hooks → types/hooks}/classLabels.d.ts +1 -0
  113. package/dist/types/hooks/classLabels.d.ts.map +1 -0
  114. package/dist/{hooks → types/hooks}/classLabelsCoco.d.ts +1 -0
  115. package/dist/types/hooks/classLabelsCoco.d.ts.map +1 -0
  116. package/dist/{hooks → types/hooks}/index.d.ts +1 -0
  117. package/dist/types/hooks/index.d.ts.map +1 -0
  118. package/dist/{hooks → types/hooks}/useMultiBarcodeScanner.d.ts +1 -0
  119. package/dist/types/hooks/useMultiBarcodeScanner.d.ts.map +1 -0
  120. package/dist/{hooks → types/hooks}/useProductDetector.d.ts +1 -0
  121. package/dist/types/hooks/useProductDetector.d.ts.map +1 -0
  122. package/dist/{hooks → types/hooks}/useReceiptScanner.d.ts +2 -1
  123. package/dist/types/hooks/useReceiptScanner.d.ts.map +1 -0
  124. package/dist/{hooks → types/hooks}/useVideoScanner.d.ts +1 -0
  125. package/dist/types/hooks/useVideoScanner.d.ts.map +1 -0
  126. package/dist/types/index.d.ts +58 -124
  127. package/dist/types/index.d.ts.map +1 -0
  128. package/dist/{processors → types/processors}/detectionProcessor.d.ts +1 -0
  129. package/dist/types/processors/detectionProcessor.d.ts.map +1 -0
  130. package/dist/{processors → types/processors}/index.d.ts +1 -0
  131. package/dist/types/processors/index.d.ts.map +1 -0
  132. package/dist/{processors → types/processors}/tfliteFrameProcessor.d.ts +5 -4
  133. package/dist/types/processors/tfliteFrameProcessor.d.ts.map +1 -0
  134. package/dist/types/{barcode.d.ts → types/barcode.d.ts} +1 -0
  135. package/dist/types/types/barcode.d.ts.map +1 -0
  136. package/dist/types/{detection.d.ts → types/detection.d.ts} +1 -0
  137. package/dist/types/types/detection.d.ts.map +1 -0
  138. package/dist/types/types/index.d.ts +127 -0
  139. package/dist/types/types/index.d.ts.map +1 -0
  140. package/dist/types/{ocr.d.ts → types/ocr.d.ts} +1 -0
  141. package/dist/types/types/ocr.d.ts.map +1 -0
  142. package/dist/{utils → types/utils}/imagePreprocessor.d.ts +1 -0
  143. package/dist/types/utils/imagePreprocessor.d.ts.map +1 -0
  144. package/dist/types/utils/logger.d.ts +52 -0
  145. package/dist/types/utils/logger.d.ts.map +1 -0
  146. package/dist/{utils → types/utils}/yoloProcessor.d.ts +1 -0
  147. package/dist/types/utils/yoloProcessor.d.ts.map +1 -0
  148. package/package.json +62 -21
  149. package/dist/index.d.ts +0 -58
@@ -0,0 +1,383 @@
1
+ /**
2
+ * useVideoScanner Hook
3
+ *
4
+ * React hook for real-time video scanning combining product detection,
5
+ * barcode scanning, and text recognition.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { useVideoScanner } from '@souschef/ml-vision';
10
+ *
11
+ * function LiveScanner() {
12
+ * const {
13
+ * isScanning,
14
+ * products,
15
+ * barcodes,
16
+ * startScanning,
17
+ * stopScanning,
18
+ * cameraRef,
19
+ * } = useVideoScanner({
20
+ * modes: ['products', 'barcodes'],
21
+ * onDetected: (results) => console.log('Found:', results),
22
+ * });
23
+ *
24
+ * return (
25
+ * <Camera ref={cameraRef} />
26
+ * );
27
+ * }
28
+ * ```
29
+ */
30
+ import { useState, useCallback, useRef, useMemo, useEffect } from 'react';
31
+ import { useMLVisionContext } from '../core/MLVisionProvider';
32
+ import { useProductDetector } from './useProductDetector';
33
+ import { useMultiBarcodeScanner } from './useMultiBarcodeScanner';
34
+ import { useTFLiteFrameProcessor, } from '../processors/tfliteFrameProcessor';
35
+ import { COCO_CLASSES } from './classLabelsCoco';
36
+ import { logger } from '../utils/logger';
37
+ // ============================================================================
38
+ // Constants
39
+ // ============================================================================
40
+ const DEFAULT_TARGET_FPS = 10;
41
+ const DEFAULT_SMOOTHING_FRAMES = 3;
42
+ const MS_PER_SECOND = 1000;
43
+ // ============================================================================
44
+ // Hook Implementation
45
+ // ============================================================================
46
+ /**
47
+ * Hook for real-time video scanning
48
+ */
49
+ export function useVideoScanner(options = {}) {
50
+ const { modes = ['products', 'barcodes'], targetFps = DEFAULT_TARGET_FPS, minProductConfidence = 0.5, productCategories, maxProducts = 10, maxBarcodes = 5, temporalSmoothing = true, smoothingFrames = DEFAULT_SMOOTHING_FRAMES, onDetected, onError, hapticFeedback = true,
51
+ // TFLite options
52
+ tfliteModel, useOnDeviceFrameProcessor = !!tfliteModel, foodOnly = true, } = options;
53
+ // Context
54
+ const { isInitialized } = useMLVisionContext();
55
+ // Child hooks
56
+ const productDetector = useProductDetector({
57
+ model: 'fast',
58
+ minConfidence: minProductConfidence,
59
+ categories: productCategories,
60
+ maxDetections: maxProducts,
61
+ hapticFeedback: false, // We'll handle haptics at video level
62
+ });
63
+ const barcodeScanner = useMultiBarcodeScanner({
64
+ maxBarcodes,
65
+ hapticFeedback: false,
66
+ });
67
+ // State
68
+ const [isScanning, setIsScanning] = useState(false);
69
+ const [products, setProducts] = useState([]);
70
+ const [barcodes, setBarcodes] = useState([]);
71
+ const [frameNumber, setFrameNumber] = useState(0);
72
+ const [fps, setFps] = useState(0);
73
+ const [error, setError] = useState(null);
74
+ // Track inference time from TFLite frame processor
75
+ const inferenceTimeMsRef = useRef(0);
76
+ // ============================================================================
77
+ // TFLite Frame Processor (for real-time video detection)
78
+ // ============================================================================
79
+ /**
80
+ * Convert TFLite detection to ProductDetectionResult
81
+ */
82
+ const tfliteToProductResult = useCallback((detection) => {
83
+ return {
84
+ id: `tflite_${Date.now()}_${detection.classIndex}`,
85
+ type: 'product',
86
+ confidence: detection.confidence,
87
+ boundingBox: {
88
+ x: detection.x,
89
+ y: detection.y,
90
+ width: detection.width,
91
+ height: detection.height,
92
+ },
93
+ source: 'on_device',
94
+ processingTimeMs: 0,
95
+ timestamp: Date.now(),
96
+ data: {
97
+ category: 'produce', // Map to closest ProductCategory
98
+ classLabel: detection.label,
99
+ classIndex: detection.classIndex,
100
+ name: detection.label.charAt(0).toUpperCase() + detection.label.slice(1),
101
+ },
102
+ };
103
+ }, []);
104
+ /**
105
+ * Handle TFLite detections
106
+ */
107
+ const handleTFLiteDetections = useCallback((detections) => {
108
+ const productResults = detections.map(tfliteToProductResult);
109
+ setProducts(productResults);
110
+ setFrameNumber((prev) => prev + 1);
111
+ // Callback
112
+ if (productResults.length > 0 && onDetected) {
113
+ onDetected({
114
+ products: productResults,
115
+ barcodes,
116
+ timestamp: Date.now(),
117
+ frameNumber,
118
+ });
119
+ }
120
+ }, [tfliteToProductResult, barcodes, frameNumber, onDetected]);
121
+ // TFLite frame processor hook
122
+ const tfliteFrameProcessor = useTFLiteFrameProcessor({
123
+ model: useOnDeviceFrameProcessor ? tfliteModel ?? null : null,
124
+ numClasses: 80, // COCO
125
+ confThreshold: minProductConfidence,
126
+ classLabels: [...COCO_CLASSES], // Convert readonly to mutable array
127
+ foodOnly,
128
+ onDetections: handleTFLiteDetections,
129
+ });
130
+ // Refs
131
+ const cameraRef = useRef(null);
132
+ const lastFrameTimeRef = useRef(0);
133
+ const frameCountRef = useRef(0);
134
+ const fpsStartTimeRef = useRef(Date.now());
135
+ const productHistoryRef = useRef([]);
136
+ const mountedRef = useRef(true);
137
+ // Computed readiness
138
+ const isReady = useMemo(() => {
139
+ // For products: either TFLite frame processor is ready, or productDetector is loaded
140
+ const productReady = !modes.includes('products') ||
141
+ (useOnDeviceFrameProcessor ? tfliteFrameProcessor.isReady : productDetector.isModelLoaded);
142
+ const barcodeReady = !modes.includes('barcodes') || barcodeScanner.isReady;
143
+ return isInitialized && productReady && barcodeReady;
144
+ }, [
145
+ isInitialized,
146
+ modes,
147
+ useOnDeviceFrameProcessor,
148
+ tfliteFrameProcessor.isReady,
149
+ productDetector.isModelLoaded,
150
+ barcodeScanner.isReady,
151
+ ]);
152
+ // ============================================================================
153
+ // FPS Calculation
154
+ // ============================================================================
155
+ useEffect(() => {
156
+ if (!isScanning)
157
+ return;
158
+ const interval = setInterval(() => {
159
+ const now = Date.now();
160
+ const elapsed = (now - fpsStartTimeRef.current) / MS_PER_SECOND;
161
+ if (elapsed > 0) {
162
+ setFps(Math.round(frameCountRef.current / elapsed));
163
+ }
164
+ frameCountRef.current = 0;
165
+ fpsStartTimeRef.current = now;
166
+ }, MS_PER_SECOND);
167
+ return () => clearInterval(interval);
168
+ }, [isScanning]);
169
+ // ============================================================================
170
+ // Temporal Smoothing
171
+ // ============================================================================
172
+ /**
173
+ * Apply temporal smoothing to product detections
174
+ */
175
+ const smoothProducts = useCallback((newProducts) => {
176
+ if (!temporalSmoothing)
177
+ return newProducts;
178
+ // Add to history
179
+ productHistoryRef.current.push(newProducts);
180
+ if (productHistoryRef.current.length > smoothingFrames) {
181
+ productHistoryRef.current.shift();
182
+ }
183
+ // Count occurrences of each class
184
+ const classCounts = new Map();
185
+ const bestDetections = new Map();
186
+ for (const frameProducts of productHistoryRef.current) {
187
+ for (const product of frameProducts) {
188
+ const key = product.data.classLabel;
189
+ const count = (classCounts.get(key) || 0) + 1;
190
+ classCounts.set(key, count);
191
+ // Keep best confidence detection
192
+ const existing = bestDetections.get(key);
193
+ if (!existing || product.confidence > existing.confidence) {
194
+ bestDetections.set(key, product);
195
+ }
196
+ }
197
+ }
198
+ // Keep products that appear in at least half the frames
199
+ const threshold = Math.ceil(smoothingFrames / 2);
200
+ return Array.from(bestDetections.entries())
201
+ .filter(([key]) => (classCounts.get(key) || 0) >= threshold)
202
+ .map(([, product]) => product);
203
+ }, [temporalSmoothing, smoothingFrames]);
204
+ // ============================================================================
205
+ // Frame Processing
206
+ // ============================================================================
207
+ /**
208
+ * Process a frame (called from frame processor)
209
+ * @deprecated Use TFLite frame processor instead
210
+ */
211
+ const _processFrame = useCallback(async (frameUri) => {
212
+ const now = Date.now();
213
+ const minInterval = MS_PER_SECOND / targetFps;
214
+ // Throttle based on target FPS
215
+ if (now - lastFrameTimeRef.current < minInterval) {
216
+ return;
217
+ }
218
+ lastFrameTimeRef.current = now;
219
+ frameCountRef.current++;
220
+ try {
221
+ const results = {
222
+ products: [],
223
+ barcodes: [],
224
+ timestamp: now,
225
+ frameNumber: frameNumber,
226
+ };
227
+ // Product detection
228
+ if (modes.includes('products') && productDetector.isModelLoaded) {
229
+ const detected = await productDetector.detectProducts(frameUri);
230
+ results.products = smoothProducts(detected);
231
+ }
232
+ // Barcode detection is handled by VisionCamera's code scanner
233
+ // Results come through barcodeScanner.results
234
+ // Update state
235
+ if (mountedRef.current) {
236
+ setFrameNumber((prev) => prev + 1);
237
+ if (results.products.length > 0) {
238
+ setProducts(results.products);
239
+ }
240
+ // Combine with barcode results
241
+ results.barcodes = barcodeScanner.results;
242
+ // Callback
243
+ if (results.products.length > 0 || results.barcodes.length > 0) {
244
+ onDetected?.(results);
245
+ // Haptic feedback
246
+ if (hapticFeedback) {
247
+ // Trigger haptic
248
+ }
249
+ }
250
+ }
251
+ }
252
+ catch (err) {
253
+ const frameError = err instanceof Error ? err : new Error('Frame processing failed');
254
+ logger.error('[VideoScanner] Frame error:', frameError);
255
+ setError(frameError);
256
+ onError?.(frameError);
257
+ }
258
+ }, [
259
+ targetFps,
260
+ frameNumber,
261
+ modes,
262
+ productDetector,
263
+ barcodeScanner.results,
264
+ smoothProducts,
265
+ onDetected,
266
+ onError,
267
+ hapticFeedback,
268
+ ]);
269
+ // ============================================================================
270
+ // Actions
271
+ // ============================================================================
272
+ /**
273
+ * Start video scanning
274
+ */
275
+ const startScanning = useCallback(() => {
276
+ if (!isReady) {
277
+ logger.warn('[VideoScanner] Not ready to scan');
278
+ return;
279
+ }
280
+ setIsScanning(true);
281
+ setError(null);
282
+ frameCountRef.current = 0;
283
+ fpsStartTimeRef.current = Date.now();
284
+ productHistoryRef.current = [];
285
+ // Start barcode scanner if enabled
286
+ if (modes.includes('barcodes')) {
287
+ barcodeScanner.startScanning();
288
+ }
289
+ }, [isReady, modes, barcodeScanner]);
290
+ /**
291
+ * Stop video scanning
292
+ */
293
+ const stopScanning = useCallback(() => {
294
+ setIsScanning(false);
295
+ barcodeScanner.stopScanning();
296
+ }, [barcodeScanner]);
297
+ /**
298
+ * Toggle scanning
299
+ */
300
+ const toggleScanning = useCallback(() => {
301
+ if (isScanning) {
302
+ stopScanning();
303
+ }
304
+ else {
305
+ startScanning();
306
+ }
307
+ }, [isScanning, startScanning, stopScanning]);
308
+ /**
309
+ * Clear all detections
310
+ */
311
+ const clearDetections = useCallback(() => {
312
+ setProducts([]);
313
+ setBarcodes([]);
314
+ barcodeScanner.clearResults();
315
+ productDetector.clearDetections();
316
+ productHistoryRef.current = [];
317
+ }, [barcodeScanner, productDetector]);
318
+ /**
319
+ * Capture current frame as photo
320
+ */
321
+ const captureFrame = useCallback(async () => {
322
+ // This would use VisionCamera's takePhoto method
323
+ // Requires ref to be properly typed and connected
324
+ logger.debug('[VideoScanner] Frame capture requires VisionCamera ref');
325
+ return null;
326
+ }, []);
327
+ // ============================================================================
328
+ // Frame Processor Configuration
329
+ // ============================================================================
330
+ const frameProcessorConfig = useMemo(() => {
331
+ if (!isScanning)
332
+ return null;
333
+ return {
334
+ // For VisionCamera frame processor
335
+ // This would be used with useFrameProcessor
336
+ codeScanner: modes.includes('barcodes') ? barcodeScanner.frameProcessor : undefined,
337
+ // Product detection happens through processFrame
338
+ };
339
+ }, [isScanning, modes, barcodeScanner.frameProcessor]);
340
+ // ============================================================================
341
+ // Cleanup
342
+ // ============================================================================
343
+ useEffect(() => {
344
+ mountedRef.current = true;
345
+ return () => {
346
+ mountedRef.current = false;
347
+ };
348
+ }, []);
349
+ // Sync barcode results
350
+ useEffect(() => {
351
+ if (barcodeScanner.results.length > 0) {
352
+ setBarcodes(barcodeScanner.results);
353
+ }
354
+ }, [barcodeScanner.results]);
355
+ // ============================================================================
356
+ // Return
357
+ // ============================================================================
358
+ return {
359
+ // State
360
+ isScanning,
361
+ isReady,
362
+ products,
363
+ barcodes,
364
+ frameNumber,
365
+ fps,
366
+ error,
367
+ inferenceTimeMs: inferenceTimeMsRef.current,
368
+ // Actions
369
+ startScanning,
370
+ stopScanning,
371
+ toggleScanning,
372
+ clearDetections,
373
+ captureFrame,
374
+ // Camera ref
375
+ cameraRef,
376
+ // Frame processor config
377
+ frameProcessorConfig,
378
+ // TFLite frame processor (use this with VisionCamera)
379
+ frameProcessor: useOnDeviceFrameProcessor ? tfliteFrameProcessor.frameProcessor : undefined,
380
+ };
381
+ }
382
+ export default useVideoScanner;
383
+ //# sourceMappingURL=useVideoScanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVideoScanner.js","sourceRoot":"","sources":["../../../src/hooks/useVideoScanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQ1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EACL,uBAAuB,GAExB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAsGzC,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;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e,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @souschef/ml-vision
3
+ *
4
+ * ML-powered product detection for React Native
5
+ *
6
+ * Features:
7
+ * - Multi-barcode scanning (scan multiple barcodes at once)
8
+ * - Receipt OCR (photograph receipts to extract items)
9
+ * - Visual product recognition (recognize fridge/pantry contents)
10
+ * - Video scanning (real-time product detection)
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import {
15
+ * MLVisionProvider,
16
+ * useMultiBarcodeScanner,
17
+ * useProductDetector,
18
+ * useReceiptScanner,
19
+ * } from '@souschef/ml-vision';
20
+ *
21
+ * // Wrap your app with the provider
22
+ * function App() {
23
+ * return (
24
+ * <MLVisionProvider
25
+ * config={{ serverUrl: 'http://192.168.1.100:8000' }}
26
+ * storage={mmkvInstance}
27
+ * >
28
+ * <YourApp />
29
+ * </MLVisionProvider>
30
+ * );
31
+ * }
32
+ *
33
+ * // Use hooks in your components
34
+ * function ScannerScreen() {
35
+ * const { scanPhoto, results } = useMultiBarcodeScanner();
36
+ * const { detectProducts, detections } = useProductDetector();
37
+ *
38
+ * // ...
39
+ * }
40
+ * ```
41
+ *
42
+ * @packageDocumentation
43
+ */
44
+ // Re-export barcode format constants
45
+ export { GROCERY_BARCODE_FORMATS } from './types/barcode';
46
+ // ============================================================================
47
+ // Core - Provider, Cache, Server Client
48
+ // ============================================================================
49
+ export {
50
+ // Provider
51
+ MLVisionProvider, useMLVisionContext, useMLVisionReady,
52
+ // Cache
53
+ CacheManager, createCacheManager, CACHE_TTL,
54
+ // Server Client
55
+ ServerClient, createServerClient, ServerError, } from './core';
56
+ // ============================================================================
57
+ // Hooks
58
+ // ============================================================================
59
+ // Phase 3: Visual product detection
60
+ export { useProductDetector } from './hooks/useProductDetector';
61
+ export { CLASS_LABELS, NUM_CLASSES, getClassInfo, getLabelsArray, CATEGORY_CLASSES, } from './hooks/classLabels';
62
+ // Phase 5: Multi-barcode scanning
63
+ export { useMultiBarcodeScanner } from './hooks/useMultiBarcodeScanner';
64
+ // Phase 6: Receipt OCR
65
+ export { useReceiptScanner } from './hooks/useReceiptScanner';
66
+ // Phase 7: Video scanning
67
+ export { useVideoScanner, } from './hooks/useVideoScanner';
68
+ // ============================================================================
69
+ // Components
70
+ // ============================================================================
71
+ export { DetectionOverlay, DetectionLoadingOverlay, } from './components';
72
+ // ============================================================================
73
+ // Processors
74
+ // ============================================================================
75
+ export { createDetectionProcessor, frameDetectionToResult, getClassLabel, } from './processors';
76
+ // TFLite Frame Processor for real-time video scanning
77
+ export { useTFLiteFrameProcessor, createTFLiteFrameProcessor, } from './processors';
78
+ // ============================================================================
79
+ // Utilities
80
+ // ============================================================================
81
+ // Image preprocessing for on-device TFLite inference
82
+ export { preprocessImage, isSkiaAvailable, isResizePluginAvailable, getFrameProcessorInstructions, } from './utils/imagePreprocessor';
83
+ // YOLO output processing
84
+ export { processYoloOutput, scaleDetections, } from './utils/yoloProcessor';
85
+ // COCO class labels (80 classes for general object detection)
86
+ export { COCO_CLASSES, CLASS_LABELS_COCO, NUM_CLASSES_COCO, FOOD_CLASS_INDICES, getCocoClassInfo, isFoodClass, } from './hooks/classLabelsCoco';
87
+ // Logger utility
88
+ export { logger, setLogLevel, getLogLevel, } from './utils/logger';
89
+ // ============================================================================
90
+ // Version
91
+ // ============================================================================
92
+ export const VERSION = '0.1.1';
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAsDH,qCAAqC;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,+EAA+E;AAC/E,wCAAwC;AACxC,+EAA+E;AAE/E,OAAO;AACL,WAAW;AACX,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB;AAIhB,QAAQ;AACR,YAAY,EACZ,kBAAkB,EAClB,SAAS;AAI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gBAAgB,CAAC;AAExB,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Detection Frame Processor
3
+ *
4
+ * VisionCamera frame processor for real-time product detection.
5
+ * Uses react-native-fast-tflite for on-device inference.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { useFrameProcessor } from 'react-native-vision-camera';
10
+ * import { detectProducts } from '@souschef/ml-vision/processors';
11
+ *
12
+ * function CameraScreen() {
13
+ * const frameProcessor = useFrameProcessor((frame) => {
14
+ * 'worklet';
15
+ * const detections = detectProducts(frame);
16
+ * // Handle detections...
17
+ * }, []);
18
+ *
19
+ * return <Camera frameProcessor={frameProcessor} />;
20
+ * }
21
+ * ```
22
+ */
23
+ import { CLASS_LABELS, NUM_CLASSES } from '../hooks/classLabels';
24
+ // ============================================================================
25
+ // Frame Counter for Skipping
26
+ // ============================================================================
27
+ let frameCounter = 0;
28
+ // ============================================================================
29
+ // Frame Processor Plugin
30
+ // ============================================================================
31
+ /**
32
+ * Create a detection frame processor
33
+ *
34
+ * This returns a function that can be used with VisionCamera's useFrameProcessor.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const detectFrame = createDetectionProcessor({
39
+ * minConfidence: 0.5,
40
+ * maxDetections: 10,
41
+ * });
42
+ *
43
+ * const frameProcessor = useFrameProcessor((frame) => {
44
+ * 'worklet';
45
+ * const detections = detectFrame(frame);
46
+ * runOnJS(handleDetections)(detections);
47
+ * }, []);
48
+ * ```
49
+ */
50
+ export function createDetectionProcessor(options = {}) {
51
+ const { frameSkip = 3 } = options;
52
+ /**
53
+ * The actual frame processor function
54
+ *
55
+ * Note: This is a placeholder that shows the expected interface.
56
+ * The actual TFLite inference requires native module integration
57
+ * via react-native-fast-tflite's useRunOnce or similar.
58
+ */
59
+ return function detectProductsInFrame(_frame) {
60
+ 'worklet';
61
+ // Frame skipping for performance
62
+ frameCounter++;
63
+ if (frameCounter % frameSkip !== 0) {
64
+ return [];
65
+ }
66
+ // In a real implementation, this would:
67
+ // 1. Get frame data from VisionCamera
68
+ // 2. Preprocess for TFLite input
69
+ // 3. Run inference via react-native-fast-tflite
70
+ // 4. Post-process output
71
+ // Placeholder - actual implementation requires native TFLite integration
72
+ // with VisionCamera frame processors using Reanimated worklets
73
+ return [];
74
+ };
75
+ }
76
+ // ============================================================================
77
+ // Utility Functions
78
+ // ============================================================================
79
+ /**
80
+ * Convert FrameDetection to ProductDetectionResult
81
+ *
82
+ * Call this on the JS thread after receiving worklet results.
83
+ */
84
+ export function frameDetectionToResult(detection, imageWidth, imageHeight) {
85
+ const classInfo = CLASS_LABELS[detection.classIndex] ?? {
86
+ label: `class_${detection.classIndex}`,
87
+ category: 'unknown',
88
+ };
89
+ const boundingBox = {
90
+ x: detection.box.x * imageWidth,
91
+ y: detection.box.y * imageHeight,
92
+ width: detection.box.width * imageWidth,
93
+ height: detection.box.height * imageHeight,
94
+ };
95
+ return {
96
+ id: `frame_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
97
+ type: 'product',
98
+ confidence: detection.confidence,
99
+ boundingBox,
100
+ data: {
101
+ category: classInfo.category,
102
+ classLabel: classInfo.label,
103
+ classIndex: detection.classIndex,
104
+ name: classInfo.label.replace(/_/g, ' '),
105
+ },
106
+ source: 'on_device',
107
+ processingTimeMs: 0, // Frame processor timing handled externally
108
+ timestamp: Date.now(),
109
+ };
110
+ }
111
+ /**
112
+ * Get label for class index (can be called from worklet via shared value)
113
+ */
114
+ export function getClassLabel(classIndex) {
115
+ return CLASS_LABELS[classIndex]?.label ?? `class_${classIndex}`;
116
+ }
117
+ // ============================================================================
118
+ // Export
119
+ // ============================================================================
120
+ export { NUM_CLASSES, CLASS_LABELS };
121
+ //# sourceMappingURL=detectionProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detectionProcessor.js","sourceRoot":"","sources":["../../../src/processors/detectionProcessor.ts"],"names":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MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,GAAG,WAAW;KAC3C,CAAC;IAEF,OAAO;QACL,EAAE,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QACpE,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,SAAS,CAAC,UAAU;QAChC,WAAW;QACX,IAAI,EAAE;YACJ,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,UAAU,EAAE,SAAS,CAAC,KAAK;YAC3B,UAAU,EAAE,SAAS,CAAC,UAAU;YAChC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SACzC;QACD,MAAM,EAAE,WAAW;QACnB,gBAAgB,EAAE,CAAC,EAAE,4CAA4C;QACjE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC9C,OAAO,YAAY,CAAC,UAAU,CAAC,EAAE,KAAK,IAAI,SAAS,UAAU,EAAE,CAAC;AAClE,CAAC;AAED,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Processors exports
3
+ */
4
+ export { createDetectionProcessor, frameDetectionToResult, getClassLabel, NUM_CLASSES, CLASS_LABELS, } from './detectionProcessor';
5
+ // TFLite Frame Processor for real-time video scanning
6
+ export { useTFLiteFrameProcessor, createTFLiteFrameProcessor, } from './tfliteFrameProcessor';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/processors/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAE9B,sDAAsD;AACtD,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAI3B,MAAM,wBAAwB,CAAC"}