Flutter google ml 套件人脸检测字节缓冲区和大小不匹配

问题描述 投票:0回答:1

错误:

E/MethodChannel#google_mlkit_face_detector(20979):java.lang.IllegalArgumentException:图像尺寸、ByteBuffer 大小和格式不匹配。请检查ByteBuffer是否为贴花格式。

 Future<void> initializeCamera() async { _cameras = await availableCameras(); if (_cameras == null || _cameras!.isEmpty) { showDialog( context: context, builder: (context) { return AlertDialog( title: Text('Kamera Hatası'), content: Text('Cihazınızda bir kamera bulunmuyor.'), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: Text('Tamam'), ), ], ); }, ); return; } else { final selectedCamera = _cameras![_selectedCameraIndex]; _cameraController = CameraController( selectedCamera, ResolutionPreset.medium, ); await _cameraController!.initialize(); // FaceDetector'ı başlat _faceDetector = GoogleMlKit.vision.faceDetector(); if (!mounted) { return; } setState(() { // Kamera başlatıldığında yüz algılama işlemi başlatın. startFaceDetection(); }); } } Future<void> startFaceDetection() async { await _cameraController!.startImageStream((CameraImage image) async { final inputImage = InputImage.fromBytes( bytes: image.planes[0].bytes, metadata: InputImageMetadata( size: Size(image.width.toDouble(), image.height.toDouble()), rotation: InputImageRotation.rotation0deg, format: InputImageFormat.nv21, bytesPerRow: image.planes[0].bytesPerRow, ), ); try { final List<Face> faces = await _faceDetector.processImage(inputImage); // Algılanan yüzlerle ilgili işlemleri burada yapabilirsiniz. for (Face face in faces) { final boundingBox = face.boundingBox; // Yüzün sınırlayıcı kutusu final headEulerAngleY = face.headEulerAngleY; // Yüzün başın eğim açısı final headEulerAngleZ = face.headEulerAngleZ; // Yüzün başın eğim açısı // Diğer özellikleri kullanabilirsiniz. } } catch (e, stackTrace) { print('Error processing image: $e\n$stackTrace'); } }); }

你好,我正在尝试用flutter做一个人脸检测项目。但我无法解决这个错误。

flutter face-detection google-mlkit
1个回答
0
投票

请将代码粘贴为块,粘贴为单行时无法读取

© www.soinside.com 2019 - 2024. All rights reserved.