# Research on a Multi-Type Barcode Defect Detection Model Based on Machine Vision
## 4 Experiment and Results Analysis
### Confusion Matrix Analysis  
To further validate the model's classification performance on different categories of targets, this paper constructs a confusion matrix based on the inference results from the test set, as shown in Figure 11. In the matrix, TP, TN, FP, and FN represent the classification results for each model: True Positives, True Negatives, False Positives, and False Negatives. From this, Precision, Recall, and F1 score for the two categories can be calculated, with the equations related to the confusion matrix as follows:  
\[Recall\ =\ \frac{TP}{TP\ +\ FN}\text{, }Precision\ =\ \frac{TP}{TP\ +\ FP}\text{, }F1\ -\ score\ =\ \frac{2\times Precision\times Recall}{Precision\ +\ Recall} \tag{14}\]  
Figure 10: Evaluation curves on the test set: PR, F1–Confidence, Recall–Confidence, and Precision–Confidence. (**a**) Precision–Recall curve; (**b**) F1–Confidence curve; (**c**) Recall–Confidence curve; (**d**) Precision–Confidence curve. 1D Barcode Classification Results: The model correctly identified 2403 1D barcodes as 1D, misclassified 3 as 2D, missed 11 as background, and misclassified 54 background objects as 1D. \(Precision_{1D}\approx 0.978\), \(Recall_{1D}\approx 0.994\), \(F1-score_{1D}\approx 0.986\). 2D Barcode Classification Results: The model correctly identified 465 2D barcodes as 2D, misclassified 22 as 1D, missed 19 as background, and no false positives for 2D barcodes in the background are shown in the figure. \(Precision_{2D}\approx 0.955\), \(Recall_{2D}\approx 0.919\), \(F1-score_{2D}\approx 0.937\). From the results, it can be seen that the model achieves a Precision and Recall greater than 0.97 for 1D barcodes, with an F1 score of 0.9861, which is nearly saturated. Although the performance for 2D barcodes is slightly lower, it remains at a high level, with an F1 score of 0.9363. As discussed earlier in the curve analysis, the slightly lower performance for 2D barcodes is mainly due to factors such as small target size and strong reflective interference, which lead to some missed detections or misclassifications. Overall, the model demonstrates stable and efficient recognition ability for both types of barcodes. To compare the proposed detector with established baselines, we reproduced the models of [PERSON] et al. [21], Faster R-CNN [35], RetinaNet [36], YOLO-Nano and YOLO-Medium [7], and RT-DETR [37] using the authors' released code and hyperparameters, then retrained each model on the same training split of the BarBeR dataset. Evaluation was performed on the held-out test split, in which every image contains at least one barcode of the relevant type. A detection was counted as correct when it satisfied an intersection-over-union (IoU) threshold of 0.5. Instance-level Precision, Recall, and F1 score obtained under these conditions are reported in Tables 2 and 3 for one-dimensional (1D) and two-dimensional (2D) barcodes, respectively. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Detection Method** & **Precision** & **Recall** & **F1 Score** \\ \hline [PERSON] et al. [21] & 0.715 & 0.940 & 0.812 \\ Faster R-CNN [35] & 0.979 & 0.990 & 0.984 \\ RetinaNet [36] & 0.984 & 0.986 & 0.985 \\ YOLO Nano [7] & 0.985 & 0.988 & 0.986 \\ YOLO Medium [7] & 0.982 & 0.989 & 0.985 \\ RT-DETR [37] & 0.986 & 0.993 & 0.989 \\ Y8-LiBAR-1D & 0.978 & 0.994 & 0.986 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Comparative Results of 1D Barcode Object Detection (Each Image Contains \(\geq\) 1 One-Dimensional Barcode, IoU = 0.5). Figure 11: Evaluation curves on the test set: PR, F1–Confidence, Recall–Confidence, and Precision–Confidence. (**a**) Confusion Matrix; (**b**) Normalized Confusion Matrix. For 1D barcodes, Y8-LiBAR-1D achieved an F1 score of 0.986, only 0.003 (0.3 percentage points) lower than the best-performing RT-DETR. For 2D barcodes, Y8-LiBAR-2D obtained the highest F1 score of 0.937, edging the second-ranked Faster R-CNN by 0.001 (0.1 percentage points).