首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >X+宽度必须为<= bitmap.width()

X+宽度必须为<= bitmap.width()
EN

Stack Overflow用户
提问于 2020-11-06 16:27:29
回答 1查看 243关注 0票数 0

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

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

代码语言:javascript
复制
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 <= bitmap.width()导致的错误。我哪里做错了?

EN

回答 1

Stack Overflow用户

发布于 2020-11-14 04:27:08

您可以尝试mlkit示例here中提供的util方法来从YUV图像创建bimap吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64711144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档