journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.74k stars 1.27k forks source link

Is auto flash (like in Camera app) possible? #141

Open Bajranghudda1 opened 8 years ago

Bajranghudda1 commented 8 years ago

@rkistner

For auto flash light you doing isAutoFlashLightEnabled(boolean), and for this you using light sensor and if darkness density is 45.0f (will turn of flash) and 450.0f will turn off flash, i think it is worst if instantly light sensor has been covered by user's shadow.

I think this torch auto On/Off can be improved by using logic like android's Camera app does, i tested Camera app not using Light sensor for detecting darkness.

Bajranghudda1 commented 8 years ago

Hello @rkistner ,

I need to manage auto flash like in camera app, but in our library we are managing using sensor (light sensor), but it seems worst because sometimes occasionaly it get off when moving our hand or sensor coverd by our hand or may be some device does not support light sensor too. I am new in android, i dont know using light sensor is best apporch rather than like in camera app.

Please look into this,

Bajranghudda1 commented 8 years ago

Hello @rkistner , My idea for this is, in possibleResultPoints() called all the time when scanner is running and we have to check only is camera focusing? then capture the image and find the darkness in its pixel, so according to that we can turn on/off flash.

rkistner commented 8 years ago

It should be possible to do something like that. Do you know of any existing open source applications doing this, which we can use as a starting point, instead of implement this from scratch?

Bajranghudda1 commented 8 years ago

I searched a lot on Google but i couldn't find any one except camera app, and i noticed that it is not working in camera app too when video is recording (we can only On/Off not auto).

Bajranghudda1 commented 8 years ago

Hello @rkistner

I tired a lot on Camera's FLASH_MODE_AUTO it will not work for our lib, we have to completely customize it. Because in camera's default auto mode camera will on torch every frame detection, i think it is worst. Then i tired it in other way see this here but i think it will make slow our app because of there are a lot of image/bitmap processing.

I am new in android please suggest me a best way or should i neglect this feature in our app?

rkistner commented 8 years ago

There are a few ways to optimize it to reduce the performance impact:

  1. Only check once every few frames. You don't want to turn the flash on and off too quickly anyway (probably once every second or two max).
  2. Check the raw byte data - don't convert it to a Bitmap. Youcan also use the LuminanceSource for this, e.g. in DecoderThread.
  3. There's no need to check all the pixels to calculate the average - you can get a good estimate by just checking say every 5th row and column.

That said, this will still complicated to implement and making sure it works well in all the edge cases. I suggest just using a toggle button for now.

Bajranghudda1 commented 8 years ago

Thanks @rkistner

I will try any other way too.

AndreyNazarchuk commented 8 years ago

@rkistner any plans to add this?

rkistner commented 8 years ago

@AndreyNazarchuk No plans currently, but pull requests are welcome.