【问题标题】:Flutter Face DetectionFlutter 人脸检测
【发布时间】:2021-09-09 14:29:07
【问题描述】:

我正在试用flutter camera ml vision 的示例应用程序 现在我想做的是只在自定义画家的范围内拍一张脸,然后保存为 png。

在默认示例中,自定义画家是一个带有粗红色边框的正方形,显示在检测到的面部周围,但现在我需要帮助的是在该正方形内拍摄面部照片。

【问题讨论】:

    标签: flutter camera face-detection mlvision


    【解决方案1】:

    基本上你想从原始图像中裁剪面部。所以使用this库来裁剪图像。所以我假设你在脸部周围显示框时具有脸部的坐标值。

    导入此image 库并使用以下方法裁剪图像:

    import 'package:image/image.dart' as IMG;
    
    Future<void> cropSquare(String srcFilePath, String destFilePath) async {
      final bytes = await File(srcFilePath).readAsBytes();
      IMG.Image src = IMG.decodeImage(bytes);
    
      // pass x and y(offset),width, height value of face bounding box you detected
      IMG.Image destImage = IMG.copyCrop(src, x, y, width, height);
    
      final png = IMG.encodePng(destImage);
      await File(destFilePath).writeAsBytes(png);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-02
      • 1970-01-01
      • 2019-11-18
      • 2013-09-24
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      • 2022-11-24
      • 2013-07-16
      相关资源
      最近更新 更多