【问题标题】:x + width must be <= bitmap.width()x + 宽度必须 <= bitmap.width()
【发布时间】:2021-02-18 23:34:02
【问题描述】:

我正在尝试使用 google-mlkit 开发人脸检测。按照 google-mlkit https://developers.google.com/ml-kit/vision/face-detection/android 的文档设置相机、分析仪、检测器等后,我能够检测到人脸。检测到人脸后,我正在尝试提取检测到的人脸图像。

获取检测到的人脸boundingBox,使用boundingBox将完整的位图提取到检测到的人脸位图中。代码如下。

Bitmap bmp = Bitmap.createBitmap(mediaImage.getWidth(), mediaImage.getHeight(), Bitmap.Config.ARGB_8888);                                             
YuvToRgbConverter converter = new YuvToRgbConverter(context);
converter.yuvToRgb(mediaImage, bmp);
Bitmap extractedBmp = extractFace(
   bmp,
   (int) (face.getBoundingBox().exactCenterX() / 2),
   (int) (face.getBoundingBox().exactCenterY() / 2),
   face.getBoundingBox().width(),
   face.getBoundingBox().height()
);

private Bitmap extractFace(Bitmap bmp, int x, int y, int width, int height) {
  return Bitmap.createBitmap(bmp, x, y, width, height);
}

有时成功,有时也失败。调试后发现是x + width must be &lt;= bitmap.width()的错误。 我做错了什么?

【问题讨论】:

    标签: android face-detection google-mlkit


    【解决方案1】:

    您能否尝试使用 mlkit 示例 here 中提供的 util 方法从 YUV 图像创建 bimap?

    【讨论】:

    • ok,我先试试。我会回复你的结果。
    猜你喜欢
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多