welcome to linkAR technical documentation

previous

Process Picture

Add this instructions to process camera images only after some event (like button pressed).

Add the callback

Add the following callback:

  • Camera.PictureCallback

Add the fields

        private static final long DELAY = 2000;
        private Handler myHandler;

Instantiate the Handler

In your activity

@Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myHandler=new Handler();
 
        ...
 
    }

Also add the following line in the SurfaceChanged method:

/** Important to implement this method*/
	@Override
	public void surfaceChanged(SurfaceHolder arg0, int arg1, int w, int h) {
		...
		p.setPreviewSize(camWidth,camHeight);
		p.setPictureSize(camWidth,camHeight);
 
		camera.setParameters(p);
		...		
	}

Finally remove the preview Callback in the Surface Created method:
camera.setPreviewCallback(this);

	@Override
	public void surfaceCreated(SurfaceHolder arg0) {
		/** Gets the camera*/
		camera=Camera.open();
 
 
	}

Implement the callback function

	@Override
	public void onPictureTaken(byte[] arg0, Camera arg1) {
		if(arg0!=null)
			aRmatcher.processFrame(arg0, camWidth, camHeight);
	}

Take the picture

When you want to take a picture, add the following lines:

  camera.takePicture(null, this, this);
  myHandler.postDelayed(new Runnable() {				
    @Override
    public void run() {
      camera.startPreview();
    }
  }, DELAY);

The handler will resume the camera preview (after calling the takePicture method the preview is automatically stopped).

previous