从CameraSource裁剪脸部 [英] Crop face from the CameraSource

查看:104
本文介绍了从CameraSource裁剪脸部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现 Google-vision人脸跟踪器
MyFaceDetector 类:

public class MyFaceDetector extends Detector<Face> {
    private Detector<Face> mDelegate;

    MyFaceDetector(Detector<Face> delegate) {
        mDelegate = delegate;
    }

    public SparseArray<Face> detect(Frame frame) {
        return mDelegate.detect(frame);
    }

    public boolean isOperational() {
        return mDelegate.isOperational();
    }

    public boolean setFocus(int id) {
        return mDelegate.setFocus(id);
    }

}

FaceTrackerActivity 类:

private void createCameraSource() {

    imageView = (ImageView) findViewById(R.id.face);

    FaceDetector faceDetector = new FaceDetector.Builder(this).build();
    myFaceDetector = new MyFaceDetector(faceDetector);
    myFaceDetector.setProcessor(new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
            .build());
    mCameraSource = new CameraSource.Builder(this, myFaceDetector)
            .setRequestedPreviewSize(640, 480)
            .setFacing(CameraSource.CAMERA_FACING_FRONT)
            .setRequestedFps(60.0f)
            .build();

    if (!myFaceDetector.isOperational()) {
        Log.w(TAG, "Face detector dependencies are not yet available.");
    }
}

我需要修剪脸并将其设置为 ImageView 。我无法在此处实现自定义 Frame frame.getBitmap()始终在 detect(Frame frame) null $ c>。我该如何实现?

I need to crop the face and set it on ImageView. I am not able to implement my custom Frame here. frame.getBitmap() always returns null in detect(Frame frame). How do I achieve this?

推荐答案

frame.getBitmap()仅在帧最初是由位图创建的情况下才返回值。 CameraSource提供的图像信息是字节缓冲区而不是位图,因此是可用的图像信息。

frame.getBitmap() will only return a value if the frame was originally created from a bitmap. CameraSource supplies image information as ByteBuffers rather than bitmaps, so that is the image information that is available.

frame.getGrayscaleImageData()将返回图像数据。

frame.getGrayscaleImageData() will return the image data.

frame.getMetadata()将返回元数据,例如图像尺寸和图像格式。

frame.getMetadata() will return metadata such as the image dimensions and the image format.

这篇关于从CameraSource裁剪脸部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆