QR code reader on Ubuntu
It appears that your QR code reader is just a camera, and additional software is required to read the QR codes. You can use zbarcam
from zbar-tools
to read QR codes.
zbarcam
will attempt to decode barcodes and QR codes from a video stream, and will output the contents of the scanned codes into stdout.
QtQR is simple QR code scanner using your webcam. It can be installed from the Software Center or from command line:
sudo apt-get install qtqr
The device is simply a camera, the image processing and QR reading is made in the computer's "dirver". If do you want to use it in Linux as it were a "good" reader that has the reading part on the device (It acts as a keyboard that types all what you scan), you can follow these steps:
- Install the required packages:
sudo apt-get install zbar-tools xdotool wmctrl
- Type on a terminal
gksu gedit /etc/udev/rules.d/00-usb-qreader.rules
-
A text editor will open up, copy and paste these lines:
ACTION=="add", SUBSYSTEM=="video4linux", ATTRS{idVendor}=="1871", ATTRS{idProduct}=="0101", ENV{XAUTHORITY}="/home/<your_username>/.Xauthority", ENV{DISPLAY}=":0", OWNER="<your_username>", RUN+="/usr/local/bin/usb-qreader", SYMLINK+="qreader" ACTION=="remove", SUBSYSTEM=="video4linux", ATTRS{idVendor}=="1871", ATTRS{idProduct}=="0101", ENV{XAUTHORITY}="/home/<your_username>/.Xauthority", ENV{DISPLAY}=":0", RUN+="/usr/local/bin/usb-qreader"
- Press Ctrl+H to find and replace all
<your_username>
occurrences by your username. - Save the file and close the text editor.
- Type on a terminal
gksu gedit /usr/local/bin/usb-qreader
-
On this file put these lines (you can customize it if you know what are doing):
#!/bin/bash ZBAR_SETTINGS="--raw --nodisplay" # Put here the options ALWAYS_ON_TOP="true" # Keep the zbar window always on top END_CHARACTER="Return" # Character sent after code scan ("Return", "Tab", "space", "") TYPEIN_WINDOW='' # Title of the window onto type. If it's blank, it will type on the current window function scan() { zbarcam $ZBAR_SETTINGS /dev/qreader | while read line; do CODE=$(head -c -1 <<< "$line") if [[ $TYPEIN_WINDOW != "" ]]; then WINDOW="--window $(xdotool search --name $TYPEIN_WINDOW | tail -n 1)" fi xdotool type $WINDOW "$CODE" xdotool key $WINDOW "$END_CHARACTER" done } if [[ "${ACTION}" == "add" ]]; then scan & if [[ "$ALWAYS_ON_TOP" == "true" && ! "$OPTIONS" =~ "--nodisplay" ]]; then while :; do wmctrl -l | grep -q "zbar barcode reader" && break; done wmctrl -r "zbar barcode reader" -b add,above fi elif [[ "${ACTION}" == "remove" ]]; then ps aux \ | grep -e 'zbarcam.*/dev/qreader' \ | grep -v grep \ | awk '{print $2}' \ | xargs -i kill {} fi
- Type on a terminal
sudo chmod a+x /usr/local/bin/usb-qreader
- Reload the
udev
rules with this command:sudo udevadm control --reload-rules
- Plug your awesome QR reader and enjoy!
- Type on a terminal
However, if do you want a simple solution (that will not give the potential of this, but is simple) you can try the @Slaci solution below.
In 2020, you should use CoBang to scan QR code. This app was written recently by me, to catch new technologies in Linux desktop.
How to install in Ubuntu 20.04:
sudo add-apt-repository ppa:ng-hong-quan/ppa
sudo apt update
sudo apt install cobang