*4.1. Image Acquisition Devices*

Figure 21a shows a concise diagram of the imaging system, and Figure 21b is the corresponding picture of the material object. The image acquisition device includes cameras and a light source. Two line-scan charge-coupled device (CCD) cameras are used to capture images of 4096 × 1024 size of an aluminum ingot surface after milling under the illumination of light source, and the resolution is 0.315 mm/pixels. When the aluminum ingot passes through the acquisition device, the image acquisition program will control the acquisition speed of the camera according to the production speed and store the image. At the same time, the defect detection algorithm starts to process the image, and it alarms in time when defects are found.

**Figure 21.** The imaging system: (**a**) a concise diagram and (**b**) picture of the material object.

## *4.2. E*ff*ectiveness of Our Method*

For 5 days, we randomly checked the defect detection results of 39 production records and compared them with the real products. The detection rate of the algorithm is over 98.0%, and the accuracy of defect recognition rate is 96.0%. The statistical method of detection rate is as follows: the number of defects detected by the surface inspection system (regardless of defect category) accounts for the percentage of the number of defects on the surface of aluminum ingot.

### *4.3. Time E*ffi*ciency*

The aluminum ingot region detection and the ROI extraction of the proposed approach were implemented by using C++ and OpenCV 2.4.6 library in Microsoft Visual Studio 2008, and the defect ROI classification is implemented by using python and Keras. The proposed approach was executed on a workstation with a 2.8 GHz Intel Xeon i5 processor and 16 GB memory, and the workstation is configured with a piece of NVIDIA Tesla k40c. The average time consumption of one image in each step is given in Table 5. Our detection system achieves an average processing speed of approximately 2.43 fps. The production speed of the aluminum ingot milling machine production line is from 3 to 6 m/min, when the actual production speed is 6 m/min, the corresponding camera acquisition speed is approximately 0.31 fps, so our algorithm can meet the real-time requirements.



To sum up, by applying our defect detection method to the online surface inspection system, the production is guided by the timely alarm of defects, which has great significance for ensuring product quality and improving production efficiency. In addition, the using effect also proves the promising application of our method in the surface defect detection of aluminum ingot with complex texture background after milling.

### **5. Conclusions**

We proposed a novel two-stage detection approach to adaptively detect different types of defect on the surface of aluminum ingot with a complex milling grain background.

Firstly, the combination of MGRTS, DoG, and the similar region merging for the ROI extraction boosts the detection performance of various defects. Secondly, the data augmentation and the focal loss used in the inception-v3 network fine tuning handled the class imbalance well and improved the classification accuracy. Finally, the experimental results and the application in the actual production line show that when the number of defect ROI samples is large but the number of labeled original image samples is small, the performance of the two-stage defect detection algorithm proposed in this paper is significantly better than that of the one-stage deep learning algorithm. At the same time, it can also meet the real-time requirements.

Our algorithm combines the traditional detection and deep learning classification methods, which has great advantages in field application, because it can not only make full use of CPU and GPU to maximize the processing speed, but it also can be put into use quickly at the beginning of the project in the case of a lack of samples.

In future work, we will continue to collect more samples from the production line, including difficult cases and false defects. Then, we will focus on exploring a multi-scale analysis method and full convolution semantic segmentation network to further improve the detection effect of various defects. **Author Contributions:** Methodology, Y.L.; software, Y.L.; validation, P.Z.; formal analysis, K.X.; resources, P.Z.; data curation, K.X.; writing—original draft preparation, Y.L.; writing—review and editing, K.X.; project administration, P.Z.; funding acquisition, K.X. All authors have read and agreed to the published version of the manuscript.

**Funding:** This research was funded in part by the National Key R&D Program of China under Grant 2018YFB0704304, and in part by the National Natural Science Foundation of China (NSFC) under Grant 51674031 and Grant 51874022.

**Conflicts of Interest:** The authors declare no conflict of interest.

### **References**


© 2020 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
