1. Overview

A QR (Quick Response) code is a grid of dark and light dots that can hold up to 7,089 characters. These codes are widely used for URL sharing, personal identification, passes, ticketing, geolocation, contact information, WiFi network configuration, and other purposes that require access to data with a simple scan.

In this tutorial, we’ll see how to read a QR code from a webcam or a file using some Linux command-line and graphical open-source tools. As an example, we’ll use this downloadable QR code, which contains a link to the Baeldung website:

Baeldung website QR codeWe’ll use Linux Mint 21 to install and test the following tools. However, their availability on other distributions may vary.

2. Command-Line Tools

Here we’ll see how to use the Linux terminal to recognize and decode QR codes from images or video streams.

2.1. zbarimg & zbarcam

First, we need to install ZBar Bar Code Reader, a software suite that includes the two utilities we’re interested in:

$ sudo apt install zbar-tools

zbarimg takes an image file as input and outputs the decoded data to standard output or to a file:

$ zbarimg Baeldung-website-QR-code.png 
scanned 1 barcode symbols from 1 images in 0,05 seconds

If we’re interested in clean output, i.e., without any extra information beyond the decoded string, we can use the -q and –raw options:

$ zbarimg -q --raw Baeldung-website-QR-code.png 

zbarcam captures frames from a video device and scans them for QR codes, displaying the results on the screen or sending them to another program. While framing a QR code, let’s observe the terminal:

zbarcam example of usageThe Examples section of the man page shows how to pipe the resulting data through a script. It’s also possible to disable the preview window with the –nodisplay option, but this has an unfixed bug at the moment.

2.2. QR Scanner CLI

QR Scanner CLI is another solution for decoding QR codes stored in image files.

For the installation, we need to use npm, the Node Package Manager, which is the default tool to manage Node.js packages. The -g flag specifies that the software should be installed globally, making its command-line tool available to all users:

$ sudo npm i -g qr-scanner-cli

After that, it’s easy to use:

$ qrscanner ./Baeldung-website-QR-code.png 
║                               ║
║   https://www.baeldung.com/   ║
║                               ║

To get clean output, we can use the –clear option:

$ qrscanner --clear ./Baeldung-website-QR-code.png 

We can also take a look at the –clipboard option to copy the decoded string to the clipboard. This is interesting because, in Linux, we can automate the use of the clipboard using various command-line tools and scripting languages.

3. GUI Tools

Now let’s look at some more user-friendly utilities.

3.1. CoBang

CoBang allows us to decode QR codes from both local and remote pictures and webcams. Its documentation includes installation instructions for some popular distributions, as well as Flatpak support in all other cases:

$ sudo add-apt-repository ppa:ng-hong-quan/ppa
$ sudo apt update
$ sudo apt install cobang

Using the webcam is pretty intuitive:

CoBang QR scanner for LinuxUsing remote images may be less obvious. We actually have to drag the image from the browser, or from the local file system with remote mounting, into the CoBang window:

CoBang example of remote urlThe Screenshots section of the documentation shows other interesting use cases, such as CoBang’s integration with Network Manager for the use of WiFi configuration QR codes.

3.2. QR Code Reader (Firefox and Chrome)

QR Code Reader is an extension for Firefox and Chrome. Internally it uses the ZBar library seen earlier and allows scanning QR codes from webcams and local images:

QR Code Reader extensionAs noted in the FAQ, this extension only works locally and doesn’t perform any server-side interaction.

3.3. QtQR

QtQR is first and foremost a QR code generator with a clear and clean interface. Let’s install it:

$ sudo apt install qtqr

The options we’re interested in are Decode from File and Decode from Webcam:

QtQR QR Code GeneratorUnlike any other tool we’ve seen so far, this one allows us not only to decode QR codes, but also to edit them.

4. Conclusion

In this article, we’ve seen some command-line and graphical tools for decoding QR codes on Linux:

  • zbarimg & zbarcam
  • QR Scanner CLI
  • CoBang
  • QR Code Reader extension for Firefox and Chrome
  • QtQR

The choice of tool depends on our preferences. Command-line tools are especially good for automated workflows.

Comments are closed on this article!