2

I want to face tracking with FaceDetector like this.
https://github.com/googlesamples/android-vision/tree/master/visionSamples/FaceTracker

In this sample, set ByteBuffer to Frame.imageData like this.

 outputFrame = new Frame.Builder()
            .setImageData(mPendingFrameData, mPreviewSize.getWidth(),
                                mPreviewSize.getHeight(), ImageFormat.NV21)
            .setId(mPendingFrameId)
            .setTimestampMillis(mPendingTimeMillis)
            .setRotation(mRotation)
            .build();

But, I set bitmap to Frame like this.

//data is image data as byte.
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
outputFrame = new Frame.Builder()
            .setBitmap(bitmap)
            .setId(frameId)
            .setTimestampMillis(time)
            .build();

And use FaceDetector like this.

    FaceDetector fd = new FaceDetector.Builder(this.context)
                        .setTrackingEnabled(true)
                        .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
                        .build();

        fd.setProcessor(new MultiProcessor.Builder<Face>(new GraphicFaceTrackerFactory()).build());
        fd.receiveFrame(frame);

     private class GraphicFaceTrackerFactory implements MultiProcessor.Factory<Face> {
        @Override
        public Tracker<Face> create(Face face) {
            return new GraphicFaceTracker();
        }
     }

private class GraphicFaceTracker extends Tracker<Face> {

    GraphicFaceTracker() {}

    @Override
    public void onNewItem(int faceId, Face face) {
        Log.d(Constants.LOG_TAG, "onNewItem. Face Id => "+faceId);//here
    }

    @Override
    public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face) {
    }

    @Override
    public void onMissing(FaceDetector.Detections<Face> detectionResults) {

    }

    @Override
    public void onDone() {

    }
}

I expected that same faceId will be entered in onNewItem() as long as same face remain in the frame, but entered id was different every time.

Do you have an any idea?

【Additional info】
・In my application, it takes still pictures continuously at 7.5fps.

gaku
  • 101
  • 1
  • 5

0 Answers0