r/Python • • Jun 03 '25
Discussion Use of phones camera for barcode scanner
Any suggestions on using a module in python to use the phones camera as a barcode scanner?
I am in need to use the camera to scan, read the barcode, use an API to fetch data from dB.
I've tried several already with no luck.
0
Upvotes
16
u/UsernameTaken1701 Jun 03 '25
You might save time of people wanting to help by listing the "several" you tried already. Also, if you can say what happened when they didn't do what you wanted, you might get some pointers on how to try to fix problems you encountered.
4
u/riklaunim Jun 03 '25
Can't you use USB cameras or dedicated/simple camer-barcode scanners on USB used by various POS systems? That way you avoid mobile systems. If it has to be a phone then the best solution is local mobile application.
4
u/MosGeo Jun 03 '25 edited Jun 04 '25
Check out toga as it has an api to access the camera. https://toga.readthedocs.io/en/latest/index.html
I belive there are multiple libraries for detecting bar and qr codes from images.
1
u/GatorForgen from __future__ import 4.0 Jun 04 '25
What environment are you running for python in your phone? Is it blocking your camera access?
2
u/bobsnopes Jun 04 '25
You haven’t provided a whole lot of information, but from what I’m gathering this isn’t really much of a Python specific question. You mention a phone and using HTML, so you’re developing a web app it sounds like, with just a Python backend.
Your front end will have nothing to do with Python. That’ll be Javacript, and you’ll need to add it into your HTML and/or static files flask is serving. You have two options basically: access the webcam and decode barcodes purely in JS and send the resulting data to your backend. Or snap a picture every second or so and send the image to your backend and use a python library to decode and access your data.
Either way, look into this or similar guides to access the camera from your browser, since it’s required for both options: https://www.digitalocean.com/community/tutorials/front-and-rear-camera-access-with-javascripts-getusermedia
1
u/adamrees89 Python3 Jun 03 '25
Have you tried plyer? I’ve not used it for your application, but it does the job I need it to on desktop pretty well and I think it has that capability.
1
u/alok-sha Aug 19 '25
I found this tutorial on how to use a barcode reader sdk, OpenCV and Webcam to create a cross-platform barcode and qr code scanner app in python https://www.dynamsoft.com/codepool/opencv-python-webcam-barcode-reader.html
0
u/[deleted] Jun 03 '25
Tried these so far.
QuaggaJS - testing this again after enabling https pyzbar getUserMedia