android 人脸识别

android的人脸识别目前为上(4.2)只能进行人脸的识别,而不能进行人脸的对比。

下面是具体代码

package com.example.facedetectdemo;

import java.io.IOException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Face;
import android.hardware.Camera.FaceDetectionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AndroidCamera extends Activity implements SurfaceHolder.Callback{

	 Camera camera;
	 SurfaceView surfaceView;
	 SurfaceHolder surfaceHolder;
	 boolean previewing = false;
	 LayoutInflater controlInflater = null;
	 
	 Button buttonTakePicture;
	 TextView prompt;
	 
	 final int RESULT_SAVEIMAGE = 0;
	 
	   /** Called when the activity is first created. */
	   @Override
	   public void onCreate(Bundle savedInstanceState) {
	       super.onCreate(savedInstanceState);
	       setContentView(R.layout.activity_main);
	       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	      
	       getWindow().setFormat(PixelFormat.UNKNOWN);
	       surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
	       surfaceHolder = surfaceView.getHolder();
	       surfaceHolder.addCallback(this);
	       surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	      
	       controlInflater = LayoutInflater.from(getBaseContext());
	       View viewControl = controlInflater.inflate(R.layout.control, null);
	       LayoutParams layoutParamsControl
	        = new LayoutParams(LayoutParams.FILL_PARENT,
	        LayoutParams.FILL_PARENT);
	       this.addContentView(viewControl, layoutParamsControl);
	      
	       buttonTakePicture = (Button)findViewById(R.id.takepicture);
	      
	       LinearLayout layoutBackground = (LinearLayout)findViewById(R.id.background);	      
	       prompt = (TextView)findViewById(R.id.prompt);
	   }
	  
	   FaceDetectionListener faceDetectionListener
	   = new FaceDetectionListener(){

	  @Override
	  public void onFaceDetection(Face[] faces, Camera camera) {
	   
	   if (faces.length == 0){
	    prompt.setText(" No Face Detected! ");
	   }else{
	    prompt.setText(String.valueOf(faces.length) + " Face Detected :) ");
	    Log.i("faceScore", faces[0].score+"");
	    Point leftEye = faces[0].leftEye;
	    
//	    leftEye
	    
	   }
	   
	   
	  }};
	  
	  
	 @Override
	 public void surfaceChanged(SurfaceHolder holder, int format, int width,
	   int height) {
//	  // TODO Auto-generated method stub
	  if(previewing){
	   camera.stopFaceDetection();
	   camera.stopPreview();
	   previewing = false;
	  }
	  
	  if (camera != null){
	   try {
	    camera.setPreviewDisplay(surfaceHolder);
	    camera.startPreview();

	    prompt.setText(String.valueOf(
	      "Max Face: " + camera.getParameters().getMaxNumDetectedFaces()));
	    camera.startFaceDetection();
	    previewing = true;
	   } catch (IOException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	   }
	  }
	 }

	 @Override
	 public void surfaceCreated(SurfaceHolder holder) {
	  // TODO Auto-generated method stub
	  camera = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
	  camera.setFaceDetectionListener(faceDetectionListener);
	 }

	 @Override
	 public void surfaceDestroyed(SurfaceHolder holder) {
	  // TODO Auto-generated method stub
	  camera.stopFaceDetection();
	  camera.stopPreview();
	  camera.release();
	  camera = null;
	  previewing = false;
	 }
	 
	 Camera.FaceDetectionListener faceDetionListener = new Camera.FaceDetectionListener() {
		
		@Override
		public void onFaceDetection(Face[] faces, Camera camera) {
			// TODO Auto-generated method stub
			
		}
	};
	
	
	}



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值