Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Barcode / QR Code Camera Scanner Demo (objc_util)
-
Someone asked me on Twitter if Pythonista had support for scanning barcodes, using the camera. While there's nothing like that built-in, I looked around a bit, and it turns out that there are APIs for this in Apple's AVFoundation framework, so I thought it might be interesting to build a wrapper around that.
This demo shows a live camera preview, and it plays a sound when a barcode or QR code is found in the viewfinder. The scanned code (a number for EAN codes, URLs or text for QR codes...) is shown in an overlay label. When the view is closed, a list of all (unique) codes that were scanned is printed to the console.
Here's the code: Barcode Scanner.py (Gist)
And a screenshot:
-
Is it also possible to read a barcode from an image file instead of the camera? (For when the QR code is so small that getting the camera to focus is almost impossible.) There are lots of apps that can scan barcodes normally, but I don't know of any that can scan existing image files.
-
@dgelessus That should be possible. You'd probably use CoreImage instead of AVFoundation though – the approach would be very similar to the "Camera Scanner" demo in the bundled ObjC examples, which is using
CIDetector
withCIDetectorTypeRectangle
. There's alsoCIDetectorTypeQRCode
, which sounds like exactly what you're looking for. -
How can I push the scanner as a subview to a navigation view, get the first result it scanned, close the scanner an process the number, the scanner returned?
I already managed to load the scanner as a sub view of a navigation view but now I'm stuck.
-
Don't we have a qrcode module?
-
@jbap That's for generating QR codes (from a URL etc.), not for reading them.
-
Just wondering if the qrcode module could be expanded to produce and read.
-
I tried this, and I'm just curious how I could use the photos module to scan. When my iPad is in any other orientation than the preset in this program, the camera does not shift. My iPad will turn, but the camera won't.
-
Hi! I have been working with this script and I have been trying to get the picture from which the QR code was finally scanned? Do you know if this is possible with AVFoundation?
-
This works great except when my ipad is turned sideways the camera acts weird and is like the camera is in mirror mode or something.
-
This post is deleted!