Try using a QR code on a Raspberry Pi

Try using a QR code on a Raspberry Pi

A QR code that has become commonplace in everyday life, centered on electronic payments. I want to make it myself and make it recognized I will post the result of trying with Raspberry Pi.

What i did

・ Arbitrary QR code generation ・ Code reading + content display using a USB camera It looks like this when it is executed. (https://www.youtube.com/watch?v=xLL4vZN3S7g) Display the contents of the code (which can be generated by yourself). In order to make it easier to understand how you are recognizing, the numerical value increases for each recognition. 2020-05-12-171506_1920x1080_scrot.png

environment ・ RasPi4 (It should work with RasPi3) ・ USB camera (Logitech) → Raspi cam is also available.

RasPi setup

-Not required if RasPi or OpenCV setup is complete. Try ArUco on Raspberry Pi

-Installation of required packages Do the following in the terminal

pip install --upgrade pip
pip install pillow
pip install pyzbar
pip install qrcode

Generate a QR code

QRcreate.py


import qrcode
from PIL import Image

#Determine the size
qr = qrcode.QRCode(box_size=5)
    #List of types and sizes.
    #1	57x57
    #2	114x114
    #5	285x285
    #10	570x570

#Specify the content to be embedded
qr.add_data('Try the QR code close to you')
qr.make()

img_qr = qr.make_image()
img_qr.save('/home/pi/qr_lena_1.png') #The location and name you want to save.

Recognize QR code

QRdetect.py


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pyzbar.pyzbar import decode
from PIL import Image
import cv2
import time #For test, not required

#Start video capture
cap = cv2.VideoCapture(1) 
i=0 #For test

while True:
    #Get images from video capture
    ret, frame = cap.read() 

    #Get size
    Height, Width = frame.shape[:2] 
    img = cv2.resize(frame,(int(Width),int(Height)))
    PIL_Image=Image.fromarray(img)

    #Image display
    cv2.imshow('Qr Test', img)
    data = decode(PIL_Image)

    #Display if you can read something
    if(data != []):
        print('Read' ,i)
        i=i+1
        #print(data[0][0]) 
        print(data[0][0].decode('utf-8', 'ignore'))

    #Reception of keyboard input
    cv2.waitKey(1) 

#Free memory for video capture
cap.release() 
#Close all windows
cv2.destroyAllWindows()


Execution result

It's a little hard to see, but you can see that the number increases with each recognition. If you don't print, it will run faster. (https://www.youtube.com/watch?v=xLL4vZN3S7g)

reference

This is a very helpful page. Detailed explanation (https://note.com/yurufuwa_dev/n/n3442772e67ad) Various generation methods (https://qiita.com/MuAuan/items/7265da5281aa69623a03)

that's all.

Recommended Posts

Try using a QR code on a Raspberry Pi
Try using ArUco on Raspberry Pi
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Using a webcam with Raspberry Pi
Detect "temperature (using A / D converter)" using python on Raspberry Pi 3!
Detect "brightness" using python on Raspberry Pi 3!
Run servomotor on Raspberry Pi 3 using python
Detect temperature using python on Raspberry Pi 3!
Control the motor with a motor driver using python on Raspberry Pi 3!
Detect slide switches using python on Raspberry Pi 3!
Detect analog signals with A / D converter using python on Raspberry Pi 3!
Build a Django environment on Raspberry Pi (MySQL)
pigpio on Raspberry pi
Try using Sourcetrail, a source code visualization tool
Detect magnet switches using python on Raspberry Pi 3!
Sound the buzzer using python on Raspberry Pi 3!
Create a visitor notification system using Raspberry Pi
Cython on Raspberry Pi
Build a Python development environment on Raspberry Pi
[Raspberry Pi] Publish a web application on https using Apache + WSGI + Python Flask
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
Create a color sensor using a Raspberry Pi and a camera
Create a QR code for the URL on Linux
Try debugging Python on Raspberry Pi with Visual Studio.
Output to "7-segment LED" using python on Raspberry Pi 3!
Indoor monitoring using Raspberry Pi
Try using OpenCV on Windows
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Install PyCall on Raspberry PI and try using GPIO's library for Python from Ruby
Cross-compiling for Raspberry Pi Zero on Debian-Try using shared libraries
Access google spreadsheet using python on raspberry pi (for myself)
I tried to automate [a certain task] using Raspberry Pi
Testing uart communication on Raspberry Pi
Try using Pillow on iPython (Part 1)
USB over ethernet using Raspberry pi
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
Try using Pillow on iPython (Part 2)
Try L Chika with raspberry pi
OpenCV installation procedure on Raspberry Pi
Try using Pillow on iPython (Part 3)
Using a serial console on Ubuntu 20.04
Try moving 3 servos with Raspberry Pi
Generate QR code using Python's "qrcode"
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
L Chika on Raspberry Pi C #
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Make a simple CO2 incubator using Raspberry PI and CO2 sensor (MH-Z14A)
Turn Raspberry Pi into a router (Wake on LAN [4] over NAT)
Weighing instrument using raspberry pi and hx711 (GUI display on Tkinter)
[Note] Using 16x2-digit character LCD (1602A) from Python with Raspberry Pi
Execute Python code on C ++ (using Boost.Python)
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Try using Bash on Windows 10 2 (TensorFlow installation)
[Raspberry Pi] Add a thermometer and a hygrometer