Title: my flutter sign language detector is not detecting anything · Issue #554 · OpenSourceHelpCommunity/Questions · GitHub
Open Graph Title: my flutter sign language detector is not detecting anything · Issue #554 · OpenSourceHelpCommunity/Questions
X Title: my flutter sign language detector is not detecting anything · Issue #554 · OpenSourceHelpCommunity/Questions
Description: i am using SSDMOBILENETV2 FPN LITE 320x32 pretrained model and i trained it with my custom sign language datasets. here is my object_detection_service.dart `import 'package:camera/camera.dart'; import 'package:tflite_flutter/tflite_flutt...
Open Graph Description: i am using SSDMOBILENETV2 FPN LITE 320x32 pretrained model and i trained it with my custom sign language datasets. here is my object_detection_service.dart `import 'package:camera/camera.dart'; imp...
X Description: i am using SSDMOBILENETV2 FPN LITE 320x32 pretrained model and i trained it with my custom sign language datasets. here is my object_detection_service.dart `import 'package:camera/camera.dart...
Opengraph URL: https://github.com/OpenSourceHelpCommunity/Questions/issues/554
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"my flutter sign language detector is not detecting anything","articleBody":"i am using SSDMOBILENETV2 FPN LITE 320x32 pretrained model and i trained it with my custom sign language datasets.\n\nhere is my object_detection_service.dart\n`import 'package:camera/camera.dart';\nimport 'package:tflite_flutter/tflite_flutter.dart';\nimport 'package:image/image.dart' as img;\nimport 'dart:developer' as dev;\n\nclass InferenceData {\n final Interpreter interpreter;\n final List\u003cList\u003cList\u003cList\u003cdouble>>>> inputData;\n\n InferenceData(this.interpreter, this.inputData);\n}\n\nclass InferenceResult {\n final List\u003cdouble> scores;\n final List\u003cList\u003cdouble>> boxes;\n final List\u003cdouble> classes;\n\n InferenceResult(this.scores, this.boxes, this.classes);\n}\n\nclass ObjectDetectionService {\n static const int inputSize = 320;\n static const double confidenceThreshold = 0.1;\n\n static void _log(String message) {\n dev.log('[ObjectDetection] $message');\n }\n\n static Future\u003cList\u003cList\u003cList\u003cList\u003cdouble>>>>> preprocessImageIsolate(CameraImage image) async {\n try {\n final img.Image rgbImage;\n if (image.format.group == ImageFormatGroup.yuv420) {\n rgbImage = _convertYUV420(image);\n } else if (image.format.group == ImageFormatGroup.bgra8888) {\n rgbImage = _convertBGRA8888(image);\n } else {\n throw Exception('Unsupported image format: ${image.format.group}');\n }\n\n final resized = img.copyResize(\n rgbImage,\n width: inputSize,\n height: inputSize,\n interpolation: img.Interpolation.linear,\n );\n\n final input = List.generate(\n 1,\n (index) => List.generate(\n inputSize,\n (y) => List.generate(\n inputSize,\n (x) => List.generate(\n 3,\n (c) {\n final pixel = resized.getPixel(x, y);\n // Normalize to [0, 1] instead of [-1, 1]\n return c == 0\n ? pixel.r / 255.0\n : c == 1\n ? pixel.g / 255.0\n : pixel.b / 255.0;\n },\n ),\n ),\n ),\n );\n\n _log('Image preprocessed');\n return input;\n } catch (e, stack) {\n _log('Preprocessing error: $e\\n$stack');\n throw Exception('Preprocessing failed: $e');\n }\n }\n\n static img.Image _convertYUV420(CameraImage image) {\n final width = image.width;\n final height = image.height;\n final yPlane = image.planes[0].bytes;\n final uPlane = image.planes[1].bytes;\n final vPlane = image.planes[2].bytes;\n\n final yRowStride = image.planes[0].bytesPerRow;\n final uvRowStride = image.planes[1].bytesPerRow;\n final uvPixelStride = image.planes[1].bytesPerPixel!;\n\n final output = img.Image(width: width, height: height);\n\n for (int y = 0; y \u003c height; y++) {\n for (int x = 0; x \u003c width; x++) {\n final int yIndex = y * yRowStride + x;\n final int uvIndex = (y ~/ 2) * uvRowStride + (x ~/ 2) * uvPixelStride;\n\n final yValue = yPlane[yIndex];\n final uValue = uPlane[uvIndex];\n final vValue = vPlane[uvIndex];\n\n // Using standard YUV to RGB conversion\n final int r = (yValue + (1.370705 * (vValue - 128))).toInt().clamp(0, 255);\n final int g = (yValue - (0.698001 * (vValue - 128)) - (0.337633 * (uValue - 128))).toInt().clamp(0, 255);\n final int b = (yValue + (1.732446 * (uValue - 128))).toInt().clamp(0, 255);\n\n output.setPixelRgb(x, y, r, g, b);\n }\n }\n\n return output;\n }\n\n static img.Image _convertBGRA8888(CameraImage image) {\n return img.Image.fromBytes(\n width: image.width,\n height: image.height,\n bytes: image.planes[0].bytes.buffer,\n order: img.ChannelOrder.bgra,\n );\n }\n\n static Future\u003cInferenceResult?> runInferenceIsolate(InferenceData data) async {\n try {\n final outputBoxes = List\u003cList\u003cdouble>>.generate(\n 100,\n (_) => List\u003cdouble>.filled(4, 0.0),\n );\n final outputClasses = List\u003cdouble>.filled(100, 0);\n final outputScores = List\u003cdouble>.filled(100, 0);\n final outputCount = [1.0];\n\n final outputs = {\n 0: outputScores,\n 1: outputBoxes,\n 2: outputCount,\n 3: outputClasses,\n };\n\n data.interpreter.runForMultipleInputs([data.inputData], outputs);\n\n // Debug logging\n _log('Scores: ${outputScores.take(5).toList()}');\n _log('Classes: ${outputClasses.take(5).toList()}');\n _log('First box: ${outputBoxes[0]}');\n\n return InferenceResult(\n outputScores,\n outputBoxes,\n outputClasses,\n );\n } catch (e, stack) {\n _log('Inference error: $e\\n$stack');\n return null;\n }\n }\n}\n\n\n`\n\nand my scan_controller.dart: \n`import 'dart:developer' as dev;\nimport 'package:camera/camera.dart';\nimport 'package:get/get.dart';\nimport 'package:tflite_flutter/tflite_flutter.dart';\nimport 'package:flutter/services.dart';\nimport 'package:flutter/foundation.dart';\nimport 'camera_service.dart';\nimport 'object_detection_service.dart';\n\nclass ScanController extends GetxController {\n final List\u003cCameraDescription> cameras;\n late CameraService cameraService;\n late ObjectDetectionService detectionService;\n Interpreter? interpreter;\n List\u003cString> labels = [];\n\n RxBool isCameraInitialized = false.obs;\n RxString errorMessage = ''.obs;\n RxString label = ''.obs;\n RxDouble x = 0.0.obs;\n RxDouble y = 0.0.obs;\n RxDouble w = 0.0.obs;\n RxDouble h = 0.0.obs;\n RxBool isProcessing = false.obs;\n RxBool isTabActive = true.obs;\n\n static const String modelPath = 'assets/model.tflite';\n static const String labelsPath = 'assets/labels.txt';\n static const Duration _processingInterval = Duration(milliseconds: 100);\n DateTime _lastProcessingTime = DateTime.now();\n\n ScanController({required this.cameras}) {\n cameraService = CameraService(cameras: cameras);\n detectionService = ObjectDetectionService();\n }\n\n void _log(String message) {\n dev.log('[ScanController] $message');\n }\n\n @override\n void onInit() {\n super.onInit();\n _initialize();\n }\n\n @override\n void onClose() {\n disposeResources();\n super.onClose();\n }\n\n Future\u003cvoid> _initialize() async {\n try {\n _log('Starting initialization');\n \n final options = InterpreterOptions()..threads = 4;\n \n interpreter = await Interpreter.fromAsset(\n modelPath,\n options: options,\n );\n\n // Log interpreter details\n final inputTensor = interpreter!.getInputTensor(0);\n final outputTensor = interpreter!.getOutputTensor(0);\n _log('Input tensor shape: ${inputTensor.shape}');\n _log('Output tensor shape: ${outputTensor.shape}');\n\n await loadLabels();\n await initializeCamera();\n _log('Initialization complete');\n } catch (e, stack) {\n errorMessage.value = 'Initialization error: $e';\n _log('Initialization error: $e\\n$stack');\n }\n }\n\n Future\u003cvoid> loadLabels() async {\n try {\n final labelData = await rootBundle.loadString(labelsPath);\n labels = labelData.split('\\n')\n .where((label) => label.trim().isNotEmpty)\n .toList();\n _log('Labels loaded: ${labels.length}');\n _log('First 5 labels: ${labels.take(5).toList()}');\n } catch (e) {\n _log('Error loading labels: $e');\n rethrow;\n }\n }\n\n Future\u003cvoid> initializeCamera() async {\n try {\n await cameraService.initialize();\n if (isTabActive.value) {\n await startCamera();\n }\n isCameraInitialized.value = true;\n } catch (e) {\n errorMessage.value = e.toString();\n _log('Camera initialization error: $e');\n rethrow;\n }\n }\n\n Future\u003cvoid> startCamera() async {\n if (!isCameraInitialized.value) return;\n await cameraService.startImageStream(_processCameraImage);\n }\n\n Future\u003cvoid> stopCamera() async {\n await cameraService.stopImageStream();\n }\n\n Future\u003cvoid> disposeResources() async {\n try {\n await cameraService.dispose();\n interpreter?.close();\n isProcessing.value = false;\n isCameraInitialized.value = false;\n } catch (e) {\n _log('Error during resource disposal: $e');\n }\n }\n\n Future\u003cvoid> _processCameraImage(CameraImage image) async {\n if (isProcessing.value) return;\n\n final now = DateTime.now();\n if (now.difference(_lastProcessingTime) \u003c _processingInterval) return;\n \n _lastProcessingTime = now;\n isProcessing.value = true;\n\n try {\n if (interpreter == null) {\n _log('Interpreter not ready');\n return;\n }\n\n final inputData = await compute(\n ObjectDetectionService.preprocessImageIsolate,\n image,\n );\n _log('Image preprocessed');\n\n final outputs = await compute(\n ObjectDetectionService.runInferenceIsolate,\n InferenceData(interpreter!, inputData),\n );\n _log('Inference run completed');\n\n if (outputs != null) {\n _processDetections(\n outputs.scores,\n outputs.boxes,\n outputs.classes,\n );\n }\n } catch (e, stack) {\n _log('Processing error: $e\\n$stack');\n } finally {\n isProcessing.value = false;\n }\n }\n\n void _processDetections(\n List\u003cdouble> scores,\n List\u003cList\u003cdouble>> boxes,\n List\u003cdouble> classes,\n ) {\n try {\n double maxScore = 0;\n int maxIndex = -1;\n\n _log('Processing detections:');\n _log('Scores: ${scores.take(5)}');\n _log('Classes: ${classes.take(5)}');\n\n for (var i = 0; i \u003c scores.length; i++) {\n if (scores[i] > maxScore && \n scores[i] > ObjectDetectionService.confidenceThreshold) {\n maxScore = scores[i];\n maxIndex = i;\n }\n }\n\n if (maxIndex != -1) {\n final box = boxes[maxIndex];\n final classIndex = classes[maxIndex].toInt();\n if (classIndex \u003c labels.length) {\n label.value = '${labels[classIndex]} ${(maxScore * 100).toStringAsFixed(0)}%';\n y.value = box[0];\n x.value = box[1];\n h.value = box[2] - box[0];\n w.value = box[3] - box[1];\n _log('Detection: ${label.value} at ($x, $y) with size ($w, $h)');\n }\n } else {\n label.value = '';\n }\n } catch (e, stack) {\n _log('Detection processing error: $e\\n$stack');\n }\n }\n}`\n\ni have been working on this for weeks now and i dont know what else to do, i am also new to programming.","author":{"url":"https://github.com/janrabang","@type":"Person","name":"janrabang"},"datePublished":"2025-02-13T03:37:48Z","url":"https://github.com/OpenSourceHelpCommunity/Questions/issues/554"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5ded06bd-9b33-a895-caa6-e865a3899c1a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D700:3A347:DB3F15:123B53A:6B00FE19 |
| html-safe-nonce | 7436f77e462235a71c0d51bcab2a7fd4e1f0b93d1d6dd4491859f001ec3a5c1b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzAwOjNBMzQ3OkRCM0YxNToxMjNCNTNBOjZCMDBGRTE5IiwidmlzaXRvcl9pZCI6IjU0MTQ5NDg5ODg4MTIwNjYzMjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 105759f9a014f0cf3530753ea8d35ff56e38ef6f27471458af6acebfc3f95e71 |
| hovercard-subject-tag | issue:2849862490 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/OpenSourceHelpCommunity/Questions/554/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0c79da0de7b8c514f5148a08ecac2c8afed5e1c762abfa7f4dec01eb7f077fd7/OpenSourceHelpCommunity/Questions/issues/554 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0c79da0de7b8c514f5148a08ecac2c8afed5e1c762abfa7f4dec01eb7f077fd7/OpenSourceHelpCommunity/Questions/issues/554 |
| og:image:alt | i am using SSDMOBILENETV2 FPN LITE 320x32 pretrained model and i trained it with my custom sign language datasets. here is my object_detection_service.dart `import 'package:camera/camera.dart'; imp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | janrabang |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| turbo-cache-control | no-preview |
| go-import | github.com/OpenSourceHelpCommunity/Questions git https://github.com/OpenSourceHelpCommunity/Questions.git |
| octolytics-dimension-user_id | 23719480 |
| octolytics-dimension-user_login | OpenSourceHelpCommunity |
| octolytics-dimension-repository_id | 78395582 |
| octolytics-dimension-repository_nwo | OpenSourceHelpCommunity/Questions |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 78395582 |
| octolytics-dimension-repository_network_root_nwo | OpenSourceHelpCommunity/Questions |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width