QR Code Recognition
Revision History
| NO | Version | Description | Date |
|---|---|---|---|
| 1 | Ver1.0 | Initial creation | 2026/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
The execution efficiency on the CSUN RV1126B board is as follows:
| Algorithm Type | Execution Efficiency |
| QR Code Recognition | 32ms |
| One-dimensional Barcode Recognition | 29ms |
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:
cd ~/linuxshare/work/rv1126b/jp/embedded/images/develop_environment./run.sh 2204
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.
cd /opt/linuxshare/work/rv1126b/jp/AI/demo/ai-algorithmUse the git tool to clone the remote repository into the management directory.
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:
cd rv1126b-ai-toolkit/Demos/algorithm-qrdecode/./build.sh cpres* Because the dependent libraries are located on the development board, keep /mnt mounted during cross-compilation.
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
2.5 Sample Execution and Results
Copy the compiled files to the board.
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:
cd /userdata/Demo/algorithm-qrdecode/The command for running the sample is as follows:
./test-qrdecode EASY-EAI-QRcode.png
Figure 2-3 QR Code RecognitionSample Execution Result
In the Docker development environment, copy the test Result Image from the board.
cp /mnt/userdata/Demo/algorithm-qrdecode/result.jpg .
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
The same program can also recognize one-dimensional barcode images.
./test-qrdecode 1-code.pngThe test image can be obtained in the EASY-EAI compile environment:
cp /mnt/userdata/Demo/algorithm-qrdecode/result.jpg .The result image is as follows:

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.
| Item | Description |
| Header File Directory | easyeai-api/algorithm/qrdecode |
| Library File Directory | easyeai-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 File | qrdecode.h |
| Input Parameter | src: image in OpenCV Mat format |
| Output Parameter | path: QR code detection result output |
| Return Value | Return value on success: 0 |
| Return value on failure: -1 | |
| Notes | None |
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
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;}