I am using mobile vision API to detect face in android app.
I have used SparseArray of Face to store the references to faces, but the detector.detect(frame) method takes too long (15 seconds) to detect face.
Note: I am passing the bitmap of the image taken by camera to detectFaces method.
My code is below
void detectFaces(Context context, Bitmap picture){
com.google.android.gms.vision.face.FaceDetector detector = new com.google.android.gms.vision.face.FaceDetector.Builder(context)
.setTrackingEnabled(false)
.setClassificationType(com.google.android.gms.vision.face.FaceDetector.ALL_CLASSIFICATIONS)
.build();
//Build the frame
Frame frame = new Frame.Builder().setBitmap(picture).build();
//Detect the faces
SparseArray<Face> faces = detector.detect(frame);//**This takes approx 15 second**
if(faces.size() == 0)
Toast.makeText(context, "No Face Detected", Toast.LENGTH_SHORT).show();
else
{
Toast.makeText(context,"Face detected are : " + faces.size() , Toast.LENGTH_LONG).show();
getClassification(faces.valueAt(0));
}
//Release the detector
detector.release();
}