首页 >> 选宠技巧
选宠技巧

flutter人脸识别

发布时间:2024-01-07 12:18

lensDirection == widget.initialDirection && element.sensorOrientation == 90), ); } else { for (var i = 0; i < cameras.length; i++) { if (cameras[i].lensDirection == widget.initialDirection) { _cameraIndex = i; break; } } } if (_cameraIndex != -1) { _startLiveFeed(); } subscription = eventBus.on().listen((event) { switch (event.faceFlag) { case 1: _faceImageBg = AssetsUtils.faceBorderGrey; break; case 2: _faceImageBg = AssetsUtils.faceBorderRed; break; case 3: _faceImageBg = AssetsUtils.faceBorderGreen; break; } setState(() {}); }); } @override void dispose() { _stopLiveFeed(); subscription?.cancel(); subscription = null; super.dispose(); } @override Widget build(BuildContext context) { return _body(); } Widget _body() { Widget body; body = _liveFeedBody(); return body; } Widget _liveFeedBody() { if (_controller?.value.isInitialized == false) { return Container(); } final size = MediaQuery.of(context).size; // calculate scale depending on screen and camera ratios // this is actually size.aspectRatio / (1 / camera.aspectRatio) // because camera preview size is received as landscape // but we're calculating for portrait orientation var scale = size.aspectRatio * _controller!.value.aspectRatio; // to prevent scaling down, invert the value if (scale < 1) scale = 1 / scale; return Container( width: size.width, height: 300.h, color: Colors.white, child: Stack( fit: StackFit.expand, children: [ Center(child: CameraPreview(_controller!)), Image.asset( _faceImageBg, fit: BoxFit.fill, ), ], ), ); } Future _startLiveFeed() async { final camera = cameras[_cameraIndex]; _controller = CameraController(camera, ResolutionPreset.high, enableAudio: false, imageFormatGroup: Platform.isIOS ? ImageFormatGroup.bgra8888 : ImageFormatGroup.yuv420); _controller?.initialize().then((_) { if (!mounted) { return; } _controller?.startImageStream(_processCameraImage); setState(() {}); }).catchError((Object e) { if (e is CameraException) { switch (e.code) { case 'CameraAccessDenied': SmartDialog.showToast( "你已经拒绝了单反相机权限,请去设置中打开权限", ); break; default: SmartDialog.showToast( e.description.toString(), ); break; } } }); } Future _stopLiveFeed() async { await _controller?.stopImageStream(); await _controller?.dispose(); _controller = null; } Future _processCameraImage(CameraImage image) async { final WriteBuffer allBytes = WriteBuffer(); 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()); final camera = cameras[_cameraIndex]; final imageRotation = InputImageRotationValue.fromRawValue(camera.sensorOrientation); if (imageRotation == null) return; final inputImageFormat = InputImageFormatValue.fromRawValue(image.format.raw); if (inputImageFormat == null) return; final planeData = image.planes.map( (Plane plane) { return InputImagePlaneMetadata( bytesPerRow: plane.bytesPerRow, height: plane.height, width: plane.width, ); }, ).toList(); final inputImageData = InputImageData( size: imageSize, imageRotation: imageRotation, inputImageFormat: inputImageFormat, planeData: planeData, ); final inputImage = InputImage.fromBytes(bytes: bytes, inputImageData: inputImageData); widget.onImage(inputImage, image); }}

至于Isolate的标识符的处理须要网易啊,也很简单的

拉肚子能用蒙脱石散吗
胃肠炎吃什么药?专家:需了解病因对症用药
儿童装江中健胃消食片
注射用胸腺法新迈普新效果
眼睛视疲劳用哪个眼药水好
友情链接