# Data Extraction Method for Industrial Data Matrix Codes Based on Local Adjacent Modules Structure
## 5 Barcode Data Extraction
### Classify Pairs of Adjacent Modules by CNN  
Traditional image classification methods need handcrafted features and classifiers for training features, such as SVM and KNN, which have low classification accuracy, unsatisfactory effects, and weak adaptive ability. With the development of CNN, computational power, and computer vision, deep learning methods for image classification tasks have surpassed traditional algorithms in accuracy and real-time performance. Deep learning methods make it easy to analyze images with complex backgrounds for some specific tasks. A CNN system may have somewhere between 3 to 150 or even more layers and CNN layers can be of four main types: Convolution Layer, ReLu Layer, Pooling Layer, and Fully-Connected Layer.  
Five CNN architectures are chosen for our task based on their present performance in image classification [21], including AlexNet [22], GoogleNet [23], VGG16 [24], VGG19 [24], and ResNet50 [25]. Table 1 shows their performance in ILSVRC challenge.  
\begin{table}
\begin{tabular}{c c c c c} \hline
**ILSVRC** & **Number of** & **Top 5 Error Rate** & **Training** & **Execution** \\
**Architectures** & **Layers** & **Top 5 Error Rate** & **Dataset** & **Environment** \\ \hline AlexNet (2012) & 8 & 15.3\% & ImageNet & Two GTX 580 \\ GoogleNet & & & GPUs 3 Gg \\ (2014) & 22 & 6.67\% & ImageNet & CPU \\ VGGNet (2014) & 16-19 & 6.8\% & ImageNet & Four NVIDIA Titan Black GPU \\ ResNet (2015) & 18-34-50-101-152 & 3.57\% & ImageNet & Two GPUs \\ \hline \end{tabular}
\end{table}
Table 1: Comparison between different CNN architectures for image classification.  
Figure 5: Proposal sampling: (**a**) sample by two adjacent modules; (**b**) samples and the classification labels.  
Figure 6: The flow chart of the proposed barcode data extraction method.  
In order to sample pairs of adjacent modules from a barcode image, a sliding window algorithm is applied in the barcode image, which size is the same as the size of the two adjacent cells of the barcode grid. The sliding window with one grid stride scans the barcode image according to the position of the grid vertices. The sliding window has two states: horizontal and vertical. The horizontal sliding window in Figure 7a samples horizontal pairs of adjacent modules, and the vertical sliding window in Figure 7c samples vertical pairs of adjacent modules.  
We train a CNN network to learn the colors of a pair of two adjacent modules and classify the pairs into two categories according to whether the two adjacent modules have the same color or not. So, we use the pairs as the input of CNN models and use labels 0 and 1 as the output of CNN models. It is defined that label 0 represents the class of a pair with the same color, and label 1 represents the other class of a pair with different colors. Two matrices are used to save labels of horizontal and vertical pairs, respectively. The labels are stored in the matrix in sequence according to the original position of the sampled pairs of adjacent modules. Figure 7b,d show the horizontal and the vertical pair label matrix, respectively.