2017-04-05 39 views
1

我正在探索android视觉api,并遵循Android开发人员文档中提供的github示例。示例应用程序正在检测脸部。android手机视觉api自定义检测器未检测到脸

我想裁剪每个检测到的面。 我有一个rect obj有左,上,右,下坐标。

但我没有源位图裁剪脸。

我所做的事情:使用

1.Tried在此SOF post

这里给出的自定义检测myFaceDetector的SparseArray检测(逐帧)方法得到反复调用,它没有检测处理器集没有被调用。 我用下面的代码

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.尝试将相机图像作为源位图,但是不断拍摄图像。

任何帮助将是非常有用的。感谢提前。

回答

0

我想裁剪每个检测到的面。我有一个左,上,右,下坐标矩形对象。

一旦面孔已经被检测到,你可以用Face.getPosition(),Face.getHeight(),和Face.getWidth()

这里myFaceDetector的获得面部的位置和尺寸SparseArray detect(Frame frame)方法被重复调用,并且未检测到脸部

您是否尝试过设置正确的方向?在Frame.Builder中,添加setRotation(ROT),其中ROT是具有以下任何值的整数: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