【问题标题】:android mobile vision api custom detector not detecting faceandroid mobile vision api自定义检测器未检测到人脸
【发布时间】:2017-08-30 14:29:30
【问题描述】:

我正在探索 android vision api 并遵循 android 开发人员文档中提供的 github 示例。示例应用程序正在检测人脸。

我想裁剪检测到的每个人脸。 我有一个 rect obj 具有左、上、右、下坐标。

但我缺少用于裁剪面部的源位图。

我做过的事情

1.尝试使用SOF post中给出的自定义检测器

这里 myFaceDetector 的 SparseArray detect(Frame frame) 方法被重复调用,它没有检测到人脸。处理器集没有被调用。 我使用了下面的代码

    FaceDetector detector = new FaceDetector.Builder(context)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
            .build();

    MyFaceDetector myFaceDetector = new MyFaceDetector(detector);

    myFaceDetector.setProcessor(new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
    .build());

    mCameraSource = new CameraSource.Builder(context, myFaceDetector)
            .setRequestedPreviewSize(640, 480)
            .setFacing(CameraSource.CAMERA_FACING_FRONT)
            .setRequestedFps(2.0f)
            .build();

在相机预览开始后没有调用 GraphicFaceTrackerFactory()。

2.尝试将相机图片作为源位图,但连续拍照。

任何帮助都会非常有用。在此先感谢。

【问题讨论】:

    标签: android android-camera android-bitmap android-vision


    【解决方案1】:

    我想裁剪每个检测到的人脸。我有一个具有左、上、右、下坐标的矩形 obj。

    一旦检测到人脸,您可以通过 Face.getPosition() 、 Face.getHeight() 和 Face.getWidth() 获取人脸的位置和尺寸

    这里 myFaceDetector 的 SparseArray detect(Frame frame) 方法被重复调用,它没有检测到人脸

    您是否尝试过设置正确的方向?在 Frame.Builder 中,添加 setRotation(ROT),其中 ROT 是具有以下任何值的 int:0、1、2 或 3(分别表示 0、90、180 和 270 度)。在您引用的答案中提到了这一点:)

    但我缺少用于裁剪面部的源位图。

    可以像这样从当前帧生成位图

    Bitmap frameToBitmap(Frame currentFrame){
        ByteBuffer buffer = currentFrame.getGrayscaleImageData(); // getBitmap only works when the frame was created using Bitmap
        byte[] bytes = new byte[buffer.capacity()];
        buffer.get(bytes);
        int[] pixels = applyGrayScale(new int[bytes.length], bytes, img.getWidth(),img.getHeight());
        return Bitmap.createBitmap(pixels, img.getWidth(), img.getHeight(), Bitmap.Config.ARGB_8888);
    }
    
    static int[] applyGrayScale(int[] pixels, byte[] data, int width, int height) { //from another SOF answer...
        int p;
        int size = width*height;
        for(int i = 0; i < size; i++) {
            p = data[i] & 0xFF;
            pixels[i] = 0xff000000 | p<<16 | p<<8 | p;
        }
        return pixels;
    }
    

    附带说明,CamerSource 类有可用的代码,尽管在邻居示例中:BarCode Reader

    【讨论】:

      猜你喜欢
      • 2013-09-24
      • 2019-08-04
      • 1970-01-01
      • 2017-07-30
      • 2017-11-29
      • 1970-01-01
      • 2017-07-01
      • 2021-08-27
      • 2021-07-18
      相关资源
      最近更新 更多