To address the technical challenge of identifying tiny defects, especially dust and point defects, on mobile phone flat glass, an automatic optical inspection system is established. The system investigates algorithms including imaging principles, target detection models, data augmentation, foreground segmentation, and image fusion. The system builds an automatic optical inspection platform to collect glass defect samples. It illuminates the glass samples with a combined total reflection–grazing light source, collects the defect sample data, segments the background and defects of the collected data, generates the defect mask, and extracts the complete defects of the cell phone flat glass. The system then seamlessly integrates the extracted defects with a flawless background using Poisson editing and outputs the location information of the defects and the label output to automatically generate the dataset. The deep learning network YOLOv5 works as the core algorithm framework, into which the Constructive Block Attention Module and the small target detection layer are specifically added to enhance the capability of the model to detect small defects. According to the experimental results, the combined lighting effectively improves the precision of detecting dust and bright spots. Additionally, with the adoption of novel data augmentation techniques, the enhanced YOLOv5 model is capable of effectively addressing the challenges posed by inefficient sample data and non-uniform distribution, thus mitigating network generalization issues. Furthermore, this data augmentation approach facilitates the rapid adaptation of the same detection tasks to diverse environmental scenarios, enabling the expedited and efficient deployment of the model across various industrial settings. The mean average precision (MAP) of the optimal model in the validation set reached 98.36%, 2.62% higher than that of the original YOLOv5. In addition, its false acceptance rate (FAR) is 1.27%, its false rejection rate (FRR) was 2.47%, its detection speed was 64 fps, and its correct detection rate in the validation set was 98.75%, which meets the current industrial detection requirements by and large. In this way, this paper achieved the automated inspection of mobile phone flat glass with high robustness, high precision, and a low false acceptance rate and false rejection rate, significantly reducing material losses in the factories and the likelihood of error occurrence in follow-on products. This method can be applied to the multi-scale and multi-type detection of glass defects.