Open dhartwich1991 opened 9 years ago
Same here. Small sized codes cannot be recognized because they are all completely blurred while camera is close or really tiny when it's away and image is sharp.
Same. Faces and some QR codes work fine but barcodes need autofocus to work as they're a lot more intricate.
Sorry about that. We are working on adding an auto focus option to CameraSource and will let you know when a fix is available.
meanwhile, you can use this fix https://gist.github.com/Gericop/7de0b9fdd7a444e53b5a
it works for me until the library is updated.
Unless I'm missing something, this would also be the way you would go about turning torch mode on.
Yes, that's the way to do it. Actually, this method I provided only does the focus thing in order to make the Vision API actually work on barcodes, but you can change it so that it returns the Camera instance (or null on failure), then use that to modify the camera's parameters (focus, flash, etc.).
Edit: I extracted the camera getting parts so one can set any of the parameters of the used camera instance this way until Google releases the fix. https://gist.github.com/Gericop/364dd12b105fdc28a0b6
This solution does not work for me. It doesn't enable auto focus. I made sure that it is called when the camera is displaying. Besides, sometimes I am able to read 1D codes, but the raw value doesn't match the barcode value, and it returns different values every time I try to read the same barcode.
Can you post the code that you wrote to try to enable auto focus?
Note that some devices don't support camera auto focus (hardware limitation). See the comment that I just added here: https://gist.github.com/Gericop/7de0b9fdd7a444e53b5a
What device are you testing on? It is possible your device doesn't support continuous auto focus. Where did you put your cameraFocus(...) call? I put it in CameraSourcePreview's startIfReady() like this:
private void startIfReady() throws IOException {
if (mStartRequested && mSurfaceAvailable) {
mCameraSource.start(mSurfaceView.getHolder());
// ###### HERE IS THE FOCUS CALL ######
MultiTrackerActivity.cameraFocus(mCameraSource, Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
// ####################################
if (mOverlay != null) {
Size size = mCameraSource.getPreviewSize();
int min = Math.min(size.getWidth(), size.getHeight());
int max = Math.max(size.getWidth(), size.getHeight());
if (isPortraitMode()) {
// Swap width and height sizes when in portrait, since it will be rotated by
// 90 degrees
mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
} else {
mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
}
mOverlay.clear();
}
mStartRequested = false;
}
}
You might also want to try to invoke the method with a direct action, like in a button's onClickListener.
That's exactly the code I am using. Probably it is because my phone doesn't support auto focus. 2D barcodes are read correctly, but 1D, when they are read, provide different values for different scans.
We have recently open sourced the CameraSource class:
This version has an auto-focus option.
How to call auto-focus option of CameraSource , i'm trying to call it but getting fail...now in my case ..onPictureTaken resulting in very poor quality images.. can anyone help me..??
Can you post your code that creates the CameraSource and the failure messages that you are getting?
Update: The CameraSource implementation provided by Google Play Services 8.4 includes an auto focus option.
@pm0733464 Do you have any plans to extend the official CameraSource
implementation by the flash mode option that is already available in the open-source CameraSource
version?
We could include the flash mode if there is sufficient demand.
I think the whole open source CameraSource
could (should?) replace the official one as it offers more options to the devs.
Totally. Are there any downsides if the official CameraSource
would be extended by the flash mode options?
@pm0733464 : Any progress on extending the official CameraSource
by the flash mode options?
@pm0733464: Hi am using vision api to scan barcode, as autofocus is not working in samsung tab 3.. I donno how to figure it out whats the problem is. but when I installed the apps present in store, those are well scanning and autofocusing in my samsung tablet, I donno why google vision api is failing to do so.. please can you help me out to fix this issue.
hi, is there any solution? its a major problem for us. Only got focus by clicking to screen. Its not a good way...
@theoreticalb @claywilkinson @pm0733464 @pchx @omares @Gericop @incon @bhargavms @mbg1 @AdamSHurwitz @paolorotolo @ragdroid @Morion-Self @gonzapico
Just checked out the code for the multi-tracker application and compiled it to my device. When I tried to scan barcodes it failed, because there is no auto focus which makes it really hard to scan barcodes without any problems. The CameraSource class does not provide any options to set an auto focus option.