Test the functionality of the QR code decoding software package

QR code recognition software

 

01 Q R decoding


I. Introduction

  QR codes have many applications in many ways, and there are many software packages in Python that can be used to decode QR codes in images. Test the accuracy of two-dimensional code recognition for two-dimensional code images of different sizes and resolutions in different scenarios. The test software includes pyzbar and two software packages of QR CodeDetector in CV2.
GM1683333893_1280_800.MPG|_-6

▲ Figure 1.1.1 The picture of the QR code to be tested

▲ 图1.1.1 待测试的二维码图片

2. Test results

  This is the result of detection using pyzbar. In the program, the decode function of pyzbar is called to obtain the decoding result. This is the returned decoded result. It includes the content of the two-dimensional code, the position of the two-dimensional code, the quality of the two-dimensional code, the orientation of the two-dimensional code and other information. It can be seen that the decoding adaptability is still very strong. Some QR codes with poor image quality cannot be recognized. .
GM1683336018_1280_800.MPG|_-11

from headm import *
from PIL import Image
from pyzbar import pyzbar
import qrcode

imgid = [676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687]
tspsetpen(color=0xff, width=3)

tsprv()

for id in imgid:
    outfile = tspgetdopfile(id)

    ret = pyzbar.decode(Image.open(outfile))
    outfile = tspgetdopfile(id)
    box = tspgetbox(id)

    if len(ret) > 0:
        tspbox(0, *box)
[Decoded(data=b'https://qrco.de/bbYfSx', type='QRCODE', rect=Rect(left=58, top=55, width=90, height=90), polygon=[Point(x=58, y=55), Point(x=58, y=144), Point(x=148, y=145), Point(x=148, y=55)], quality=1, orientation='UP')]

▲ Figure 1.2.1 Recognition results

▲ 图1.2.1 识别的结果

  Change the code below to draw the position of the QR code in the picture. It can be seen that the position of the recognized two-dimensional code is marked with a rectangle. If the two-dimensional code is inclined, the marked box is the circumscribed rectangle of the two-dimensional code. If the QR code is inclined, mark the frame of the QR code as a rectangle. If no QR code is recognized, no information will be returned.
GM1683336958_1280_800.MPG|_-5

from headm import *
from PIL import Image
from pyzbar import pyzbar
import qrcode

imgid = [676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687]
tspsetpen(color=0xff, width=3)

tsprv()

for id in imgid:
    outfile = tspgetdopfile(id)

    img = Image.open(outfile)

    size = img.size
    printf(size)

    ret = pyzbar.decode(img)
    outfile = tspgetdopfile(id)
    box = tspgetbox(id)
    boxwidth = box[2] - box[0]
    boxheight = box[3] - box[1]

    if len(ret) > 0:
        left = ret[0][2][0]
        top = ret[0][2][1]
        width = ret[0][2][2]
        height = ret[0][2][3]

        printff(left, top, width, height)

        bleft = left * boxwidth // size[0] + box[0]
        btop = top * boxheight // size[1] + box[1]

        bright = (left + width) * boxwidth // size[0] + box[0]
        bbottom = (top + height) * boxheight // size[1] + box[1]

        tspbox(0, bleft, btop, bright, bbottom)

  The following tests the performance of the QRCodeDetector function in CV2. Here are the results of the test. Obviously, the adaptability of this function is much worse than that of pyzbar. Only four QR codes were recognized. For inclined QR codes, the positions in the recognition results also seem to be biased. The QR code in this picture is very clear, but it was not recognized. Therefore, the QR code recognition effect in CV2 is not very ideal.
GM1683337983_1280_800.MPG|_-4

from headm import *
from PIL import Image
from pyzbar import pyzbar
import qrcode
import cv2

imgid = [676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687]
tspsetpen(color=0xff, width=3)

tsprv()
d = cv2.QRCodeDetector()

for id in imgid:
    outfile = tspgetdopfile(id)

    img = Image.open(outfile)
    size = img.size

    val,a,b = d.detectAndDecode(cv2.imread(outfile))

    box = tspgetbox(id)
    boxwidth = box[2] - box[0]
    boxheight = box[3] - box[1]

    if len(val) > 0:

        tspbox(0, *box)
        printf(a)

        left = a[0][0][0]
        top = a[1][0][1]
        right = a[2][0][0]
        bottom = a[2][0][1]
        width = right-left
        height = bottom-top

        printff(left, top, width, height)

        bleft = int(left * boxwidth // size[0] + box[0])
        btop = int(top * boxheight // size[1] + box[1])

        bright = int((left + width) * boxwidth // size[0] + box[0])
        bbottom = int((top + height) * boxheight // size[1] + box[1])

        tspbox(0, bleft, btop, bright, bbottom)

  Let's test some samples again. Among the recognition results of CV2, only four are correctly recognized. Among the results identified by pyzbar, eight were correctly identified. This again verifies the adaptability of pyzbar recognition.

GM1683338722_1280_800.MPG|_-2

  Here are the recognition results from different angles. Pyzbar can correctly identify pictures from all angles. Among the recognition results of CV2, one is not recognized.

▲ Figure 1.2.2 Recognition results under different angles Top: Pyzbar recognition results, Bottom: CV2 recognition results

▲ 图1.2.2 不同角度下的识别结果
上:Pyzbar识别结果,下:CV2识别结果

  Let's test the recognition results under different horizontal compressions. Using the detection results of CV2, only the first two QR codes can be recognized. Using Pyzbar, it can recognize the QR codes in images with 50% horizontal compression.
GM1683340122_1280_800.MPG|_-2

▲ Figure 1.2.3 Identification results of left and right compression ratios with different ratios Top: CV2 recognition results, Bottom: Pyzbar recognition results

▲ 图1.2.3 不同比左右压缩比识别结果
上:CV2识别结果,下:Pyzbar识别结果

  Test the impact of different ratios of compression on the original image on recognition. CV2 can only recognize images at full size. Pyzbar can recognize results compressed to 50%. However, there is a strange phenomenon, in which the QR code in a relatively large picture is not recognized.
GM1683340632_1280_800.MPG|_-2

▲ Figure 1.2.4 Different compression ratio recognition results Top: CV2 recognition results, Bottom: Pyzbar recognition results

▲ 图1.2.4 不同压缩比识别结果
上:CV2识别结果,下:Pyzbar识别结果

 

Summary  ※


  This article tests two QR code recognition software, including two-dimensional in different scenarios, different compression and rotation pair recognition results. Experimental results show that Pyzbar has strong recognition performance.
GM1683340740_1280_800.MPG|_-3


● Links to related diagrams:

Guess you like

Origin blog.csdn.net/zhuoqingjoking97298/article/details/130519005