# Fuzzy Application in the Design of QR Code Data Binding Based on the GD Packaging Machine

Authors: Wei Taicheng; Chen Hao; Zhu Haoran
Journal: Mobile Information Systems
 (2022)

---

## Abstract

The tracking of raw materials, production, and circulation links is carried out using QR codes in cigarette products. Each link’s current data collection and correlation analysis are still in the research and development stage. When used in conjunction with the GD packing machine’s production process feature, the QR code reader serves as an acquisition element for the process of data acquisition and the associated design for the tobacco packets and boxes, and the software is used to associate the received data and correct process exceptions. The system satisfies the design requirements, according to the results of the field verification.


---

## Body

## 1. Introduction

The tobacco industry is propelled by consumer demand. With the advancement of science and technology, distinguishing the authenticity of tobacco products from the outer packaging has become difficult. On the other hand, because of my country’s strict control over tobacco propaganda in traditional media and limited media, consumers find it difficult to broaden their awareness of tobacco brands. With the research and statistics of the tobacco industry in recent years, the traditional tobacco industry has been continuously integrated with high and new technologies such as “Internet +” and the Internet of things [1]. As a carrier, the QR code is widely used in the tobacco industry and can effectively control production, processing, quality inspection, logistics, sales, and other links. Make analysis and judgments based on the data collected in each link, and make timely responses to abnormal situations. The construction of the Internet of things in the tobacco industry has effectively improved production efficiency, ensured product quality, and made consumers feel at ease. At the same time, it becomes a link for consumers [2].With the rapid development of the tobacco industry, the most common GD X2 (hard pack) model in the market has a small box packing capacity of 400 packs per minute. Through manual identification and manual entry of the QR code analysis data, it cannot respond to actual production requirements. In addition, the market is in the research and development stage for the data correlation between the small box and the bar box QR code. Most of the methods are to use multistation and multihardware collection, background data screening, and hardware redundancy, and the system is too complicated. The visual analysis of QR code data technology is currently fairly developed and can reach a recognition rate of more than 99 percent without impacting the efficiency of package production. The electrical and software design of the GD packaging machine realizes data association when combined with the product packaging process [3].This article primarily describes how the Nanning Cigarette Factory’s packaging workshop implemented data correlation technology between the tiny box and the box QR code based on the GD X2 (hard pack) concept.


## 2. Two-Dimensional Code Analysis Design

### 2.1. QR Code Format

Both the small box and the bar box use the fast-reading two-dimensional matrix code known as a QR code for their two-dimensional data collection. The black-and-white modules, placement patterns, data regions, and error-correcting codes that make up a QR code. The positioning pattern is distributed along the three corners of the QR code, which supports fast reading. From any position of the pattern, the ratio of black and white modules is 1 : 1 : 3 : 1 : 1, which is not disturbed by the image position, and the QR code format is shown in Figure1.Figure 1
QR code structure.There are 40 versions of the QR code. According to the standard, the QR code starts with a matrix of version 1 (21 ∗ 21) and increases by 4 symbol units in both the horizontal and vertical directions until it reaches version 40 (177 ∗ 177). Different versions of the QR codes are printed after decoding the same data, which affects the speed of parsing to a certain extent [4].


### 2.2. Code Reader

Combined with the production speed requirements of the GD machine, in order to quickly collect the two-dimensional code information, the two-dimensional code reader is used as the acquisition element [5]. A QR code reader’s hardware integrates a CCD camera, multicore processor, memory, and digital I/O. With one-key tuning, it can automatically adjust the best-captured image setting parameters (exposure gain and focal length automatic correction), parallel processing of captured images, parsing QR codes (pipeline operation reduces parsing time), multiple parsing algorithms, multiple codes, and symbols in one image application, with a high recognition rate [6].


### 2.3. Light Source

Comparing the contrast between the printed code and the background is typically how two-dimensional code analysis is accomplished [7]. While the skins of cigarette packs at the location are primarily white and yellow, the standard cigarette pack’s QR code is printed with black patterns. The background color of the QR code will reflect the emitting light source to appear brilliant, whereas the black code will absorb the light source and appear dark when using a strong red LED light source. Therefore, a higher contrast image, as shown in Figure 2, can be obtained, which is easy to convert into a high-quality binary image [8].Figure 2
Capture QR code pictures.There are some textures on the surface during the QR code collection process [9, 10]. When the light source illuminates the box, the surface forms diffuse reflection, as shown in Figure 3. By increasing the light intensity, the concave and convex parts of the printing surface appear white, so as to avoid some black spots around the two-dimensional code when converting the binary image, which makes the two-dimensional code unable to be parsed. Code images with enhanced light intensity, as shown in Figure 4, are in a state of high-quality recognition [11, 12].Figure 3
Ordinary red light.Figure 4
Highlight red light.


## 2.1. QR Code Format

Both the small box and the bar box use the fast-reading two-dimensional matrix code known as a QR code for their two-dimensional data collection. The black-and-white modules, placement patterns, data regions, and error-correcting codes that make up a QR code. The positioning pattern is distributed along the three corners of the QR code, which supports fast reading. From any position of the pattern, the ratio of black and white modules is 1 : 1 : 3 : 1 : 1, which is not disturbed by the image position, and the QR code format is shown in Figure1.Figure 1
QR code structure.There are 40 versions of the QR code. According to the standard, the QR code starts with a matrix of version 1 (21 ∗ 21) and increases by 4 symbol units in both the horizontal and vertical directions until it reaches version 40 (177 ∗ 177). Different versions of the QR codes are printed after decoding the same data, which affects the speed of parsing to a certain extent [4].


## 2.2. Code Reader

Combined with the production speed requirements of the GD machine, in order to quickly collect the two-dimensional code information, the two-dimensional code reader is used as the acquisition element [5]. A QR code reader’s hardware integrates a CCD camera, multicore processor, memory, and digital I/O. With one-key tuning, it can automatically adjust the best-captured image setting parameters (exposure gain and focal length automatic correction), parallel processing of captured images, parsing QR codes (pipeline operation reduces parsing time), multiple parsing algorithms, multiple codes, and symbols in one image application, with a high recognition rate [6].


## 2.3. Light Source

Comparing the contrast between the printed code and the background is typically how two-dimensional code analysis is accomplished [7]. While the skins of cigarette packs at the location are primarily white and yellow, the standard cigarette pack’s QR code is printed with black patterns. The background color of the QR code will reflect the emitting light source to appear brilliant, whereas the black code will absorb the light source and appear dark when using a strong red LED light source. Therefore, a higher contrast image, as shown in Figure 2, can be obtained, which is easy to convert into a high-quality binary image [8].Figure 2
Capture QR code pictures.There are some textures on the surface during the QR code collection process [9, 10]. When the light source illuminates the box, the surface forms diffuse reflection, as shown in Figure 3. By increasing the light intensity, the concave and convex parts of the printing surface appear white, so as to avoid some black spots around the two-dimensional code when converting the binary image, which makes the two-dimensional code unable to be parsed. Code images with enhanced light intensity, as shown in Figure 4, are in a state of high-quality recognition [11, 12].Figure 3
Ordinary red light.Figure 4
Highlight red light.


## 3. The Composition of the Electrical System

### 3.1. The Overall Structure of the Two-Dimensional Code System

The incremental encoder is used as the input signal for acquisition, and the main control board composed of an ARM chip outputs the trigger signal of the code reader [13]. The code reader sends the parsed data to the industrial computer through the serial port, and the software receives the data for analysis, processing, and correlation [14–16]. Interaction between humans and computers, between computers and software, and between humans and code readers all takes place on the display. When the program detects a deviation from the norm, it sends a signal to the main control board by way of the GPIO ports. After the main control board has been given the abnormal enable signal, it will send the alarm and error-related data, as well as the cigarette bar rejection signal, to the machine that it came from. The system structure diagram is shown in Figure 5 [17].Figure 5
Overall system structure.


### 3.2. Two-Dimensional Code Acquisition Synchronization Signal

In the packaging process of the GD machine, the box packaging machine and the small box transparent paper packaging machine use a unified power [18]. The carton packaging machine runs for one cycle, and the small box transparent paper packaging machine runs for five cycles. Incremental encoders are installed on the motion spindle of the carton packer. According to the input of the A-phase, B-phase, and Z-phase pulse signals, as shown in Figure 6, the main control board outputs the code reading box trigger signal, the bar box trigger signal, and the push bar signal, respectively [19].Figure 6
Input and output pulse signals.


## 3.1. The Overall Structure of the Two-Dimensional Code System

The incremental encoder is used as the input signal for acquisition, and the main control board composed of an ARM chip outputs the trigger signal of the code reader [13]. The code reader sends the parsed data to the industrial computer through the serial port, and the software receives the data for analysis, processing, and correlation [14–16]. Interaction between humans and computers, between computers and software, and between humans and code readers all takes place on the display. When the program detects a deviation from the norm, it sends a signal to the main control board by way of the GPIO ports. After the main control board has been given the abnormal enable signal, it will send the alarm and error-related data, as well as the cigarette bar rejection signal, to the machine that it came from. The system structure diagram is shown in Figure 5 [17].Figure 5
Overall system structure.


## 3.2. Two-Dimensional Code Acquisition Synchronization Signal

In the packaging process of the GD machine, the box packaging machine and the small box transparent paper packaging machine use a unified power [18]. The carton packaging machine runs for one cycle, and the small box transparent paper packaging machine runs for five cycles. Incremental encoders are installed on the motion spindle of the carton packer. According to the input of the A-phase, B-phase, and Z-phase pulse signals, as shown in Figure 6, the main control board outputs the code reading box trigger signal, the bar box trigger signal, and the push bar signal, respectively [19].Figure 6
Input and output pulse signals.


## 4. Software Design

### 4.1. Software Design Framework

The little box and the bar box both have two-dimensional codes on them, and the two-dimensional code reader is able to conduct image recognition on those codes. The bar code scanner sends the data that it has processed to the industrial computer, and the program receives the information that has been identified by the little box in turn. A new data list is formed by associating and binding the two-dimensional code data of the cigarette pack with the two-dimensional code data of the box corresponding to the packaging relationship. The overall design flow chart of data acquisition is shown in Figure7.Figure 7
A flow chart of overall software design.The background data and display data of the two-dimensional code detection and correlation system mainly include two parts: one part is the real-time data collected by the system from the field equipment, and the other part is the storage of the relationship data of the small box-bar box two-dimensional code information [20]. These data primarily cover three different types of data: the first type is the two-dimensional code information that is recognized by the code reader; the second type is the record of some operating system log machine abnormal information data; and the third type is logically associated data that is processed by software through real-time data [21].


### 4.2. Software Related Measures

The collected data follows the “first-in, first-out” data queue method, and defines the cigarette pack data from the location where the small box collects the QR code to the location where the small box and the carton are packaged as the cached data. In the software, the number of cigarette packs will be set as the pair length, and the data will form a circular queue buffer of small boxes and double stacks as shown in Figure8. When the length of the received data is equal to the set pair length, the small box first enters the pair of data out of the queue, and the number of dequeues is based on the received push bar signal as a node, and the small box QR code data is associated with the large QR code data [22].#define Max size 50//Set according to the capacity of cigarette packs in the on-site channeltype def int Queue;type def Struct {Queue[Max size];int front; \int rear;}SqQueue;bool Push (SqQueue∗ &q, ElemType num){if (q -> rear < Max size − 1);//Determine whether the capacity of the cigarette pack has been metq -> rear++; //join the teamq -> data[q -> rear] = num;}bool deQueue (SqQueue∗ &q, ElemType num) {if(q -> rear = Max size − 1)//Judgment is fullPull_I/O -> read_DI0; //Read the push bar signal;q -> front++; //out of the teamnum =q -> data[q -> front];}Figure 8
Locket queue data.There will be delays in data transmission, frame loss of serial data, and irregular initialization of the system when the production is carried out. The validity of the data association cannot be guaranteed by anything other than the queue relationship. The small box in the machine’s peripheral rhythm takes data, and the program encodes it into a queue. The machine’s peripheral rhythm is moving. The reading of the push bar signal is interpreted as a signal, and the gathered data of the current packaging box is dequeued. Additionally, the cached data from the small box queue is dequeued, and the two processes combine to form a data binding relationship.Small box dequeue data basis: icount = N-(buffer-BarCode num).icount: the number of small boxes associated; N: the number of packages; the number of buffer queue caches; BarCode num: the number of reading small packages.When the QR code data is not parsed by the reader or the data is not received during the software cycle, the software polls the GPIO signal of the lower computer. When the software reads the I/O signal, it avoids the accumulation of errors, and the software automatically fills in the occupancy data. At the same time, the abnormal signal is output to the main control board, and the main control board controls the output of the alarm device or rejection. If the received collected data exceeds the number of queue buffers and cannot match the I/O signal pulse count, the software will reinitialize the data and redetermine the pairing and data association [23].


### 4.3. Data Association Check

After the data is associated, the software outputs the JSON file in a certain format. It includes date, shift, machine, small box QR code data, and bar box QR code data. According to the running time or the number of data associations, the output JSON file is made.Tobacco bar samples are collected manually to test the correctness of the association between the QR code data of the small box and the QR code data of the box [24, 25].


## 4.1. Software Design Framework

The little box and the bar box both have two-dimensional codes on them, and the two-dimensional code reader is able to conduct image recognition on those codes. The bar code scanner sends the data that it has processed to the industrial computer, and the program receives the information that has been identified by the little box in turn. A new data list is formed by associating and binding the two-dimensional code data of the cigarette pack with the two-dimensional code data of the box corresponding to the packaging relationship. The overall design flow chart of data acquisition is shown in Figure7.Figure 7
A flow chart of overall software design.The background data and display data of the two-dimensional code detection and correlation system mainly include two parts: one part is the real-time data collected by the system from the field equipment, and the other part is the storage of the relationship data of the small box-bar box two-dimensional code information [20]. These data primarily cover three different types of data: the first type is the two-dimensional code information that is recognized by the code reader; the second type is the record of some operating system log machine abnormal information data; and the third type is logically associated data that is processed by software through real-time data [21].


## 4.2. Software Related Measures

The collected data follows the “first-in, first-out” data queue method, and defines the cigarette pack data from the location where the small box collects the QR code to the location where the small box and the carton are packaged as the cached data. In the software, the number of cigarette packs will be set as the pair length, and the data will form a circular queue buffer of small boxes and double stacks as shown in Figure8. When the length of the received data is equal to the set pair length, the small box first enters the pair of data out of the queue, and the number of dequeues is based on the received push bar signal as a node, and the small box QR code data is associated with the large QR code data [22].#define Max size 50//Set according to the capacity of cigarette packs in the on-site channeltype def int Queue;type def Struct {Queue[Max size];int front; \int rear;}SqQueue;bool Push (SqQueue∗ &q, ElemType num){if (q -> rear < Max size − 1);//Determine whether the capacity of the cigarette pack has been metq -> rear++; //join the teamq -> data[q -> rear] = num;}bool deQueue (SqQueue∗ &q, ElemType num) {if(q -> rear = Max size − 1)//Judgment is fullPull_I/O -> read_DI0; //Read the push bar signal;q -> front++; //out of the teamnum =q -> data[q -> front];}Figure 8
Locket queue data.There will be delays in data transmission, frame loss of serial data, and irregular initialization of the system when the production is carried out. The validity of the data association cannot be guaranteed by anything other than the queue relationship. The small box in the machine’s peripheral rhythm takes data, and the program encodes it into a queue. The machine’s peripheral rhythm is moving. The reading of the push bar signal is interpreted as a signal, and the gathered data of the current packaging box is dequeued. Additionally, the cached data from the small box queue is dequeued, and the two processes combine to form a data binding relationship.Small box dequeue data basis: icount = N-(buffer-BarCode num).icount: the number of small boxes associated; N: the number of packages; the number of buffer queue caches; BarCode num: the number of reading small packages.When the QR code data is not parsed by the reader or the data is not received during the software cycle, the software polls the GPIO signal of the lower computer. When the software reads the I/O signal, it avoids the accumulation of errors, and the software automatically fills in the occupancy data. At the same time, the abnormal signal is output to the main control board, and the main control board controls the output of the alarm device or rejection. If the received collected data exceeds the number of queue buffers and cannot match the I/O signal pulse count, the software will reinitialize the data and redetermine the pairing and data association [23].


## 4.3. Data Association Check

After the data is associated, the software outputs the JSON file in a certain format. It includes date, shift, machine, small box QR code data, and bar box QR code data. According to the running time or the number of data associations, the output JSON file is made.Tobacco bar samples are collected manually to test the correctness of the association between the QR code data of the small box and the QR code data of the box [24, 25].


## 5. Conclusion

The GD machine packaging machine is equipped with a two-dimensional code detection and association system, which enables the data association of a two-dimensional code between a small box and a bar box. This is made possible by the GD machine packaging machine. According to the findings, the recognition rate of a code reading can get up to 99 percent, the accuracy of data association can get up to 99.5 percent, and the feedback effect is satisfactory. At a later stage, further optimization designs might be applied in order to achieve a higher recognition rate.



---

*Source: 6447578-2022-10-03.xml*