1
public class PhotoActivity extends Activity implements SurfaceHolder.Callback {

private ImageView imageView;
private SurfaceView mSurfaceView;
private Bitmap bmp;
private SurfaceHolder mSurfaceHolder;
private Camera mCamera;
private Parameters parameters;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
    imageView = (ImageView) findViewById(R.id.image_view);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {

    parameters = mCamera.getParameters();
    mCamera.setParameters(parameters);
    mCamera.startPreview();

    Camera.PictureCallback mCall = new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {

            bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
            imageView.setImageBitmap(bmp);
            mSurfaceView.setVisibility(View.INVISIBLE);

            // Call web service
            SendPhotoAsync photoToWeb = new SendPhotoAsync(data);
            photoToWeb.execute();
        }
    };
    mCamera.takePicture(null, null, mCall);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {

    mCamera = Camera.open();
    mCamera.setDisplayOrientation(90);
    try {

        mCamera.setPreviewDisplay(holder);

    } catch (IOException exception) {
        mCamera.release();
        mCamera = null;
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

    mCamera.stopPreview();
    mCamera.release();
    mCamera = null;
}
@Override
protected void onResume() {
    super.onResume();
}

@Override
protected void onPause() {
    super.onPause();
}

我如何修改此代码以在相机预览上检测人脸,在 android 中使用人脸检测器 api ..请提供任何帮助..我也想检测眼睛..希望有人能帮助我..我经历了这个在按钮上工作点击。在我拍照的情况下,没有按钮点击..有一些高效代码的人会很受欢迎..请帮助我,这非常关键

4

1 回答 1

0

如果您有面部检测器的 android API..从照片活动中调用此活动..在照片活动中将捕获的图像保存到 sd 卡...在面部检测器 api 中读取此文件..这样我们就可以做到..但是三星galaxy+google nexus不执行面部检测..AAkash可以..

于 2013-07-26T09:06:43.083 回答