Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do detect a QR code pattern in an image?

I'm working on a QR detector code and I need to locate the Finding Patterns (FP) on an image. I have created a binary template resembling the squares you find on the corners of QR codes as:

FP = ones(9);
FP(2:8,2:8)=0;
FP(3:7,3:7)=1;
FP(4:6,4:6)=0;
figure;imshow(FP)

And I have tried looking for the points in the image with maximum correlation with this template using xcorr2. My problem is obvious: My template is very small compared to the actual sizes QR codes might have on the images.

Is there a way of looking for a pattern/mask without having to resize it? Is there another approach to this problem?

As an example, here's an image with a QR code

enter image description here

like image 271
alvaro.delaserna Avatar asked Jun 10 '14 08:06

alvaro.delaserna


People also ask

Can you search a QR code from a picture?

Fortunately, Google Lens offers a native feature to scan QR codes from images in the gallery or camera roll on both Android and iOS. It comes preinstalled in different forms on almost all Android devices, such as a standalone app, widget, or baked into the Gallery or Camera app.

What is finder pattern in QR code?

Finder Patterns are separated from the rest of a QR Code by a light area of width one module. Finder Patterns are used by readers to determine position and orientation of a QR Code. Timing patterns—these are placed inside a QR Code and interconnect finder patterns.

Can QR codes be scanned from screenshots?

Open the Google Lens app, and go to the “image” option. Select the screenshot with the QR code. The app will scan the code, and generate its link in seconds. You can select the “only the QR code” option if there is text, or any other element on the image.


1 Answers

You don't need to use xcorr2. You should look for a 1:1:3:1:1 (widths of dark-light-dark-light-dark) pattern in 1d using scanlines.

There is a description of a reference detection algorithm on page 60 of the standard.

Also, ZXing is an open-source library that implements QR code detection/recognition. You can go over their code for reference.

Edit: At each scanline, count subsequent dark and subsequent light pixels. You will get a list of integers representing sequence lengths.

Then start from the largest dark subsequence, and look to its sides. If the dark subsequence length is 300, then its adjacent light subsequences should be of length 50-150, and their adjacent dark subsequences should be of length 50-150 as well (this is due to the tolerance of 0.5 proposed in the standard.).

So if you find such a sequence, you mark it with size 300. Then you try the next largest dark subsequence and so on.

Just to clarify, the above method should be used to find the 3 marked corners.

like image 69
Michael Litvin Avatar answered Oct 24 '22 00:10

Michael Litvin