liuyuqi-dellpc 2 years ago
parent
commit
5daecb8a07
4 changed files with 31 additions and 8 deletions
  1. 4 1
      lib/common/camera.dart
  2. 3 1
      lib/common/transform.dart
  3. 15 0
      lib/main.dart
  4. 9 6
      lib/screen/home/home.dart

+ 4 - 1
lib/common/camera.dart

@@ -4,13 +4,16 @@ import 'package:camera/camera.dart';
 import 'package:flutter/foundation.dart';
 import 'package:google_mlkit_object_detection/google_mlkit_object_detection.dart';
 
+/// 图片预处理
+/// [camera] 相机
+/// [image] 图片
+/// [onImage] 回调函数
 Future<InputImage?> processCameraImage(
   CameraDescription camera,
   CameraImage image,
   void Function(InputImage inputImage) onImage,
 ) async {
   final WriteBuffer allBytes = WriteBuffer();
-  // ignore: curly_braces_in_flow_control_structures
   for (final Plane plane in image.planes) allBytes.putUint8List(plane.bytes);
   final bytes = allBytes.done().buffer.asUint8List();
   final Size imageSize = Size(image.width.toDouble(), image.height.toDouble());

+ 3 - 1
lib/common/transform.dart

@@ -2,6 +2,7 @@ import 'dart:io';
 import 'dart:ui';
 import 'package:google_mlkit_object_detection/google_mlkit_object_detection.dart';
 
+/// x
 double translateX(double x, InputImageRotation rotation, Size size, Size absoluteImageSize) {
   switch (rotation) {
     case InputImageRotation.rotation90deg:
@@ -12,7 +13,8 @@ double translateX(double x, InputImageRotation rotation, Size size, Size absolut
       return x * size.width / absoluteImageSize.width;
   }
 }
-
+/// x
+/// [y] 原始坐标
 double translateY(double y, InputImageRotation rotation, Size size, Size absoluteImageSize) {
   switch (rotation) {
     case InputImageRotation.rotation90deg:

+ 15 - 0
lib/main.dart

@@ -1,9 +1,24 @@
+import 'dart:io';
+
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 import 'package:internal/screen/home/home.dart';
 
+/// Description: enter point
+/// Time       : 04/12/2023 Wednesday
+/// Author     : liuyuqi.gov@msn.cn
 void main() {
+  WidgetsFlutterBinding.ensureInitialized();
 
   runApp(const App());
+  if (Platform.isAndroid) {
+    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
+      statusBarColor: Colors.transparent,
+      statusBarIconBrightness: Brightness.dark,
+      systemNavigationBarColor: Colors.transparent,
+      systemNavigationBarIconBrightness: Brightness.dark,
+    ));
+  }
 }
 
 class App extends StatelessWidget {

+ 9 - 6
lib/screen/home/home.dart

@@ -49,14 +49,15 @@ class _HomeScreenState extends State<HomeScreen> {
     /// 检测可用相机
     availableCameras().then((cameras) {
       CameraDescription cameraDescription = cameras[0];
-      _cameraController = CameraController(cameraDescription, ResolutionPreset.high, enableAudio: false);
+      _cameraController = CameraController(cameraDescription, ResolutionPreset.high, enableAudio: false); // ResolutionPreset.high 质量较高的预设,不录音
       _cameraController!.initialize().then((_) {
         _cameraController!.startImageStream((image) => processCameraImage(cameraDescription, image, onImage));
         setState(() {});
       });
     });
   }
-  /// 回调函数
+
+  /// 回调函数,处理camera拍摄的图片
   Future<void> onImage(InputImage inputImage) async {
     if (!_canRender) return;
     _canRender = false;
@@ -65,9 +66,10 @@ class _HomeScreenState extends State<HomeScreen> {
     if (!xx) await shouldGUIDELINE(inputImage);
     _canRender = true;
   }
-
+  /// 是否需要旋转图片
+  /// [inputImage] 图片
   Future<bool> shouldTURNAROUND(InputImage inputImage) async {
-    final list = await _textDetector.processImage(inputImage);
+    final list = await _textDetector.processImage(inputImage); // 识别文字
     Size? size = _cameraPreviewKey.currentContext?.size;
     if (size == null) {
       return false;
@@ -89,6 +91,7 @@ class _HomeScreenState extends State<HomeScreen> {
         message = "TURN AROUND";
         if (_canSpace) {
           _canSpace = false;
+          // 语音播放:打开录音
           tts.speak("TURN AROUND").then((_) => _canSpace = true);
         }
         _data.addAll(data);
@@ -98,9 +101,9 @@ class _HomeScreenState extends State<HomeScreen> {
     }
     return false;
   }
-  /// 检测指示
+  /// 是否需要引导
   Future<void> shouldGUIDELINE(InputImage inputImage) async {
-    final list = await _objectDetector.processImage(inputImage);
+    final list = await _objectDetector.processImage(inputImage); // 识别物体
     Size? size = _cameraPreviewKey.currentContext?.size;
     if (size == null) {
       return;