0

I have used zbar scanner for android and it captures the barcodes quite easily. But the problem is that on phones which have autofocus, it captures the barcodes too quickly to detect it correctly. If only it could wait for a few milliseconds more, it could then be able to capture more clearer image and thereby not show "not found" page.

How can I solve this problem? Is there a provision to delay the focus on the barcode? Maybe a delay in capturing the image?

tshepang
  • 12,111
  • 21
  • 91
  • 136
kookaburra
  • 21
  • 3

2 Answers2

0

Are you talking about the example code, CameraTestActivity.java?

Implement a counter that counts for similar scanning results. If the scanning result remains the same (e.g. for 10 times in a row), we can assume the result is quite reliable.

Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98
0

I really like @Juuso_Ohtonen's reply, and actually just used it in my own reader, however if you want an AutoFocus delay you can create a Camera.AutoFocusCallback object and implement its onAutoFocus method with a .postDelayed. This object is then used on your Camera camera.autoFocus() method.

// Mimic continuous auto-focusing
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback() {
    public void onAutoFocus(boolean success, Camera camera) {
        autoFocusHandler.postDelayed(doAutoFocus, 1000);
    }
};

This section is used in the class that extends SurfaceView, which then implements surfaceChanged();

public CameraPreview(Context context, Camera camera,
                      PreviewCallback previewCb,
                      AutoFocusCallback autoFocusCb) {
    super(context);
    mCamera = camera;
    previewCallback = previewCb;
    autoFocusCallback = autoFocusCb;

    // Install a SurfaceHolder.Callback so we get notified when the
    // underlying surface is created and destroyed.
    mHolder = getHolder();
    mHolder.addCallback(this);

    // deprecated setting, but required on Android versions prior to 3.0
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    /*
     * If your preview can change or rotate, take care of those events here.
     * Make sure to stop the preview before resizing or reformatting it.
     */
    if (mHolder.getSurface() == null) {
        // preview surface does not exist
        return;
    }

    // stop preview before making changes
    try {
        mCamera.stopPreview();
    } catch (Exception e) {
        // ignore: tried to stop a non-existent preview
    }

    try {
        mCamera.setPreviewDisplay(mHolder);
        mCamera.setPreviewCallback(previewCallback);
        mCamera.startPreview();
        mCamera.autoFocus(autoFocusCallback);
    } catch (Exception e) {
        Log.d("DBG", "Error starting camera preview: " + e.getMessage());
    }
}
John Shelley
  • 2,655
  • 3
  • 27
  • 36