Embedded QR Code Recognition System Based on Image Processing

Weilong Zheng, Junwu Weng, Zhuangbin Huang, Zhenzhen Zhuang


This project was supported by the Fundamental Research Funds for the Central Universities. It aimed to implement a device which was used to recognize QR Code (Quick Response Code) by using camera. In this project, I am mainly responsible for the QR Code sampling and decoding algorithms.


The images we process are from a camera installed on our embedded demo board. Generally, these pictures look like the photo shown in Figure 1(1). As we could see, in order to sample the QR code in this picture, there should be two problems need to be solved. First, segment the QR code from the original image so that background noise would not interfere performance of sampling algorithm. Second, rotate the QR code to its right position.

  • (1) Original Image

  • (2) Segmented Image

  • (3) Rotated Image

  • Figure 1. Image Processing Procedure

Image Segmentation

Here, we utilize the Quiet Zone, green area in Figure 2, around QR code to segment QR code zone. First, the original image need to be transformed into gray image. Then we use Sobel Operator to detect edges of the gray image. By projecting the horizontal and vertical "edge images" of the gray image to x and y axis respectively, we could get two histograms and the positions of the Quiet Zone may appear at troughs in these two histograms. Then we could get the segmented image shown in Figure 1(2). As we can see, the original image could not be segmented perfectly. However, this algorithm could still reduce area of background noise.

  • Figure 2. QR Code Structure

Image Rotation

We use Otsu's Method to binarize the segmented gray image. Then scan this image row by row to search the black and white sequence whose compound ratio is 1:1:3:1:1 (the feature of QR Code Position Symbol, as shown in Figure 3). Because no matter at which angle the scan line goes through the center of the Position Symbol, the compound ratio stays the same, we do not need to take the rotation angle of the QR Code into consideration. After this step, we could obtain coordinations of three Position Symbols and then calculate the rotation angle of QR Code. The result is shown in Figure 1(3).

  • Figure 3. Position Symbol


Since we alreadly know the coordinations of three Position Symbols (rotated), we could then build the sampling grid and sample the binary data of this QR Code.


In order to decode QR Code, we first need to find out the Version Information and Format Information of QR Code. The positions of these two information are shown in Figure 2. By this way, the Error Correction Level and Mask Pattern of QR Code could be found out. The following steps are masking QR Code by using Mask Pattern, rearranging data blocks and decoding data blocks. More details could be seen in Wikipedia.