Reputation: 5367
This question is about using Google's Mobile Vision Face API on Android.
I am trying to implement a function that detects faces in a camera view, and overlaying images on those faces.
Now, I have already successfully implemented such feature by using Mobile Vision API's Face Detection. Its mechanism is like this:
Bitmap
The problem is, the above process obviously takes too much time. I can only update the overlaying image position 3-5 times every second, even less frequent on slower devices.
By looking at the profiling, the most heavy method is, surprisingly, step 3 (Face detetction). It takes an average of 100ms to perform once.
Second heavy method is converting the NV21 frame into a Bitmap object, which takes around 90ms.
Summing up everything now I get an update FPS of 3~5.
But other than that, every thing works perfectly - image can be captured in high quality, with auto focus and pinch zooming.
On the other hand, Mobile Vision API provides another API - Face Tracking.
In Google's sample app, the tracking is very fast, it follows almost instantaneously with the faces in the camera preview. As stated in the document, this is because the mechanism is completely different - instead of detecting faces on each frame, once a face is detected, the position simply follows its movement without performing any face detection.
But it fact such mechanism is good enough in my use case!
However, by looking at the sample code, it looks like I have to use its built-in implementation of CameraSource
. This can be find in the code below:
mCameraSource = new CameraSource.Builder(context, detector)
.setRequestedPreviewSize(640, 480)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedFps(30.0f)
.build();
detector
is the main character here, and it is only used here when passing to CameraSource
. It looks like I have to stick to using this CameraSource
.
However, although this camera source has takePicture()
method, I cannot find any way to implement auto focus and zooming.
My ultimate objective is to implement the feature I have mentioned in the beginning, with the below requirements:
1-3 can be done using Face Detection, but not 4;
While 4 can be done using Face Tracker, but not 1-3.
Is there a way to accomplish all 1-4? I welcome any suggestion even if it is to use another library instead of Mobile Vision.
Thanks for reading such long question till the end!
Upvotes: 2
Views: 987
Reputation: 57163
CameraSource.java is available on GitHub under a permissive Apache license. Feel free to add auto-focus and zoom.
Upvotes: 2