flutter - Flutter 人脸检测
问题描述
我正在尝试flutter camera ml vision的示例应用程序 现在我想做的是仅在自定义画家的范围内拍摄面部照片并保存为png。
在默认示例中,自定义画家是一个带有粗红色边框的正方形,显示在检测到的面部周围,但现在我需要帮助的是在该正方形内拍摄面部照片。
解决方案
基本上你想从原始图像中裁剪面部部分。所以使用这个 库来裁剪图像。所以我假设你在面部周围显示框时具有面部的坐标值。
导入此图像库并使用以下方法裁剪图像:
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);
}
推荐阅读
- go - gopacket ubuntu16.04 错误未定义:pcapErrorNotActivated
- python - 需要验证scikit-learn开发版是否安装正确
- kernel - 我如何使用 cscope 在 linux 内核中查找 task_struct
- python - 使用 Python 编辑 pdf 中的信息
- java - 为什么从 File->BufferedImage->byte[] 转换时,我的 jpg 图像尺寸会变小
- sqlite - 如何在 ionic v3 中重新创建 sqlite 数据库?
- c# - UserControl 从 MainWindow 获取更新的数据
- sql - 如何更新列的值?
- java - 我想使用 lambda 表达式而不是 addOnCompleteListener(new OnCompleteListener
() { { - javascript - 如何在弹出窗口出现和消失后延迟背景显示