ekreutz / react-native-barcode-scanner-google

Barcode scanner for react native, which implements barcode detection from Google's Vision API.
MIT License
113 stars 69 forks source link

Implemented torchMode and precisionMode #7

Closed srolija closed 5 years ago

srolija commented 7 years ago

Thank you for the fantastic library, it really works wonders compared to react-native-camera for Android scanning purposes.

This pull request implements torchMode with syntax similar to react-native-camera and adds additionally precisionMode which determines resolution of camera source (which is piped into both the barcode detector and the camera preview), it is backward compatible (PRECISE mode) but also offers RESPONSIVE mode which lowers resolution in order to increase frame rate and enable much smoother UI (for our use case it was important consideration, and it isn't big scanning performance tradeoff).

I bumped version to 1.3.0 and added to docs and example aforementioned properties.

srolija commented 7 years ago

Latest commit also fixes PropTypes deprecation in previous versions and removal from latest React/React Native version which crashes application.

ekreutz commented 6 years ago

Do you think you could revise this to only include added features? (torchMode)

srolija commented 6 years ago

Sure, would you be also willing to merge in precisionMode since it really looks laggy when there are only 15FPS especially considering that all native camera views normally display with at least 30FPS.

ekreutz commented 6 years ago

Yes, sure. From a usability perspective it doesn't really matter if the frame rate is 15 or 30 fps; the scanner is still plenty fast. However, you're right that it looks better with 30 so end-users might consider it better..! :)

Notice that anything that increases resolution/frame rate will increase the workload on the scanner when it tries to depict barcodes. So let's keep the defaults quite low anyway!

srolija commented 6 years ago

I understand that, that is why I tried to compensate by lowering source resolution in that mode (same aspect ratio, half total image area size), to keep CPU usage roughly the same... based on few crude tests using CPU monitoring app it yields roughly the same usage.

That is why I called them precise mode (larger resolution, better recognition of far distanced codes, original 15fps) and responsive mode (more FPS so looks more responsive, but smaller resolution).

picksomething commented 6 years ago

@srolija Hi, torchMode does not working, Have you tried it?

srolija commented 6 years ago

It should work on my fork: https://github.com/srolija/react-native-barcode-scanner-google I tested it on Nexus 5X, Samsung Galaxy J5 and some crapy Huawei, on all of them it worked as expected.

I didn't have time yet to update fork to be mergeable with the latest version of this branch. I will try to do it today or this weekend. :)

picksomething commented 6 years ago

@srolija Thank you for your reply, i have try it on my oneplus 5, but it does not seem to work. Maybe I ignored something, i will try again later.

niom commented 6 years ago

Any effort on getting this merge ready? I'm also interested on the precision mode.

@srolija could you resolve the conflicting files?

srolija commented 5 years ago

Since RNCamera now includes (https://github.com/ekreutz/react-native-barcode-scanner-google/issues/33) the high-performance barcode scanning based on MLKit which replaced the Google Vision API (now deprecated, used in this library); I would highly recommend anyone to check that integration. I have no plans of updating this PR as that one already has torch prop and works much better.

To get you started faster here is the code that shows modifications needed to integrate that one as drop-in replacement for normal RNCamera (which most people likely use for iOS). https://gist.github.com/srolija/f5ab14ea720eb0e00efa3ca9e490fb3c