Abstract
This paper presents a study on the surface roughness detection of sand castings utilizing machine vision technology combined with image processing techniques. A residual convolutional neural network integrated with an attention mechanism was trained using surface images of standard roughness blocks. This trained network was then employed as the core of a detection software, coupled with an image acquisition module, to achieve non-contact measurement of casting surface roughness. The developed system was tested on actual sand castings, achieving an accuracy rate of 87.5% with a single measurement time of 0.086 seconds. This approach provides a rapid, accurate, and convenient means of measuring casting roughness in practical production environments.

Introduction
With the rapid development of technology, the casting industry has gradually become an essential component of high-end equipment manufacturing, playing a crucial role in the modernization of China’s industry and the development of the equipment manufacturing sector. Surface roughness is a vital indicator for assessing the surface quality of components, closely related to factors such as wear resistance, fatigue strength, and vibration noise, significantly impacting component performance and service life. The surface roughness of sand castings typically ranges from Ra3.2 to Ra50. Traditionally, this is measured using the standard block comparison method, which is susceptible to subjective factors. Contact measurement methods, such as stylus profilometers, have a measurement range of Ra0.025 to Ra12.5 and are greatly limited by space constraints, making them difficult to use for measuring the surface roughness of sand castings or casting molds. Therefore, there is an urgent need for a method that can quickly, accurately, and conveniently measure the roughness of castings in actual production.
This study explores the application of machine vision technology in the field of surface roughness detection of sand castings. By combining image processing techniques and convolutional neural networks, a non-contact surface roughness detection system for sand castings is developed. This system aims to reduce the influence of subjective factors on measurement results, improve the objectivity and efficiency of surface roughness assessment, and provide a reference for the application of subsequent non-contact measurement methods.
Literature Review
Previous research has demonstrated the feasibility of using image-based methods for surface roughness detection. Dai et al. found that feature parameters such as histogram mean, variance, and kurtosis extracted from casting surface images have a corresponding relationship with surface roughness. Lu et al. built a casting surface image analysis system using a CCD camera and computer, realizing the automatic extraction of surface roughness-related features, which confirmed the feasibility of calculating surface roughness from captured images. Neural networks, as a type of computational model composed of multiple layers of neurons, can handle complex nonlinear mapping relationships. Shao constructed a fully connected neural network and trained it using extracted surface image features as input parameters, achieving a mapping from casting surface roughness images to surface roughness values. However, the number of image features extracted manually is limited, and the extraction process may lose other important information related to roughness contained in the images, thus presenting certain limitations. Additionally, related research has focused solely on the accuracy of dataset recognition, lacking validation on actual castings.
Convolutional neural networks (CNNs), as a special type of neural network structure, can effectively utilize spatial information from images while reducing the number of parameters that need to be learned in the neural network. They have played an important role in image recognition, image segmentation, and pattern recognition . This study leverages the combination of image processing and CNN-based machine vision technology to build a surface roughness detection system for sand castings, enabling rapid and non-contact detection of casting surface roughness. This approach aims to minimize the impact of subjective factors on measurement results, enhance the objectivity and efficiency of surface roughness assessment, and provide a reference for the application of subsequent non-contact measurement methods.
Experimental Methodology
The experimental methodology involves several key steps, including dataset preparation, neural network construction and training, and testing on actual castings. A detailed technical roadmap is provided to illustrate the overall process.
1. Dataset Preparation
1.1 Surface Image Acquisition
Standard roughness blocks for casting surface quality assessment were used as the dataset source. Images of five roughness grades (Ra3.2 to Ra50) from both steel sand mold and aluminum-zinc-magnesium metal mold standard blocks were collected. A CMOS image sensor-based macro camera module (DYVCAM-W20246 V22) with an output image size of 640 px × 480 px and unilateral side lighting was employed for image acquisition. An auxiliary shell designed for stable lighting conditions during image capture was 3D printed using black resin and connected via a USB interface.
1.2 Image Preprocessing
Due to the use of a macro lens, the image center was clear while the edges were blurred, which could adversely affect subsequent recognition results. Therefore, images were cropped to a 480 px × 480 px square during preprocessing. Additional preprocessing steps included grayscale conversion, contrast-limited adaptive histogram equalization (CLAHE), and median filtering to enhance image contrast, reduce noise, and highlight texture differences between different roughness surfaces.
1.3 Data Augmentation
To expand the dataset and improve the neural network’s generalization ability, data augmentation techniques such as horizontal flipping were applied, doubling the number of images to 6,956. The dataset was divided into training, validation, and test sets with 4,916, 1,040, and 1,000 images, respectively.
2. Neural Network Construction and Training
2.1 Attention Mechanism and Residual Convolutional Neural Network
A residual convolutional neural network integrated with a squeeze-and-excitation (SE) attention mechanism was constructed. The SE module, a lightweight attention mechanism, enhances important features by applying global average pooling, two 1×1 convolutional layers, a ReLU layer, and a Sigmoid function to generate an attention weight vector. This vector is then multiplied by the original feature map.
2.2 Neural Network Training
The neural network was trained using Python and PyTorch, with an Adam optimizer and cross-entropy loss function. The initial learning rate was set to 0.1, the batch size to 64, and the maximum number of training epochs to 2000. The model with the highest validation accuracy was selected as the final classification model.
3. Testing on Actual Castings
A surface roughness detection software was developed based on Python, capable of capturing real-time images from the image acquisition device, preprocessing the images, and outputting detection results using the trained neural network model. The software was tested on stainless steel pump housings and aluminum alloy volute casings, with the results compared to those obtained using the standard block comparison method.
Results and Discussion
1. Dataset Preparation
A total of 3,478 images of standard roughness blocks were collected and augmented to 6,956 images. After preprocessing, the images exhibited improved contrast and reduced noise, highlighting texture differences between different roughness surfaces.
2. Neural Network Training
The neural network was trained for 280 epochs, with the validation accuracy converging around the 90th epoch. The final model achieved recognition accuracies of 99.00% and 99.60% on the two test sets, respectively.
3. Testing on Actual Castings
The developed detection software was tested on stainless steel pump housings and aluminum alloy volute casings. A total of 32 measurements were taken at different key locations on each casting, with 4 misidentifications, resulting in an overall accuracy rate of 87.5%. The average time for a single measurement was 0.086 seconds.
Casting Type | Standard Block | SE-ResNet-50 | Correct/Incorrect |
---|---|---|---|
Stainless Steel Pump Housing | Ra6.3 | Ra6.3 | Correct |
Ra12.5 | Ra12.5 | Correct | |
Ra6.3 | Ra6.3 | Correct | |
Ra6.3 | Ra6.3 | Correct | |
Ra3.2 | Ra3.2 | Correct | |
Ra3.2 | Ra3.2 | Correct | |
Ra3.2 | Ra6.3 | Incorrect | |
Ra12.5 | Ra12.5 | Correct | |
Ra12.5 | Ra12.5 | Correct | |
Ra12.5 | Ra12.5 | Correct | |
Ra6.3 | Ra12.5 | Incorrect | |
Ra6.3 | Ra6.3 | Correct | |
Ra6.3 | Ra6.3 | Correct | |
Ra6.3 | Ra6.3 | Correct | |
Ra12.5 | Ra12.5 | Correct | |
Ra12.5 | Ra12.5 | Correct | |
Aluminum Alloy Volute Casing | Ra50 | Ra50 | Correct |
Ra50 | Ra50 | Correct | |
Ra50 | Ra50 | Correct | |
Ra25 | Ra25 | Correct | |
Ra12.5 | Ra12.5 | Correct | |
Ra12.5 | Ra12.5 | Correct | |
Ra25 | Ra50 | Incorrect | |
Ra50 | Ra50 | Correct | |
Ra50 | Ra50 | Correct | |
Ra50 | Ra50 | Correct | |
Ra50 | Ra50 | Correct | |
Ra25 | Ra50 | Incorrect | |
Ra25 | Ra25 | Correct | |
Ra12.5 | Ra12.5 | Correct | |
Ra25 | Ra25 | Correct | |
Ra25 | Ra25 | Correct |
Table 1: Test results of casting surface roughness
Conclusion
This study presents a surface roughness detection system for sand castings based on machine vision and image processing techniques. By utilizing a residual convolutional neural network integrated with an attention mechanism, the system achieves non-contact measurement of casting surface roughness. Testing on actual castings demonstrated an accuracy rate of 87.5% with a single measurement time of 0.086 seconds, indicating the system’s potential for rapid, accurate, and convenient roughness measurement in practical production environments.