Skip to content

QR Code Recognition

Revision History

NOVersionDescriptionDate
1Ver1.0Initial creation2026/06/29

The information in this document may be changed without prior notice for the purpose of improving the document. Please refer to our website for the latest version.

Reproduction in any form without the written permission of Nissho Technology Co., Ltd. is strictly prohibited.

1. QR Code RecognitionOverview

A two-dimensional barcode / QR code (2-dimensional bar code) records data symbol information by arranging specific geometric patterns on a plane (in two dimensions) according to certain rules and using black-and-white patterns. During encoding, it makes effective use of the concept of bit streams “0” and “1”, which form the logical basis inside a computer, and represents character or numeric information with multiple geometric shapes corresponding to binary values. Automatic reading through an image input device or optical scanner enables automatic information processing. Similar to barcode technology, each code system has its own character set, each character has a certain width, and the code provides error detection and correction capabilities. It also supports automatic identification of information in different rows and adaptation to rotation changes in the graphic.

Figure 1-1 QR CodeStructure

Figure 1-1 QR CodeStructure

The execution efficiency on the CSUN RV1126B board is as follows:

Algorithm TypeExecution Efficiency
QR Code Recognition32ms
One-dimensional Barcode Recognition29ms

2. Quick Start

2.1 Preparing the Development Environment

If you are reading this document for the first time, refer to Getting Started / Preparing and Updating the Development Compilation Environment, and deploy the compilation environment according to the related steps.

On the Ubuntu system on the PC side, run the run script to enter the Docker development environment. The steps are as follows:

Terminal window
cd ~/linuxshare/work/rv1126b/jp/embedded/images/develop_environment
./run.sh 2204

Figure 2-1 Starting the Docker Development Environment

Figure 2-1 Starting the Docker Development Environment

2.2 Downloading the Source Code

In the Docker development environment, create a management directory for storing the source code repository.

Terminal window
cd /opt/linuxshare/work/rv1126b/jp/AI/demo/ai-algorithm

Use the git tool to clone the remote repository into the management directory.

Terminal window
git clone https://github.com/csunltd/rv1126b-ai-toolkit.git

※ Even when downloading from the GitHub web page, download the entire repository. Do not download only the directory corresponding to this sample.

※ If the repository has already been downloaded, skip this step.

2.3 Building the Sample

Move to the directory containing the sample and execute the build. The specific commands are as follows:

Terminal window
cd rv1126b-ai-toolkit/Demos/algorithm-qrdecode/
Terminal window
./build.sh cpres

* Because the dependent libraries are located on the development board, keep /mnt mounted during cross-compilation.

Terminal window
sudo mount -t nfs -o vers=3,proto=tcp,mountproto=tcp,nolock,retrans=5,timeo=5 192.168.10.85:/ /mnt

* When the cpres parameter is specified for the build.sh script, all resources in the Release/ directory are copied to the development board.

Figure 2-2 Sample Build Result

Figure 2-2 Sample Build Result

2.5 Sample Execution and Results

Copy the compiled files to the board.

Terminal window
cp Release/\* /mnt/userdata/Demo/algorithm-qrdecode/

※ If you build with ./build.sh cpres, the files are copied automatically.

Enter the backend of the development board through serial debugging or SSH debugging, and move to the sample deployment directory as follows:

Terminal window
cd /userdata/Demo/algorithm-qrdecode/

The command for running the sample is as follows:

Terminal window
./test-qrdecode EASY-EAI-QRcode.png

Figure 2-3 QR Code RecognitionSample Execution Result

Figure 2-3 QR Code RecognitionSample Execution Result

In the Docker development environment, copy the test Result Image from the board.

Terminal window
cp /mnt/userdata/Demo/algorithm-qrdecode/result.jpg .

Figure 2-4 QR Code Recognition Result

Figure 2-4 QR Code Recognition Result

The recognition result is shown in the following figure.

Figure 2-5 One-dimensional Barcode RecognitionSample Execution Result

Figure 2-5 One-dimensional Barcode RecognitionSample Execution Result

The same program can also recognize one-dimensional barcode images.

Terminal window
./test-qrdecode 1-code.png

The test image can be obtained in the EASY-EAI compile environment:

Terminal window
cp /mnt/userdata/Demo/algorithm-qrdecode/result.jpg .

The result image is as follows:

Figure 2-6 One-dimensional Barcode Recognition results

Figure 2-6 One-dimensional Barcode Recognition results

For detailed API descriptions and API calls (the source code of this sample), refer to the following.

3. QR Code RecognitionAPI Description

3.1 Reference Method

To allow users to call the EASY EAI API library directly from a local project, the libraries and header files that need to be linked in this project are listed below. Users can add them directly.

ItemDescription
Header File Directoryeasyeai-api/algorithm/qrdecode
Library File Directoryeasyeai-api/algorithm/qrdecode
Library Link Parameter-lzbar

3.2 QR Code RecognitionExecution Function

QR Code RecognitionExecution Functionprototypeas follows.

int qr_decode(cv::Mat src, struct qrcode_info \*p_info)

The details are as follows.

Function Name: qr_decode()
Header Fileqrdecode.h
Input Parametersrc: image in OpenCV Mat format
Output Parameterpath: QR code detection result output
Return ValueReturn value on success: 0
Return value on failure: -1
NotesNone

4. QR Code Recognition Sample

The sample directory is Demos/algorithm-qrdecode/test-qrdecode.cpp, and the operation flow is as follows.

Figure 4-1 QR Code Recognition Algorithm Processing flow

Figure 4-1 QR Code Recognition Algorithm Processing flow

The reference sample is as follows.

#include <opencv2/opencv.hpp>
#include <stdio.h>
#include <sys/time.h>
#include "qrdecode.h"
using namespace cv;
int main(int argc, char **argv)
{
if( argc != 2)
{
printf("./test-qrdecode xxx\n");
return -1;
}
struct timeval start;
struct timeval end;
float time_use=0;
Mat image;
image = cv::imread(argv[1], 1);
gettimeofday(&start,NULL);
struct qrcode_info info;
qr_decode(image, &info);
gettimeofday(&end,NULL);
time_use=(end.tv_sec-start.tv_sec)*1000000+(end.tv_usec-start.tv_usec);//マイクロ秒
printf("time_use is %f\n",time_use/1000);
printf("x1:%d\n", info.x1);
printf("x2:%d\n", info.x2);
printf("y1:%d\n", info.y1);
printf("y2:%d\n", info.y2);
printf("type:%s\n", info.type);
printf("result:%s\n", info.result);
rectangle(image, Point(info.x1, info.y1), Point(info.x2, info.y2), Scalar(0, 255, 0), 3);
imwrite("result.jpg", image);
return 0;
}