【问题标题】:Expo image-manipulator crop - according to facedetector valuesExpo image-manipulator crop - 根据 facedetector 的值
【发布时间】:2021-03-25 15:04:37
【问题描述】:

简短:如何使用面部检测器坐标和大小进行图像操纵器裁剪?我想从照片中裁剪人脸。

解释;

我使用带有面部检测功能的曝光相机。它工作得很好。人脸检测器给出输出对象

 "origin": Object {
    "x": 85.00000000000006,
    "y": 231.35,   },   "size": Object {
    "height": 182,
    "width": 173.33333333333331,   }, }

我可以在相机预览模式下用该坐标在脸部周围绘制一个框,它适合屏幕尺寸。拍摄图像后,输出图像比相机预览大得多。所以我不能用那个坐标来裁剪图片。我根据图像大小更新了面部检测器坐标和大小。例如,如果图像宽度是屏幕宽度的 2 倍,我将 originx 和宽度乘以 2。但图像操纵器裁剪并没有给我想要的结果。 任何帮助将不胜感激。

【问题讨论】:

  • 我也有同样的问题,你能解决吗?
  • 是的,我解决了。它有点复杂,但仍然很容易。

标签: react-native expo expo-camera


【解决方案1】:

这是我的解决方案。我取屏幕尺寸和人脸尺寸的百分比。

const growthFactor = {
          w: data.width / width,
          h: data.height / height,
        };
        const cropDimensions = {
          originX: Math.round(
            growthFactor.w * face.origin.x
          ),
          originY: Math.round(
            growthFactor.h * face.origin.y
          ),
          width: Math.round(
            growthFactor.h * face.size.height
          ),
          height: Math.round(
            growthFactor.h * face.size.height
          ),
        };

附言。我将高度和宽度都与 growtfactor.h 相乘,因为我需要方形裁剪照片。

【讨论】:

  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 2021-11-25
  • 2020-08-02
  • 1970-01-01
  • 2022-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多