Android face detection without user interaction

I want to determine the number of faces in the front frame of the camera. I can identify the face as soon as I get the image using this: http://www.developer.com/ws/android/programming/face-detection-with-android-apis.html . But I do not know how to capture an image using the front camera every 30 seconds without user interaction. Can someone please help me?

+8
android face-detection camera
source share
3 answers

The following code will record a photo from the camera every 5 seconds.

if (TIMER_STARTED) { multishotTimer.cancel(); multishotTimer.purge(); TIMER_STARTED = false; } else { multishotTimer = new Timer(); multishotTimer.schedule(new TimerTask() { @Override public void run() { TIMER_STARTED = true; Camera camera = surfaceView.getCamera(); camera.takePicture(null, null, new HandlePictureStorage()); } }, 1000, 5000L); } 

Here TIMER_STARTED has a boolean value indicating whether the timer is working.

Below is the code for HandlePictureStorage

 private class HandlePictureStorage implements PictureCallback { @Override public void onPictureTaken(byte[] picture, final Camera camera) { //do something when picture is captured... } } 
+4
source share

You can manually create a SurfaceView and a preview camera as follows:

 //First get a reference to the SurfaceView displaying the camera preview cameraSurface = (SurfaceView) findViewById(R.id.cameraSurface); cameraSurfaceHolder = cameraSurface.getHolder(); cameraSurfaceHolder.addCallback(cameraSurfaceHolderCallbacks); . . . private SurfaceHolder.Callback cameraSurfaceHolderCallbacks = new SurfaceHolder.Callback() { @Override public void surfaceDestroyed(SurfaceHolder holder) { if(mCamera == null)return; mCamera.stopPreview(); mCamera.release(); mCamera = null; } @Override public void surfaceCreated(SurfaceHolder holder) { try { mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception exception) { if(mCamera == null)return; mCamera.release(); mCamera = null; } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Parameters cameraParameters = mCamera.getParameters(); cameraParameters.setPreviewSize(320, 240); cameraParameters.setPictureSize(320, 240); int avrgExposure = (cameraParameters.getMinExposureCompensation() + cameraParameters.getMaxExposureCompensation())/2; cameraParameters.setExposureCompensation(avrgExposure); mCamera.setParameters(cameraParameters); mCamera.startPreview(); mCamera.takePicture(null, null, mPictureCallback); } }; 

Remember to add the correct camera resolution to the manifest:

 <uses-permission android:name="android.permission.CAMERA"/> 

And finally, if you are using Android 4.0 or higher, you can use the method:

 mCamera.startFaceDetection(); . . . private FaceDetectionListener faceDetectionListener = new FaceDetectionListener() { @Override public void onFaceDetection(Face[] faces, Camera camera) { //Faces have been detected... } }; . . . mCamera.setFaceDetectionListener(faceDetectionListener); 

You can go to this post , which explains everything related to this particular functionality, and even provides functional Android source code that you can download it yourself.

Hello!

+1
source share

You must schedule the RTC_WAKEUP Alarm with the AlarmManager every 30 seconds, set the PendingIntent to Alarm in order to start the Service and inside the Service you need to access Camera to capture the image.

You should probably check out this post: Open / Launch Camera from Background Service .

-one
source share

All Articles