Method and system for detecting casting defects of valve housing based on machine vision
Patent Information
- Application Number
- CN202611216604.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-12
- Publication Date
- 2026-10-27
AI Technical Summary
第一,采集端多采用单相机配合旋转台的扫描方式,工件旋转过程易产生运动模糊,旋转机构增加设备复杂度与检测周期,难以适配高速生产线节拍;部分多相机方案未针对阀壳回转曲面结构优化布局,存在检测盲区
[0036]本发明通过多工位工业相机阵列环形布置与同步触发采集,实现对阀壳顶面、底面及周向表面的全表面无盲区覆盖,消除单相机旋转扫描方案的运动模糊与检测盲区问题。图像拼接环节同步生成接缝区域掩码矩阵,该掩码矩阵跨模块联动至预处理环节与特征提取环节,分别用于逐像素自适应调整去噪阈值与对比度增强系数、衰减修正接缝区域特征权重,配合接缝区域梯度方向二次校验,形成从图像层到特征层的全链路接缝伪影抑制机制,有效降低拼接伪缺陷误检率。通过分类置信度反向反馈优化特征加权系数,构建特征提取与分类识别的闭环优化链路,低置信度样本自动强化高区分度特征贡献,提升小样本缺陷类型的识别准确率。
Smart Images

Figure CN122989674A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of industrial casting visual inspection technology, specifically relating to a method and system for detecting defects in valve shell casting based on machine vision. Background Technology
[0002] Valves, as core components of fluid control systems, are widely used in industrial applications such as petroleum, chemical, power, and water treatment. The valve body, as the pressure-bearing component of the valve, directly determines the valve's operational reliability and service life through its casting quality. The valve body casting process involves multiple steps, including metal smelting, pouring, and cooling. Various casting defects, such as porosity, inclusions, cracks, and cold shuts, are prone to appear on the casting surface. Casting defects reduce the mechanical and sealing properties of the valve body; undetected defects may lead to media leakage or structural failure during valve service, threatening industrial production safety. Defect detection after valve body casting is a necessary step to ensure product quality.
[0003] Machine vision inspection is a non-contact, non-destructive testing technology. It uses industrial cameras to acquire images of the target surface and employs image processing and pattern recognition algorithms to automatically identify defects. It features high inspection speed, strong repeatability, and no damage to the workpiece, and is gradually replacing traditional manual visual inspection, becoming the mainstream technology in the field of industrial defect detection. For the detection of surface defects in castings, existing technologies have formed a standard processing chain of image acquisition, preprocessing, feature extraction, and classification.
[0004] Existing defect detection solutions for valve body castings still have several shortcomings. First, the acquisition end often uses a single camera with a rotating stage for scanning. The workpiece rotation process easily introduces motion blur, increasing equipment complexity and inspection cycle time, making it difficult to adapt to high-speed production line cycles. Some multi-camera solutions lack optimized layout for the valve body's curved surface structure, resulting in blind spots. Second, image stitching and preprocessing are independent processes. The grayscale differences at the seams caused by stitching are not compensated for in the preprocessing stage, easily leading to false defects in the seam area. Third, defect identification often uses single features or fixed-weight feature combinations, resulting in uneven feature representation capabilities for different defect types. The accuracy of identifying small sample defect types is low, and the feature extraction and classification identification stages lack a closed-loop feedback optimization mechanism. Fourth, defect size quantification often uses planar projection conversion, failing to consider the projection deviation caused by the valve body's curved surface structure. Depth estimation methods are simplistic, and shadow depth calculation is based on the ideal Lambertian body assumption, failing to consider the photometric model deviation caused by the non-uniform distribution of micro-roughness on the casting surface, resulting in insufficient quantification accuracy. Fifth, the test results are only used for product quality assessment and are not correlated with casting process parameters, so they cannot guide process optimization in reverse and the value of the test data is not fully realized; the life prediction does not consider the influence of surface micro-properties on stress concentration, thus limiting the prediction accuracy. Summary of the Invention
[0005] The purpose of this invention is to provide a method and system for detecting defects in valve shell casting based on machine vision. It achieves blind-zone-free imaging through multi-view synchronous acquisition and image stitching, establishes a full-link artifact suppression mechanism with cross-module linkage of joint area masks, combines feature-classification closed-loop feedback optimization, contrast-driven dual-source depth fusion and surface size correction, introduces micro-roughness cross-domain compensation to eliminate photometric model bias, improves detection accuracy and quantification precision, and extends defect distribution and process correlation analysis to realize the transformation of detection data into process value.
[0006] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0007] A machine vision-based method for detecting defects in valve shell casting includes the following steps:
[0008] Acquire original images of the valve shell surface simultaneously from multiple different perspectives, perform feature matching and transformation matrix estimation on the original images, stitch them together to generate a panoramic image of the valve shell surface, and simultaneously generate a mask matrix for the seam area.
[0009] Using the seam area mask matrix as a parameter adjustment factor, the noise reduction threshold and contrast enhancement coefficient are adaptively adjusted pixel by pixel to preprocess the panoramic image of the valve shell surface.
[0010] The depth features and multiple manual features of the preprocessed panoramic image are extracted, and the feature weights at different locations are corrected by combining the seam area mask matrix, and a weighted defect feature vector is generated by fusing them.
[0011] The weighted defect feature vector is input into a multi-classifier, which outputs the defect type and the corresponding classification confidence. The feature weighting coefficient is adjusted in reverse according to the classification confidence to obtain the optimized defect feature vector and complete the final classification and recognition.
[0012] The identified defect areas are located at the pixel level. The physical size parameters of the defects are calculated by combining dual-source depth estimation based on multi-view parallax and shadow features and valve shell surface projection correction. The physical size parameters are compared with the batch-calibrated evaluation criteria to output the defect level judgment result.
[0013] As a preferred technical solution of the present invention, the acquisition of original images of the valve shell surface simultaneously acquired from multiple different perspectives is specifically as follows: a multi-station industrial camera array is arranged in a ring around the circumference of the valve shell, covering the top surface, bottom surface and circumferential surface of the valve shell, the included angle between the optical axes of adjacent cameras is not greater than 60°, and the overlap rate of the field of view of adjacent cameras is not less than 20%; all cameras are uniformly controlled by a synchronous trigger controller, and the synchronization accuracy of the trigger signal is better than 100 μs.
[0014] As a preferred technical solution of the present invention, the process of stitching together a panoramic image of the valve shell surface and simultaneously generating a seam area mask matrix specifically involves: extracting scale-invariant feature transformation feature points from each of the original images, estimating the homography transformation matrix between adjacent images using a random sampling consensus algorithm; projecting all the original images onto a unified coordinate system based on the homography transformation matrix, performing fade-in / fade-out grayscale fusion on the overlapping areas to generate the panoramic image of the valve shell surface; marking the center line of the seam in the stitched overlapping areas, extending a preset pixel width along both sides of the center line to form the seam area, generating a binary seam area mask matrix, with the seam area pixels marked as 1 and the non-seam area pixels marked as 0.
[0015] As a preferred embodiment of the present invention, the preprocessing using the seam region mask matrix as a parameter adjustment factor specifically involves: employing a wavelet transform adaptive threshold denoising algorithm to suppress image noise, wherein the wavelet denoising threshold is adjusted pixel-by-pixel by the seam region mask matrix, satisfying the following equation:
[0016]
[0017] in, Representing coordinates Wavelet denoising threshold corresponding to a pixel; The baseline noise reduction threshold for the non-seamless region; This represents the noise reduction threshold adjustment coefficient for the seam area; This indicates that the seam area mask matrix is located in coordinates. The value at the location; An adaptive histogram equalization algorithm is used to improve image contrast. The contrast enhancement coefficient is adjusted in reverse according to the same logic. The enhancement coefficient of the seam area is lower than that of the non-seam area to suppress the excessive amplification of gray-scale abrupt changes at the seam.
[0018] As a preferred technical solution of the present invention, the specific steps of correcting feature weights and fusing them with the seam area mask matrix to generate a weighted defect feature vector are as follows: A deep convolutional neural network is used to extract 512-dimensional depth features from the image; 10-dimensional handcrafted features, including texture, shape, and geometric features, are extracted from the defect area; the depth features and the handcrafted features are concatenated to obtain an initial feature vector; the weights of various features at different positions are attenuated and corrected using the seam area mask matrix, with the attenuation magnitude of edge features being greater than that of texture features, reducing edge feature interference caused by splicing artifacts; the initial feature vector is multiplied element-wise by the corresponding feature weight to generate a weighted defect feature vector.
[0019] As a preferred embodiment of the present invention, adjusting the feature weighting coefficients in reverse according to the classification confidence score specifically involves: obtaining the classification confidence score of the initial classification output; when the classification confidence score is lower than a preset optimization threshold, updating the feature weights based on the classification confidence score and the discriminant coefficients of each feature category, with the update formula satisfying the following equation:
[0020]
[0021] in, Indicates the updated number Class feature weights; Indicates the number before the update Class feature weights; The learning rate represents the confidence level feedback; This represents the classification confidence score of the current sample, with a value range of [value range missing]. ; Indicates the first The class discrimination coefficient of class features, with a value range of 100%. The weighted defect feature vector is recalculated using the updated feature weights, input into the multi-classifier to complete the secondary classification, and the final classification result is output.
[0022] As a preferred embodiment of the present invention, the multi-classifier employs a one-to-one voting multi-class support vector machine, comprising 15 binary support vector machines, and uses a radial basis function kernel; the classification confidence is calculated using a probability transformation method, with a value range of [value missing]. When the classification confidence level is lower than the preset confidence threshold, the corresponding defect is marked as a suspected defect and sent for manual review; the labeled samples after manual review are stored in the sample library, and the multi-class support vector machine is incrementally trained periodically.
[0023] As a preferred technical solution of the present invention, after the final classification and recognition and before pixel-level positioning, a secondary verification step for pseudo-defects in the seam area is also included: extracting the principal gradient direction of the defect candidate area in the seam area and the local direction of the seam, and calculating the angle between them; when the angle is less than a preset angle threshold, the defect extension direction is consistent with the seam direction, and it is determined to be a splicing artifact, and the corresponding defect candidate area is marked as a pseudo-defect and removed.
[0024] As a preferred embodiment of the present invention, dual-source depth estimation specifically involves: calculating the disparity depth value based on the disparity of the same defect in multi-view images; calculating the shadow depth value based on the shadow texture features of the defect region; calculating the fusion weight based on the local contrast value output by the preprocessing, and performing weighted fusion of the disparity depth value and the shadow depth value, wherein the fusion process satisfies the following formula:
[0025]
[0026] in, Representing coordinates The final estimated defect depth at the location, in mm; Representing coordinates Local contrast value at; This represents the maximum contrast value in the panoramic image of the valve housing surface; This represents the depth value calculated based on multi-view parallax, in mm. This represents the depth value calculated based on shadow shape recovery, in mm.
[0027] As a preferred technical solution of the present invention, the valve shell surface projection correction specifically involves: mapping the defect pixel coordinates to the surface of the standard three-dimensional model of the valve shell, obtaining the surface normal vector at the location of the defect, and calculating the angle between the surface normal vector and the camera optical axis; correcting the defect size calculated by the planar projection based on the angle, with a larger angle resulting in a higher correction magnitude, to obtain the true defect size on the valve shell surface.
[0028] As a preferred technical solution of the present invention, after outputting the defect level determination result, the method further includes: statistically analyzing the spatial distribution characteristics of defects on the valve body surface, performing time-series matching of the spatial distribution characteristics with casting process parameters, calculating the correlation degree between each process parameter and the defect occurrence rate through grey relational analysis, and outputting process parameter optimization suggestions; collecting historical detection data and corresponding valve body service life data, training a long short-term memory neural network life prediction model, and correcting the prediction result by combining the defect stress concentration coefficient, with a larger correction range for sharper defects, and outputting the predicted value of the remaining service life of the valve body.
[0029] As a preferred technical solution of the present invention, the evaluation criteria after batch calibration are as follows: Before each production batch is started, the surface gray value of the standard calibration part is collected, and the gray value is compared with the reference gray value to calculate the gray value drift ratio. The defect segmentation threshold and grading threshold are adjusted according to the same ratio to offset the detection deviation caused by changes in ambient light and equipment aging. The calibration cycle is synchronized with the production batch.
[0030] This invention also discloses a machine vision-based valve shell casting defect detection system, used to execute the machine vision-based valve shell casting defect detection method described above, including an image acquisition module, an image stitching module, a preprocessing module, a feature extraction module, a classification and recognition module, a quantization and grading module, and a data storage module; the image acquisition module is used to simultaneously acquire multiple original images of the valve shell surface from different perspectives and output the original images to the image stitching module; the image stitching module is used to receive the original images from the image acquisition module, generate a panoramic image of the valve shell surface through feature matching and transformation matrix estimation, simultaneously generate a seam region mask matrix, and output the panoramic image of the valve shell surface and the seam region mask matrix to the preprocessing module and the feature extraction module; the preprocessing module is used to receive the panoramic image of the valve shell surface and the seam region mask matrix from the image stitching module, adaptively adjust the denoising threshold and enhancement coefficient using the seam region mask matrix as an adjustment factor, and after completing the preprocessing, output the preprocessed image and local contrast data to the feature extraction module and the quantization and grading module; The feature extraction module receives the preprocessed image from the preprocessing module and the seam region mask matrix from the image stitching module, extracts multi-dimensional features, and combines the mask to correct feature weights, generating a weighted defect feature vector. The weighted defect feature vector is then output to the classification and recognition module. The classification and recognition module receives the weighted defect feature vector from the feature extraction module, outputs the defect type and classification confidence score, feeds the classification confidence score back to the feature extraction module to optimize feature weights, and outputs the classification result and defect location information to the quantization and grading module. The quantization and grading module receives the classification result and defect location information from the classification and recognition module, the preprocessed image from the preprocessing module, and contrast data. It performs defect pixel localization, dual-source depth estimation, surface size correction, and grade determination, outputting the final detection result. The data storage module receives and stores all process data and final result data generated by all modules.
[0031] As a preferred embodiment of the present invention, before calculating the shadow depth value based on the shadow texture features of the defect region, a micro-roughness compensation step for the shadow depth features is further included: obtaining the coefficients of each of the five high-frequency sub-bands obtained by the wavelet transform adaptive threshold denoising algorithm in the defect region decomposition, wherein each high-frequency sub-band coefficient includes three types of high-frequency components in the horizontal, vertical, and diagonal directions; calculating the local energy variance of each high-frequency sub-band coefficient, and constructing the corresponding micro-roughness characterization coefficients of the defect region based on the local energy variance; constructing a reflectivity compensation function based on the micro-roughness characterization coefficients, and using the reflectivity compensation function to correct the diffuse reflection component of the pixel grayscale of the defect region, thereby eliminating the Lambertian model deviation caused by the sudden change in local micro-roughness of the valve body surface on the shadow depth calculation; and calculating the shadow depth value using the pixel grayscale of the defect region after the diffuse reflection component correction.
[0032] As a preferred embodiment of the present invention, the diffuse reflection component of the pixel grayscale of the defective region is corrected using a reflectivity compensation function, and the correction calculation process satisfies the following formula:
[0033]
[0034] in, Representing coordinates The pixel grayscale after diffuse reflection component correction; Representing coordinates The original pixel grayscale value is not corrected. This indicates the pre-calibrated roughness photometric sensitivity coefficient for the valve body casting material; Representing coordinates The local energy variance is calculated based on five high-frequency sub-bands. The maximum value of the local energy variance statistically obtained from the panoramic image of the valve body surface is represented; the maximum value and arithmetic mean of the micro-roughness characterization coefficients are extracted, and the maximum value and the arithmetic mean are combined to form a micro-roughness feature vector; the micro-roughness feature vector is concatenated and fused into the input feature sequence of the long short-term memory neural network lifetime prediction model to dynamically correct the defect stress concentration coefficient; the larger the local energy variance value, the greater the attenuation of the valve body remaining service life prediction value output by the long short-term memory neural network lifetime prediction model.
[0035] Compared with the prior art, the present invention has the following beneficial effects:
[0036] This invention achieves full-surface, blind-spot-free coverage of the valve body's top, bottom, and circumferential surfaces through a multi-station industrial camera array arranged in a ring and synchronously triggered for acquisition, eliminating motion blur and detection blind spot problems inherent in single-camera rotating scanning schemes. During image stitching, a seam region mask matrix is generated synchronously. This mask matrix is linked across modules to the preprocessing and feature extraction stages, respectively used for pixel-by-pixel adaptive adjustment of the denoising threshold and contrast enhancement coefficient, and attenuation correction of seam region feature weights. Combined with secondary verification of the seam region gradient direction, this forms a full-link seam artifact suppression mechanism from the image layer to the feature layer, effectively reducing the false detection rate of stitching defects. By optimizing the feature weighting coefficients through classification confidence feedback, a closed-loop optimization link for feature extraction and classification recognition is constructed. Low-confidence samples automatically enhance the contribution of high-discrimination features, improving the recognition accuracy of small sample defect types.
[0037] In the defect quantification stage, cross-domain compensation for micro-roughness is introduced. The high-frequency sub-band coefficients from preprocessed wavelet decomposition are transformed into micro-roughness characterization coefficients. A reflectivity compensation function is constructed to correct pixel grayscale, eliminating the influence of Lambertian model bias on shadow depth calculation. Using the local contrast value from the preprocessed output as a weighting basis, the disparity depth value and the corrected shadow depth value are weighted and fused to achieve dual-source adaptive depth estimation. Combined with valve shell surface projection correction, the planar projection size is converted into the actual surface size, significantly improving the quantification accuracy of defect depth and size. A grayscale calibration mechanism synchronized with production batches is set up, dynamically adjusting the defect segmentation threshold and grading threshold according to the grayscale drift ratio to ensure the long-term stability of the production line. The detection data is further extended to gray relational analysis of casting process parameters and remaining life prediction based on long short-term memory neural networks. Micro-roughness features are also used to dynamically correct stress concentration coefficients, improving life prediction accuracy and realizing the full-chain transformation of data value from defect detection to process optimization and life assessment. Attached Figure Description
[0038] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained from these drawings without creative effort.
[0039] Figure 1 This is an overall flowchart of the detection method of the present invention.
[0040] Figure 2 This is a flowchart of the secondary verification branch for pseudo-defects in the joint area of the present invention.
[0041] Figure 3 This is a flowchart of the micro-roughness compensation sub-process of the present invention.
[0042] Figure 4 This is a flowchart of the confidence-based reverse feedback optimization sub-process of the present invention. Detailed Implementation
[0043] In the following description, only certain exemplary embodiments are briefly described. As those skilled in the art will recognize, the described embodiments can be modified in various ways without departing from the spirit or scope of the embodiments of the invention. Therefore, the drawings and description are considered to be exemplary in nature and not restrictive.
[0044] The following is in conjunction with the appendix Figures 1-4 The embodiments of the present invention will be described in detail below.
[0045] The overall execution flow of the machine vision-based valve shell casting defect detection method disclosed in this invention is as follows: image acquisition and stitching, adaptive image preprocessing, multi-dimensional defect feature extraction, defect classification and feedback optimization, defect quantization and grading, and data storage and process analysis. The image stitching stage synchronously outputs a seam region mask matrix, which is simultaneously transmitted to the adaptive image preprocessing stage and the multi-dimensional defect feature extraction stage. These are used to adjust preprocessing parameters and correct feature weights, respectively, forming end-to-end seam artifact suppression from the image layer to the feature layer. The local contrast value output by the adaptive image preprocessing stage is transmitted to the defect quantization and grading stage to adjust the dual-source depth fusion weights, achieving coordinated adaptation of image quality and depth estimation. The wavelet high-frequency sub-band coefficients generated by the adaptive image preprocessing stage are synchronously transmitted to the defect quantization and grading stage for micro-roughness characterization and photometric model correction, realizing cross-domain multiplexing of frequency domain signals and geometric measurements.
[0046] The weighted defect feature vector output from the multi-dimensional defect feature extraction stage is input into the defect classification and identification stage. The classification confidence score output from the defect classification and identification stage is fed back to the multi-dimensional defect feature extraction stage to optimize the feature weighting coefficients, forming a closed-loop optimization between classification and features. The defect distribution data and micro-roughness features output from the defect quantification and grading stage are transmitted to the process analysis stage for process parameter correlation and life prediction.
[0047] The method specifically includes the following steps:
[0048] Step S1: Image Acquisition and Stitching; The core function of this step is to acquire a high-quality panoramic image covering the entire surface of the valve body, and at the same time generate a mask matrix for the seam area as the basis for subsequent adjustment of multiple modules.
[0049] A multi-station industrial camera array is fixedly installed along a ring-shaped bracket at each inspection station. The array consists of six cameras, with the optical axes of adjacent cameras forming a 60° angle, corresponding to the six circumferential positions of the valve housing. An auxiliary camera is also positioned on the top and bottom surfaces, comprehensively covering the entire outer surface of the valve housing. All cameras are uniformly controlled by a synchronous trigger controller, with a trigger signal synchronization accuracy better than 100 μs, ensuring that all cameras complete exposure at the same time and avoiding stitching errors caused by minute workpiece displacements. Each camera is equipped with a fixed-focus lens and a ring-shaped diffused light source to reduce the impact of metal surface reflections on imaging.
[0050] The overlap rate of adjacent camera fields of view is determined by both the camera angle and the field of view angle. It is necessary to ensure that the overlapping area contains a sufficient number of feature points to meet the stitching accuracy requirements. For example, if the horizontal field of view angle of a single camera is 75° and the optical axis angle between adjacent cameras is 60°, the corresponding overlap rate is 20%, which can meet the overlapping area requirements for feature matching.
[0051] After acquisition, the original images from all viewpoints are synchronously transmitted to the image processing unit. The image stitching algorithm first extracts feature points from each original image using scale-invariant feature transformation, then matches feature points between adjacent viewpoints, eliminates mismatched points using a random sampling consensus algorithm, and estimates the homography transformation matrix between adjacent images. The random sampling consensus algorithm estimates the homography transformation matrix from a dataset containing outliers iteratively. In each iteration, four sets of matching points are randomly selected to calculate the transformation matrix, and the number of inliers that match the transformation matrix is counted. After the iteration, the transformation matrix with the most inliers is selected as the final result.
[0052] Based on the homography transformation matrix, all the original images are projected onto a unified coordinate system. Gradient-in / gradient-out grayscale fusion is performed on the overlapping areas to smoothly transition the grayscale differences in the overlapping areas, generating a panoramic image of the valve shell surface. Simultaneously, the center line of the seam between the overlapping areas is marked, and a preset pixel width is extended along both sides of the center line to form the seam region, generating a binary seam region mask matrix. For example, if the seam width is set to 15 pixels, then pixels within a range of 7 to 8 pixels on each side of the seam center line are marked as the seam region, and the remaining areas are marked as non-seam regions.
[0053] The generated panoramic image of the valve housing surface completely covers all outer surfaces of the valve housing, with no detection blind spots. The mask matrix of the seam area has the same size as the panoramic image of the valve housing surface and is simultaneously output to the preprocessing module and the feature extraction module as the basis for parameter adjustment in subsequent steps.
[0054] Step S2: Adaptive Image Preprocessing; The core function of this step is to suppress image noise, enhance the contrast of defective areas, and specifically compensate for the grayscale differences in the splicing seams, thereby reducing the probability of subsequent false detections. Preprocessing is divided into two stages: denoising and contrast enhancement. Both stages incorporate the seam region mask matrix as the basis for parameter adjustment.
[0055] The denoising stage employs a wavelet transform adaptive thresholding algorithm. First, a five-level wavelet decomposition is performed on the panoramic image of the valve body surface, using the db4 wavelet as the wavelet basis function. This decomposition yields one low-frequency sub-band and five high-frequency sub-bands. Subsequently, the coefficients of the high-frequency sub-bands are thresholded. The threshold is calculated using an adaptive method based on unbiased risk estimation to achieve adaptive matching of noise levels.
[0056] For the seam area, the denoising threshold is increased based on the baseline threshold to enhance the suppression of stitching artifacts. The calculation method for the pixel-by-pixel denoising threshold is the same as the corresponding formula mentioned above. For example, if the baseline denoising threshold is set to 20 and the adjustment coefficient is set to 0.2, then the denoising threshold for the seam area is 24, which is higher than 20 for the non-seam area, and can more effectively suppress high-frequency artifacts at the seam.
[0057] After thresholding, the denoised image is reconstructed using inverse wavelet transform. The coefficients of the five high-frequency sub-bands are simultaneously preserved for subsequent micro-roughness compensation.
[0058] The contrast enhancement stage employs an adaptive histogram equalization algorithm. The image is divided into 64×64 pixel sliding windows, and the grayscale histogram within each window is equalized. For seam areas, the contrast enhancement coefficient is lowered from the baseline coefficient to prevent abrupt grayscale changes at the seams from being amplified as pseudo-defects. For example, if the baseline enhancement coefficient is set to 1.5, the coefficient for the seam area is proportionally lowered to 1.2 to avoid excessive amplification of grayscale changes at the seams.
[0059] After enhancement processing, the grayscale difference between the defective and normal areas is amplified, significantly improving the discernibility of minor defects. Simultaneously, local contrast values are calculated at various locations within the image. These local contrast values are the difference between the maximum and minimum grayscale values within a window, and are output to the quantization and grading stage to adjust the weights of the dual-source depth fusion process.
[0060] The preprocessed image is output to the feature extraction module and the quantization and grading module. The parameters of the denoising and enhancement process can be calibrated and adjusted according to the on-site environment.
[0061] Step S3: Multi-dimensional defect feature extraction; The core function of this step is to extract multi-dimensional features that can characterize defect attributes from the preprocessed image, and combine them with the seam area mask to correct the feature weights, generating a weighted defect feature vector, which provides a basis for subsequent classification and recognition.
[0062] Feature extraction is divided into two parts: deep feature extraction and manual feature extraction. The two parts of features are concatenated and weighted by a mask to form the final defect feature vector.
[0063] Deep feature extraction is implemented using a deep convolutional neural network. The network structure of the deep convolutional neural network consists of five convolutional layers, three pooling layers, and two fully connected layers. The first convolutional layer has an 11×11 kernel size and a stride of 4, outputting a 96-channel feature map. Following the first convolutional layer is a batch normalization layer and a linear rectified activation layer, then a first max-pooling layer with a pooling window size of 3×3 and a stride of 2. The second convolutional layer has a 5×5 kernel size and a stride of 1, outputting a 256-channel feature map. Following the second convolutional layer is a batch normalization layer and a linear rectified activation layer, then a second max-pooling layer with a pooling window size of 3×3 and a stride of 2. The third to fifth convolutional layers all have a 3×3 kernel size, a stride of 1, and 384, 384, and 256 channels respectively. Each convolutional layer is followed by a batch normalization layer and a linear rectified activation layer. The fifth convolutional layer is followed by a third max-pooling layer with a 3×3 pooling window and a stride of 2. The two fully connected layers have 1024 and 512 neurons respectively, ultimately outputting a 512-dimensional depth feature vector.
[0064] The deep convolutional neural network model was trained using transfer learning. The baseline model was pre-trained on a publicly available image dataset to acquire general image feature extraction capabilities. It was then fine-tuned on a dedicated valve shell defect dataset, containing over 50,000 annotated valve shell defect images covering four common defect morphologies: porosity, inclusions, cracks, and cold shuts. The cross-entropy loss function was used, and the adaptive moment estimation optimizer was employed. The initial learning rate was set to 0.0001, the batch size to 32, and the number of iterations to 50. Data augmentation strategies, including random flipping, random cropping, and brightness perturbation, were used during training to improve the model's generalization ability. The training set to validation set ratio was 9:1, and training stopped when the validation set classification accuracy reached 94% or higher.
[0065] The preprocessed panoramic image is input into a deep convolutional neural network, which outputs a 512-dimensional depth feature vector after forward inference. The inference time for a single image is no more than 20 ms. The depth features contain high-level semantic information about defects and have a strong ability to distinguish defect categories.
[0066] Manual feature extraction comprises three categories: texture features, shape features, and geometric features. Texture features are calculated based on the gray-level co-occurrence matrix, extracting four parameters: contrast, correlation, energy, and uniformity. Shape features are calculated based on the binary region of the defect, extracting four parameters: perimeter, area, roundness, and compactness. Geometric features extract two parameters: the curvature of the defect edge and the initial depth value. The manual features total ten dimensions, which are concatenated and fused with the 512-dimensional depth features to form a 522-dimensional initial feature vector.
[0067] By combining the seam region mask matrix, the weights of various features at different locations are attenuated and corrected, reducing the weight of edge features in the seam region and minimizing feature interference caused by splicing artifacts. The attenuation magnitude of edge shape features is greater than that of texture features because splicing artifacts mainly manifest as abrupt edge changes, which have a stronger impact on edge features. For example, if the baseline weight of edge shape features is 1, the attenuation in the seam region is 0.7; if the baseline weight of texture features is 1, the attenuation in the seam region is 0.9. The feature weight adjustment and the parameter adjustment in the preprocessing stage share the same seam region mask matrix, forming a layer-by-layer artifact suppression from the image layer to the feature layer.
[0068] The initial feature vector is multiplied element by element by the feature weight at the corresponding position to generate a weighted defect feature vector. The weighted defect feature vector is then output to the classification and recognition module.
[0069] Step S4: Defect Classification and Feedback Optimization; The core function of this step is to determine the defect type and output the confidence level based on the input weighted defect feature vector, while optimizing the feature weights through back-feedback of the confidence level, and setting a low-confidence verification mechanism to ensure the reliability of classification.
[0070] The classifier employs a multi-class support vector machine (SVM) based on a one-to-one voting strategy. For four basic defect categories (porosity, inclusions, cracks, and cold shuts) and two composite defect categories, 15 binary SVMs are trained, each classifying one of the two defect types. A radial basis function (RBF) kernel is used, with a penalty parameter of 10 and a kernel parameter of 0.01. All binary SVMs perform the classification in parallel, and the category with the highest number of votes is the final classification result.
[0071] The initial training set contained 30,000 labeled defect samples, with a balanced number of samples in each class. A grid search method was used to optimize the parameters, and five-fold cross-validation was employed to determine the optimal penalty and kernel function parameters. The incremental training period was 7 days, during which newly labeled samples, after manual review, were added to the training set, and the classifier was retrained. The original sample weights were retained during the training process to avoid catastrophic forgetting.
[0072] The multi-class support vector machine receives the weighted defect feature vector, and all binary support vector machines perform parallel discrimination, outputting the final classification result and the corresponding classification margin. Classification confidence is calculated using a probability transformation method, mapping the classification margin to a probability value between 0 and 1. Single-sample classification takes no more than 1 ms.
[0073] The classification confidence score of the initial classification output is obtained. When the classification confidence score is lower than a preset optimization threshold, the feature weights are updated based on the classification confidence score and the discriminant coefficients of each feature class. The feature weight update method is consistent with the corresponding formula mentioned above. For example, if a sample has a classification confidence score of 0.6, a discriminant coefficient of a certain feature class of 0.8, an original weight of 1, and a learning rate of 0.1, the updated weight is calculated to be 1.032, thus increasing the weight of the high-discriminant feature.
[0074] The weighted defect feature vector is recalculated using the updated feature weights and input into the multi-class support vector machine to complete the secondary classification, outputting the final classification result. The confidence-based backfeedback optimization mechanism can automatically strengthen the contribution of high-discriminative features for low-confidence samples, improving classification accuracy.
[0075] A confidence threshold of 0.7 is set. When the final classification confidence is higher than the threshold, the classification result takes effect directly; when the confidence is lower than the threshold, the corresponding defective sample is marked as a suspected defect and automatically pushed to the manual review queue. The labeled data after manual review is stored in the sample library, and the multi-class support vector machine is incrementally trained periodically to continuously optimize the classification accuracy.
[0076] After final classification and identification, a secondary verification step for pseudo-defects in the joint area is performed. This step verifies the candidate defect areas within the joint area, eliminating linear pseudo-defects extending along the joint. The principal gradient direction of the candidate defect areas within the joint area and the local orientation direction of the joint are extracted, and the angle between them is calculated. When the angle is less than a preset threshold of 15°, the defect extension direction is consistent with the joint orientation, and it is determined to be a splicing artifact. The corresponding candidate defect area is then marked as a pseudo-defect and eliminated. This secondary verification step for pseudo-defects in the joint area can further reduce the false detection rate in the joint area.
[0077] The classification results and corresponding defect location information are output to the quantitative grading module.
[0078] Step S5: Defect Quantification and Grading; The core function of this step is to accurately locate and measure the size of defects. The quantification accuracy is improved by dual-source deep fusion, micro-roughness compensation and surface size correction. The defect level is determined by comparing with the quality standard of dynamic calibration, and the final detection conclusion is output.
[0079] Defect localization is achieved using a connected component analysis algorithm. First, adaptive threshold segmentation is performed on the preprocessed image to obtain a binary image of the defect region. The segmentation threshold is dynamically adjusted by a batch calibration mechanism. Then, an eight-neighbor connected component labeling algorithm is used to label all independent defect regions. For each connected component, parameters such as pixel area, boundary coordinates, centroid position, and minimum bounding rectangle are extracted to achieve pixel-level defect localization.
[0080] Defect depth is estimated jointly using multi-view disparity and shadow features, with the fusion weight adjusted by the local contrast value output from the preprocessing. Disparity depth is calculated based on the disparity of the same defect in multi-view images, using triangulation principles as input. The input consists of the pixel coordinate difference of the corresponding point of the defect in different view images and the camera baseline parameters. Micro-roughness compensation is performed before shadow depth calculation to eliminate photometric model bias caused by surface microstructure.
[0081] Micro-roughness compensation uses the five-layer high-frequency sub-band coefficients obtained from wavelet decomposition in the preprocessing stage as input to achieve physical signal multiplexing across stages. The five-layer high-frequency sub-band coefficients obtained from wavelet decomposition contain high-frequency detail information of the image. The energy fluctuations of the high-frequency signal directly correspond to the degree of minute unevenness on the metal surface and can be used as a quantitative characterization of micro-roughness.
[0082] First, the local energy variance of the high-frequency subband coefficients of each layer is calculated. A sliding window is used to traverse the defect region, with the window size set to 7×7 pixels. The statistical variance of the absolute values of all high-frequency subband coefficients within the window is the local energy variance at the corresponding location. The local energy variance constitutes the micro-roughness characterization coefficient of the defect region, realizing the non-contact quantification of surface micro-physical properties through optical means.
[0083] Subsequently, a reflectivity compensation function is constructed based on the micro-roughness characterization coefficient to correct the diffuse reflection component of the pixel grayscale in the defect area. The correction calculation method is consistent with the corresponding formula mentioned above. The roughness photometric sensitivity coefficient is pre-calibrated according to the valve body material; the roughness photometric sensitivity coefficient for ductile iron is calibrated to 0.45. The larger the local energy variance, the higher the surface micro-roughness, the more obvious the scattering attenuation, and the greater the grayscale correction amplitude.
[0084] By recalculating the shadow depth value using the pixel grayscale of the defect area after correction by the diffuse reflection component, a high-precision shadow depth value is obtained after eliminating the bias of the Lambertian model.
[0085] The fusion weights are calculated based on the local contrast values output from the preprocessing. The disparity depth value and the shadow depth value are then weighted and fused, with the fusion process consistent with the aforementioned formula. For example, if the local contrast value at a certain location is 80 and the maximum image contrast value is 100, then the disparity depth weight is 0.8 and the shadow depth weight is 0.2. If the disparity depth is 0.7 mm and the shadow depth is 0.6 mm, the final calculated depth is 0.68 mm. Higher local contrast results in more accurate disparity calculation and a higher corresponding weight; lower local contrast increases the disparity error, leading to a reduction in the disparity weight and an increase in the shadow depth weight, thus ensuring the accuracy of depth estimation in different areas.
[0086] The valve housing has a curved surface structure of revolution, and the dimensions calculated by planar projection have geometric deviations, requiring surface correction. The defect pixel coordinates are mapped to the surface of the standard 3D model of the valve housing, and the surface normal vector at the defect location is obtained. The angle between this surface normal vector and the camera's optical axis is calculated. The defect area calculated by planar projection is corrected based on this angle; the larger the angle, the greater the projection deviation, and the higher the correction magnitude. For example, if the defect area calculated by planar projection is 6 mm², and the surface normal angle is 30°, the corrected actual surface area is approximately 6.93 mm².
[0087] The linear dimensions of defects, such as length and width, are corrected using the same logic to obtain the true surface dimensions. Dimension conversion is based on camera calibration results, which employs the Zhang Zhengyou calibration method. Calibration yields intrinsic and extrinsic parameters of the camera, and the conversion coefficients between pixels and physical dimensions are calculated.
[0088] The defect classification adopts a three-level evaluation standard. Level 1 defects are minor defects, and the criteria for judgment are an area of less than 5 mm² and a depth of less than 0.5 mm; Level 2 defects are moderate defects, and the criteria for judgment are an area of 5 to 20 mm² or a depth of 0.5 to 2 mm; Level 3 defects are severe defects, and the criteria for judgment are an area of more than 20 mm² or a depth of more than 2 mm.
[0089] The grading threshold supports dynamic calibration. Before each production batch starts, the surface grayscale value of a standard calibration part is collected and compared with the reference grayscale value to calculate the grayscale drift ratio. The defect segmentation threshold and grading threshold are then adjusted proportionally. For example, if the reference grayscale value is 128, the currently collected grayscale value is 120, and the reference area threshold is 5 mm², the area threshold for the current batch after calibration will be approximately 5.33 mm², which can offset the segmentation deviation caused by grayscale drift.
[0090] The calibration cycle is synchronized with the production batch to ensure consistency of testing standards between different batches. After quantification and grading are completed, a complete inspection report is generated, including all information such as defect location, defect type, defect size, and defect level.
[0091] Step S6: Data Storage and Process Analysis; The core function of this step is to store the entire process testing data and mine its value, extending to process optimization and lifespan prediction.
[0092] All test data, along with product number, batch number, and timestamp, are stored in the database. The database employs a hybrid architecture of relational and time-series databases; structured data is stored in the relational database, while images and time-series data are stored in the time-series database. The database supports multi-condition searches by product model, defect type, test time, and defect level, with a single query response time not exceeding 100 ms.
[0093] The process correlation analysis module reads defect location data, calculates the distribution density of defects in the circumferential and axial directions of the valve body, and reads process parameters such as pouring temperature, cooling rate, and mold temperature of the corresponding batch from the casting process control system. It then uses a grey relational analysis algorithm to calculate the correlation between each process parameter and the defect occurrence rate.
[0094] The calculation process of grey relational analysis is as follows: The defect occurrence rate sequence is determined as the reference sequence, and each process parameter sequence is used as the comparison sequence; all sequences are dimensionless; the difference between the comparison sequence and the reference sequence is calculated point by point, and the minimum and maximum differences at both levels are extracted; the correlation coefficient at each time point is calculated; the average of the correlation coefficients is taken to obtain the correlation degree. Based on the correlation degree ranking, the process links corresponding to high defect incidence are located, and targeted parameter adjustment suggestions are output.
[0095] The lifetime prediction module is based on a long short-term memory neural network, and the prediction results are corrected by combining the defect stress concentration factor and micro-roughness characteristics.
[0096] The Long Short-Term Memory (LSTM) neural network consists of two LSM layers and a fully connected output layer. The first LSM layer has 128 hidden units, and the second LSM layer has 64 hidden units. The basic input feature dimension is 8-dimensional, including defect area, defect depth, defect number, defect distribution dispersion, service time, operating pressure, operating temperature, and media corrosion level. In the implementation that incorporates micro-roughness compensation, the input feature dimension is expanded to 10-dimensional, adding two new dimensions: the maximum micro-roughness value and the arithmetic mean micro-roughness value. The output is the predicted remaining service life in hours (h).
[0097] The training dataset contains 12,000 historical valve shell inspection data points and corresponding service life data; the training set incorporating micro-roughness features contains 15,000 valve shell samples equipped with roughness inspection data and fatigue life data. The mean squared error loss function is used, and the adaptive moment estimation optimizer is employed. The initial learning rate is set to 0.001, the batch size to 64, and the number of iterations to 100. The training set to test set ratio is 8:2, and the average prediction error on the test set does not exceed 15%.
[0098] Input the current valve body defect detection data and operating parameters, and output the basic life prediction value through forward inference. Determine the corresponding stress concentration factor based on the defect type and geometric parameters, and dynamically correct the stress concentration factor in conjunction with micro-roughness characteristics to adjust the basic life value. The sharper the defect and the higher the micro-roughness, the more obvious the stress concentration and the larger the correction magnitude. For example, if the basic life prediction value is 10000 h, the stress concentration factor for crack-type defects is 1.8, and the corrected life is approximately 5556 h.
[0099] Process optimization suggestions and life prediction results can be fed back to the casting production line control system and production management system via industrial bus, realizing the value extension of the test data.
[0100] To facilitate a better understanding of the present invention by those skilled in the art, the present invention will be further illustrated below with reference to specific implementation examples.
[0101] Example 1: This example is a basic implementation method that describes the complete testing process under standard configuration, covering all core technical features.
[0102] In this embodiment, a machine vision-based valve shell casting defect detection system is deployed at the final inspection station of the valve shell casting production line. Six industrial cameras are evenly arranged along a circular support, with adjacent cameras at a 60° angle. An auxiliary camera is provided on both the top and bottom surfaces, forming an eight-station multi-position industrial camera array. The camera resolution is 2448×2048 pixels, the frame rate is 60 frames per second, the horizontal field of view of a single camera is 75°, and the field of view of a single camera is 200 mm × 200 mm. The synchronization triggering accuracy is 50 μs.
[0103] The inspection process is performed as follows: First, the valve body workpiece is conveyed to the inspection station by a transfer mechanism, and the positioning fixture clamps and positions the workpiece. A synchronous trigger controller sends trigger signals to all cameras, and an array of eight multi-station industrial cameras simultaneously exposes and acquires images of the valve body surface from corresponding viewpoints. The total acquisition time is approximately 80 ms. The overlap rate between adjacent cameras is 20%, meeting the feature matching requirements.
[0104] In the second step, the eight original images are transmitted to the image processing unit. Feature points are extracted and matched using a scale-invariant feature transform algorithm. Approximately 2000 feature points are extracted from each image, and approximately 300 feature points are matched from adjacent images. After removing mismatches using a random sampling consensus algorithm, a homography transformation matrix is obtained. The stitched panoramic image of the valve body surface is 5000×4000 pixels in size, completely covering all outer surfaces of the valve body. The seam width is set to 15 pixels, and a mask matrix for the corresponding seam area is generated.
[0105] The third step involves performing five-layer db4 wavelet denoising and adaptive histogram equalization on the panoramic image of the valve shell surface. The baseline denoising threshold is set to 20, and the seam region denoising threshold adjustment coefficient is set to 0.2. Substituting these values into the denoising threshold adjustment formula, the calculated seam region denoising threshold is 24. The baseline enhancement coefficient is set to 1.5, and the seam region enhancement coefficient is adjusted to 1.2. After denoising, the peak signal-to-noise ratio of the image reaches 36.8 dB, and the contrast in the defect area is significantly improved. Local contrast values are calculated and output synchronously.
[0106] In the fourth step, a deep convolutional neural network performs forward inference on the preprocessed image, extracting 512-dimensional depth features. Simultaneously, 10-dimensional handcrafted features are calculated, including contrast (12.3), correlation (0.78), energy (0.06), uniformity (0.82), perimeter (126 pixels), area (980 pixels), roundness (0.62), compactness (1.45), mean edge curvature (0.31), and initial depth (0.3 mm). The depth features and handcrafted features are concatenated to obtain a 522-dimensional initial feature vector. This is then combined with the seam region mask matrix for feature weighting, with an attenuation coefficient of 0.3 for edge features and 0.1 for texture features, generating a weighted defect feature vector.
[0107] In the fifth step, the multi-class support vector machine receives the weighted defect feature vector. The initial classification outputs the defect type as crack, with a confidence score of 0.62, which is lower than the optimization threshold of 0.7. This triggers confidence feedback optimization. The discriminative coefficient of the crack-type feature is 0.8, and the learning rate for confidence feedback is 0.1. Substituting these values into the weight update formula, the weights of high-discriminative features are increased by approximately 3%. The feature vector is recalculated using the updated weights. The secondary classification output has a confidence score of 0.76, which is higher than the confidence threshold of 0.7, and the classification result takes effect.
[0108] Step 6: Connectivity analysis is performed to mark the defective pixel region, with a defective pixel area of 980 pixels. The pixel physical conversion coefficient is 0.08 mm per pixel, and the planar projected area is 6.272 mm². The parallax depth is calculated to be 0.72 mm, the shadow depth is calculated to be 0.65 mm, the local contrast at the defect location is 80, and the maximum contrast of the panoramic image of the valve shell surface is 100. Substituting these values into the dual-source depth fusion formula, the final depth is calculated to be 0.706 mm. According to the three-level grading standard, the area is in the range of 5 to 20 mm², and the depth is in the range of 0.5 to 2 mm, thus it is classified as a level two defect.
[0109] Step 7: All test data is stored in the data storage module, completing the single valve body test process.
[0110] In this embodiment, the complete inspection cycle for a single valve shell is 28 seconds, the defect classification accuracy is 96.2%, the defect size measurement error is 0.08 mm, the valve shell surface inspection coverage is 100%, and the false detection rate in the joint area is 3.5%.
[0111] Example 2: This example is a further optimization based on Example 1, targeting high-precision detection scenarios, and focuses on improving the accuracy of defect detection and quantification.
[0112] In this embodiment, three optimizations are added based on Embodiment 1: First, a secondary verification of pseudo-defects in the gradient direction of the joint area is added; second, dual-source depth fusion estimation is used to replace single parallax depth; and third, the valve shell surface projection size is corrected.
[0113] In the detection process, after classification and identification are completed, a secondary verification step for pseudo-defects in the joint area is performed, and gradient verification is conducted on the defect candidate areas of the joint area. If the main gradient direction of a defect candidate area in a certain joint area is 88°, and the local direction of the joint is 90°, the angle between the two is 2°, which is less than the angle threshold of 15°, and it is determined to be a pseudo-defect and removed.
[0114] The depth estimation process employs a dual-source fusion approach, prioritizing parallax depth in areas with high local contrast and increasing shadow depth weight in areas with low local contrast, thereby reducing the average depth estimation error from 0.12 mm to 0.066 mm.
[0115] The dimension conversion process includes surface correction. A defect is located on the circumferential side of the valve body, with a surface normal angle of 30° and a planar projected area of 6.272 mm². After correction, the actual surface area is approximately 7.24 mm², which is closer to the actual size of the defect.
[0116] The remaining procedures in this embodiment are consistent with those in Embodiment 1.
[0117] In this embodiment, the false detection rate of defects in the joint area is reduced to 1.2%, a decrease of 65.7% compared to Embodiment 1; the average error in defect depth estimation is reduced by 45%; and the measurement error in defect size in the curved area is reduced by 40%. The overall classification accuracy reaches 97.5%, which is suitable for high-end valve body product testing scenarios with higher requirements for detection accuracy.
[0118] Example 3: This example is based on the same principles as Example 1, but differs in that it focuses on long-term optimization for mass production scenarios, emphasizing the stability of the production line's long-term operation and the extension of data value.
[0119] In this embodiment, grayscale calibration is performed before each production batch starts. The baseline grayscale value of the standard calibration piece is 128, and the grayscale value of the standard calibration piece collected in the current batch is 120, with a grayscale drift coefficient of approximately 1.067. The baseline first-level defect area threshold is 5 mm², and after calibration, the threshold for the current batch is approximately 5.33 mm², offsetting the segmentation deviation caused by the decrease in grayscale.
[0120] After batch production is completed, the spatial distribution data of defects in this batch is statistically analyzed and subjected to grey relational analysis with three sets of process parameters: pouring temperature, cooling rate, and mold temperature. The results show that the correlation between pouring temperature and defect incidence rate is 0.82, cooling rate is 0.75, and mold temperature is 0.68. The correlation ranking indicates that pouring temperature has the greatest impact on defect incidence rate, and process recommendations for optimizing pouring temperature are output.
[0121] In the life prediction stage, the defect size, quantity, and operating parameters of a valve body are input, and the long short-term memory neural network outputs a base life value of 12,000 hours. The valve body has one crack defect with a stress concentration factor of 1.8. After correction, the remaining life is approximately 6,667 hours. The prediction result can be used as a reference for service maintenance.
[0122] For the rare defect type that appeared in this batch, a meta-learning approach was used for rapid adaptation. Using only 15 labeled samples and 4 steps of gradient updates, the recognition accuracy of this rare defect reached 88%, without the need to retrain the entire classification model.
[0123] In this embodiment, the batch-to-batch detection accuracy fluctuation is controlled within 0.8%, and the long-term operational stability is significantly improved. The process optimization suggestions can help reduce the defect rate of subsequent batches by about 10%, and the small sample defect adaptation cycle is shortened by more than 80%. This embodiment is suitable for long-term online inspection scenarios in large-volume, multi-model valve body casting production lines.
[0124] Example 4: This example is a further optimization based on Example 1, targeting high-precision inspection scenarios in complex casting environments. It focuses on constructing a cross-domain collaborative micro-roughness compensation mechanism to eliminate optical projection model bias and extend and enhance life prediction accuracy. All operations are automatically executed by a machine vision-based valve shell casting defect detection system.
[0125] The cooling rates in different regions of the valve housing exhibit physical differences, resulting in a non-uniform distribution of micro-roughness on the final formed valve housing surface. The shadow shape recovery algorithm forcibly assumes that the casting surface is an ideal Lambertian surface, meaning that the diffuse reflectance remains constant throughout the surface. In local areas with higher micro-roughness, incident light undergoes strong micro-facet scattering, causing the intensity of reflected light received by the industrial camera to be lower than the theoretical reflected light intensity of an ideal Lambertian surface. The photometric attenuation caused by roughness is incorrectly interpreted by the shadow shape recovery algorithm as an increase in physical depth, resulting in a systematic overestimation bias of depth. To eliminate this model bias at the physical level, this embodiment deeply couples the data interaction link between the preprocessing module and the quantization and grading module.
[0126] The first step is to extract and fuse the high-frequency signal spectrum. In the adaptive image preprocessing stage, the preprocessing module performs wavelet transform on the panoramic image of the valve body surface. The db4 wavelet is selected as the wavelet basis function, and standard five-level discrete wavelet decomposition is performed. Low-frequency subbands are used to reconstruct the main image information, and the horizontal, vertical, and diagonal high-frequency subband coefficients generated by the five-level decomposition are extracted simultaneously. The preprocessing module sums the absolute values of the high-frequency subband coefficients at each level and in each direction to generate a global high-frequency energy density map aligned with the resolution of the panoramic image of the valve body surface.
[0127] The second step is to quantify and characterize the microscopic physical roughness. For the extracted global high-frequency energy density map, the quantization and grading module uses a sliding window with a size of 7×7 pixels to traverse the defect region pixel by pixel. Within each sliding window, the algorithm independently calculates the statistical variance of all high-frequency energy density values within the window, and defines the obtained variance as the coordinate... Local energy variance at The intense fluctuations of high-frequency signals directly reflect the minute unevenness of the metal surface. The local energy variance constitutes the micro-roughness characterization coefficient of the corresponding defect region, enabling precise quantification of surface physical roughness through non-contact optical means.
[0128] The third step is to perform nonlinear photometric correction. The quantization and grading module reads the set roughness photometric sensitivity coefficient. For the ductile iron valve body material, after preliminary calibration in the darkroom of the optical laboratory, the roughness and photosensitive coefficient were determined. The value is kept constant at 0.45. Subsequently, the quantization grading module performs diffuse component correction on each pixel within the defect area. For example, if a small inclusion defect exists at coordinates (245, 310), the uncorrected original pixel grayscale at that coordinate will be... The value is 82. Based on the previous steps, the local energy variance of this coordinate is calculated. The value is 120. The system traverses the entire image to extract the maximum local energy variance. The value is 185. Substituting the above parameters into the reflectivity compensation function:
[0129]
[0130] After calculation, the pixel grayscale after diffuse reflection component correction The value was 61.23, and the system rounded the correction result to 61. Pixels that originally appeared as dark gray due to the extreme roughness of their microscopic surfaces were restored to their intrinsic gray levels, which are more consistent with the actual physical depth, after compensating for the scattering attenuation caused by the roughness.
[0131] The fourth step is to reconstruct the dual-source depth fusion link. The quantization and grading module uses the pixel grayscale matrix of all defect areas after diffuse reflection component correction, re-substitutes it into the shadow shape recovery algorithm, and outputs a shadow depth value that eliminates photometric deviation. Taking the above-mentioned inclusion defect as an example, without correction, the shadow depth value calculated by the traditional algorithm is 1.45 mm. After completing the diffuse reflection component correction, the recalculated shadow depth value is corrected to 1.12 mm. At the same time, the system reads the parallax depth value calculated by the parallax principle in parallel, which is 1.08 mm. The quantization and grading module continues to call the dual-source depth fusion formula for calculation. The contrast weight of this area is biased towards parallax calculation, and the final absolute depth value output by dual-source fusion is 1.09 mm. The absolute depth value output by dual-source fusion is highly consistent with the actual physical depth of 1.10 mm obtained by the coordinate measuring machine from the same valve body and the same defect point test, proving that this embodiment successfully eliminates the macroscopic quantization error caused by changes in the microstructure of the material in the traditional detection method.
[0132] Comparative verification was conducted using 1000 valve shells from continuous production, each containing various typical defects. The benchmark was the algorithm from Example 1 without micro-roughness compensation. Statistical processing of the verification data showed a significant improvement in the accuracy of shadow depth calculations for all types of defects. The average absolute error for porosity defects decreased from 0.18 mm to 0.05 mm, an improvement of 72.2%; the average absolute error for inclusion defects decreased from 0.22 mm to 0.07 mm, an improvement of 68.1%; the average absolute error for cold shut defects decreased from 0.15 mm to 0.04 mm, an improvement of 73.3%; and the average absolute error for microcrack defects decreased from 0.26 mm to 0.06 mm, an improvement of 76.9%. The average absolute error for depth measurement for all types of defects was compressed to within 0.08 mm. The most significant improvement in accuracy was observed after compensation for defect types with the most drastic changes in surface roughness gradient, such as microcracks.
[0133] The fifth step is to optimize the long short-term memory neural network based on micro-constraints. This embodiment not only uses micro-roughness for immediate spatial geometric correction but also deeply embeds it as a decay constraint variable in the time dimension into the long short-term memory neural network lifetime prediction model. The fatigue fracture theory of metallic materials shows that the micro-roughness valleys on the surface of castings are often natural sources of stress concentration, directly dominating the initiation and propagation rate of microcracks.
[0134] The process analysis module extracts the micro-roughness characterization coefficient matrix generated in the preceding steps, and extracts the maximum and arithmetic mean of micro-roughness for each independent defect region. The original model input features contain 8 dimensions; in this embodiment, the input feature sequence is expanded to 10 dimensions, with the two newly added dimensions corresponding to the maximum and arithmetic mean of micro-roughness, respectively.
[0135] When retraining the long short-term memory neural network life prediction model, the training set contained 15,000 valve shell fatigue bench data points equipped with high-precision life cycle test results. The model learning rate was set to 0.0005, and a dropout regularization strategy was used to prevent overfitting, with a dropout probability set to 0.25. After 150 iterations, the model's mean squared error loss function converged to 0.032.
[0136] In practical implementation, when a cold shut defect of the same depth but with an extremely rough bottom is detected, a high local energy variance is input into the neural network. The states of the input gate and the forget gate are modulated by a new roughness feature vector, and the weights of the hidden layers inside the neural network impose a strong downlink penalty on the lifetime output value. The original Example 1 model gave a remaining lifetime prediction of 8500 h, while the improved model in this example, combined with the severe stress concentration effect caused by extreme micro-roughness, outputs a corrected remaining lifetime prediction of 6100 h. This specific valve body was tested on a destructive accelerated fatigue test bench, and the valve body failed due to fatigue leakage after 6350 h of equivalent operation. The corrected prediction value and the physical failure time are significantly more consistent than the traditional prediction model that does not consider micro-roughness characteristics, demonstrating the technical superiority and industrial application value of establishing a link from frequency domain signal to physical lifetime prediction.
[0137] In some preferred embodiments, each camera is equipped with both bright-field and side-lit dual light sources to simultaneously acquire dual-illumination images, and the depth distribution is completed based on shadow shape recovery. The light source positions are precisely calibrated, and multiple images are acquired by switching between different angle light sources. These images are then combined with a photometric stereo vision algorithm to calculate pixel-level surface normal vectors, reconstructing a high-precision depth map. This multi-light source photometric stereo vision solution can further improve depth estimation accuracy to within 0.03 mm, making it suitable for high-pressure valve housing products with extremely high depth detection requirements.
[0138] In some preferred embodiments, the defect stress concentration factor is obtained using finite element simulation calibration. For different defect types and locations on different valve body models, the corresponding stress concentration factors are pre-calculated using finite element simulation to form a parameter library. During actual testing, the corresponding parameters are directly called, which can further improve the accuracy of life prediction correction by more than 20%.
[0139] In some preferred embodiments, the machine vision-based valve shell casting defect detection system supports rapid model changeover for multiple valve shell models. The system pre-stores 3D model parameters, camera calibration parameters, and grading threshold parameters for different valve shell models. During model changeover, only the corresponding product model needs to be selected, and the system automatically loads all parameters without recalibration. The changeover time is no more than 2 minutes.
[0140] In some preferred embodiments, the machine vision-based valve body casting defect detection system and the casting production line control system interact with each other via the Profinet industrial bus. The data frames contain information such as product number, defect level, and process suggestions, and the feedback cycle is no more than 100 ms, realizing online defect monitoring and quality traceability.
[0141] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0142] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. It should be noted that any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A machine vision-based method for detecting casting defects in valve bodies, characterized in that, Includes the following steps: Acquire original images of the valve shell surface simultaneously from multiple different perspectives, perform feature matching and transformation matrix estimation on the original images, stitch them together to generate a panoramic image of the valve shell surface, and simultaneously generate a mask matrix for the seam area. Using the seam area mask matrix as a parameter adjustment factor, the noise reduction threshold and contrast enhancement coefficient are adaptively adjusted pixel by pixel to preprocess the panoramic image of the valve shell surface. The depth features and multiple manual features of the preprocessed panoramic image are extracted, and the feature weights at different locations are corrected by combining the seam area mask matrix, and a weighted defect feature vector is generated by fusing them. The weighted defect feature vector is input into a multi-classifier, which outputs the defect type and the corresponding classification confidence. The feature weighting coefficient is adjusted in reverse according to the classification confidence to obtain the optimized defect feature vector and complete the final classification and recognition. The identified defect areas are located at the pixel level. The physical size parameters of the defects are calculated by combining dual-source depth estimation based on multi-view parallax and shadow features and valve shell surface projection correction. The physical size parameters are compared with the batch-calibrated evaluation criteria to output the defect level judgment result.
2. The method for detecting casting defects in valve bodies based on machine vision according to claim 1, characterized in that, The process of acquiring original images of the valve shell surface from multiple different perspectives is as follows: a multi-station industrial camera array is arranged in a ring around the circumference of the valve shell, covering the top, bottom and circumferential surfaces of the valve shell. The angle between the optical axes of adjacent cameras is no greater than 60° and the overlap rate of the field of view of adjacent cameras is no less than 20%. All cameras are controlled uniformly by a synchronous trigger controller, and the synchronization accuracy of the trigger signal is better than 100μs.
3. The method for detecting casting defects in valve bodies based on machine vision according to claim 1, characterized in that, The process of stitching together a panoramic image of the valve housing surface and simultaneously generating a seam area mask matrix involves: extracting scale-invariant feature transformation (SIN) points from each original image; estimating the homography transformation matrix between adjacent images using a random sampling consensus algorithm; projecting all original images onto a unified coordinate system based on the homography transformation matrix; performing fade-in / fade-out grayscale fusion on the overlapping areas to generate the panoramic image of the valve housing surface; marking the center line of the seam in the stitched overlapping areas; expanding the seam area by a preset pixel width along both sides of the center line to form the seam area; generating a binary seam area mask matrix, with pixels in the seam area marked as 1 and pixels in the non-seam area marked as 0.
4. The method for detecting casting defects in valve bodies based on machine vision according to claim 1, characterized in that, The preprocessing using the seam region mask matrix as a parameter adjustment factor specifically involves: employing a wavelet transform adaptive threshold denoising algorithm to suppress image noise. The wavelet denoising threshold is adjusted pixel-by-pixel by the seam region mask matrix, satisfying the following equation: in, Representing coordinates Wavelet denoising threshold corresponding to a pixel; The baseline noise reduction threshold for the non-seamless region; This represents the noise reduction threshold adjustment coefficient for the seam area; This indicates that the seam area mask matrix is located in coordinates. The value at the location; An adaptive histogram equalization algorithm is used to improve image contrast. The contrast enhancement coefficient is adjusted in reverse according to the same logic. The enhancement coefficient of the seam area is lower than that of the non-seam area to suppress the excessive amplification of gray-scale abrupt changes at the seam.
5. The method for detecting valve shell casting defects based on machine vision according to claim 1, characterized in that, The specific steps for correcting feature weights and fusing them to generate a weighted defect feature vector, based on the seam region mask matrix, are as follows: A deep convolutional neural network is used to extract 512-dimensional depth features from the image; 10-dimensional handcrafted features, including texture, shape, and geometric features, are extracted from the defect region; The depth features and the handcrafted features are concatenated to obtain an initial feature vector; The seam region mask matrix is used to attenuate and correct the weights of various features at different locations, with the attenuation magnitude for edge features being greater than that for texture features, reducing edge feature interference caused by splicing artifacts; The initial feature vector is then multiplied element-wise by the corresponding feature weight to generate a weighted defect feature vector.
6. The valve shell casting defect detection method based on machine vision according to claim 1, characterized in that, The specific method for adjusting the feature weighting coefficients based on the classification confidence is as follows: Obtain the classification confidence from the initial classification output. When the classification confidence is lower than a preset optimization threshold, update the feature weights based on the classification confidence and the discriminant coefficients of each feature category. The update formula satisfies the following equation: in, Indicates the updated number Class feature weights; Indicates the number before the update Class feature weights; The learning rate represents the confidence level feedback; This represents the classification confidence score of the current sample, with a value range of [value range missing]. ; Indicates the first The class discrimination coefficient of class features, with a value range of 100%. The weighted defect feature vector is recalculated using the updated feature weights, input into the multi-classifier to complete the secondary classification, and the final classification result is output.
7. The method for detecting casting defects in valve bodies based on machine vision according to claim 1, characterized in that, The multi-classifier employs a one-to-one voting multi-class support vector machine, with a total of 15 binary support vector machines. The kernel function is a radial basis function kernel. The classification confidence is calculated using a probability transformation method, and its value range is [value range missing]. ; When the classification confidence level is lower than the preset confidence threshold, the corresponding defect is marked as a suspected defect and sent for manual review; the labeled samples after manual review are stored in the sample library, and the multi-class support vector machine is incrementally trained periodically.
8. The method for detecting casting defects in valve bodies based on machine vision according to claim 1, characterized in that, After the final classification and recognition is completed but before pixel-level localization, a secondary verification step for pseudo-defects in the seam area is also included: extracting the principal gradient direction of the defect candidate area in the seam area and the local direction of the seam, and calculating the angle between them; when the angle is less than a preset angle threshold, the defect extension direction is consistent with the seam direction, and it is determined to be a splicing artifact, and the corresponding defect candidate area is marked as a pseudo-defect and removed.
9. The method for detecting casting defects in valve bodies based on machine vision according to claim 1, characterized in that, The valve housing surface projection correction is specifically as follows: the defect pixel coordinates are mapped to the surface of the standard 3D model of the valve housing, the surface normal vector at the location of the defect is obtained, and the angle between the surface normal vector and the camera optical axis is calculated; the defect size calculated by the planar projection is corrected according to the angle, the larger the angle, the higher the correction magnitude, and the true defect size on the valve housing surface is obtained.
10. A machine vision-based valve shell casting defect detection system, used to execute the machine vision-based valve shell casting defect detection method according to any one of claims 1-9, characterized in that, The system includes an image acquisition module, an image stitching module, a preprocessing module, a feature extraction module, a classification and recognition module, a quantization and grading module, and a data storage module. The image acquisition module simultaneously acquires multiple original images of the valve shell surface from different perspectives and outputs these original images to the image stitching module. The image stitching module receives the original images from the image acquisition module, generates a panoramic image of the valve shell surface through feature matching and transformation matrix estimation, simultaneously generates a seam area mask matrix, and outputs the panoramic image of the valve shell surface and the seam area mask matrix to the preprocessing module and the feature extraction module. The preprocessing module is used to receive the panoramic image of the valve body surface and the seam area mask matrix from the image stitching module, and adaptively adjust the denoising threshold and enhancement coefficient with the seam area mask matrix as the adjustment factor. After completing the preprocessing, the preprocessed image and local contrast data are output to the feature extraction module and the quantization and grading module. The feature extraction module receives the preprocessed image from the preprocessing module and the seam region mask matrix from the image stitching module, extracts multi-dimensional features, and combines the mask to correct feature weights, generating a weighted defect feature vector. The weighted defect feature vector is then output to the classification and recognition module. The classification and recognition module receives the weighted defect feature vector from the feature extraction module, outputs the defect type and classification confidence score, feeds the classification confidence score back to the feature extraction module to optimize feature weights, and outputs the classification result and defect location information to the quantization and grading module. The quantization and grading module receives the classification result and defect location information from the classification and recognition module, the preprocessed image from the preprocessing module, and contrast data. It performs defect pixel localization, dual-source depth estimation, surface size correction, and grade determination, outputting the final detection result. The data storage module receives and stores all process data and final result data generated by all modules.