Engine cylinder body and cylinder cover surface abnormal defect detection method based on traditional algorithm
Through the image processing method based on traditional algorithms, dense optical flow method and mixed Gaussian background modeling, combined with Sobel operator to extract gradient features, the first identification and interception of surface defects of the engine cylinder head is solved, and the accuracy and efficiency of detection are improved.
Patent Information
- Application Number
- CN202510689006.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-27
- Publication Date
- 2025-08-12
AI Technical Summary
The prior art cannot effectively identify and intercept abnormal defects on the surface of the engine cylinder head when the defect samples are lacking or first appearing, resulting in high leakage detection rate and low efficiency, and it is difficult to achieve high-precision detection especially under fluctuations in complex backgrounds and light conditions.
The detection method based on traditional algorithms is adopted, images with small mechanical displacement differences are selected as reference templates, image registration and mixed Gaussian background modeling are combined with dense optical flow method, gradient features are extracted using Sobel operator, and the final defect area is determined through cross-comparison, and the fusion area standard filters misjudgment.
The detection accuracy under complex background and lighting changes is improved, the misjudgment rate of false defects is reduced, the response ability to first appear is enhanced, and efficient defect identification and interception is achieved.
Smart Images

Figure CN120471903A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of appearance defect detection of engine parts, specifically a method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head using a traditional algorithm. Background Art
[0002] As a core component of the automotive powertrain, the machining quality of the cylinder block and cylinder head directly impacts the performance and lifespan of the entire engine. During manufacturing, abnormal surface defects (such as pores, cracks, scratches, and residue) on the cylinder block and cylinder head are critical quality control points. Traditional inspection methods rely primarily on manual visual inspection, but due to factors such as human subjectivity and fatigue, this method results in a high rate of missed inspections and low efficiency, making it unable to meet the demands of modern high-speed production lines.
[0003] With the development of industrial automation and machine vision, automatic detection of surface defects has gradually become a research and application hotspot. Currently, mainstream methods can be divided into two categories: one is based on traditional image processing algorithms, and the other is intelligent detection methods based on deep learning.
[0004] Traditional algorithms extract target area features through image filtering, edge extraction, morphological processing, and threshold segmentation, and are suitable for industrial scenarios with strong regularity and stable backgrounds. For example, in the inspection of some aluminum alloy cylinder bodies, the Sobel operator combined with background modeling enables coarse detection of defects such as pores and protrusions, achieving a high recognition rate under certain conditions. These methods offer the advantages of model transparency, low computational overhead, and the lack of a large number of sample training samples. They are particularly suitable for intercepting unknown defects that appear for the first time. However, they still lack robustness against complex backgrounds, reflective surfaces, and curved surfaces.
[0005] Another class of deep learning-based methods, such as those using convolutional neural networks (CNNs) for image classification and segmentation, offer excellent automatic feature extraction capabilities and strong generalization, demonstrating superior detection accuracy under large sample conditions. However, these methods often rely on a large number of labeled defect samples, require long training cycles, and often have poor recognition capabilities for new defects that appear for the first time, resulting in a high risk of missed detections.
[0006] Furthermore, in actual industrial production, interference factors such as fluctuating lighting conditions, complex surface curvatures, and image differences between multiple workstations further complicate detection. This is especially true when unknown defects first appear during production. Existing AI algorithms struggle to identify and intercept them in a timely manner, causing defective workpieces to flow into subsequent processes, increasing rework and scrap rates.
[0007] In summary, the existing technology has the problem of being unable to effectively identify and intercept abnormal defects when defect samples are lacking or appear for the first time. Summary of the Invention
[0008] To solve the problem in the prior art that abnormal defects cannot be effectively identified and intercepted when defect samples are lacking or appear for the first time, the technical solution provided by the present invention is as follows:
[0009] A method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm, comprising:
[0010] The step of collecting images of the cylinder block and cylinder head, and selecting an image that meets preset conditions as a reference template image;
[0011] A step of constructing a background model based on the reference template image;
[0012] Perform registration and mask area extraction on the image to be detected, obtain the target area image, remove noise from the target area image and smooth the image;
[0013] Based on the filtered image, extracting a first suspected defect area according to a preset threshold;
[0014] performing foreground detection on the filtered image based on the background model, and extracting an abnormal change area as a second suspected defect area;
[0015] The step of obtaining a final defect detection result based on the first suspected defect area and the second suspected defect.
[0016] Furthermore, a preferred embodiment is provided, wherein the image that meets the preset condition is an image with small mechanical displacement difference.
[0017] Furthermore, a preferred embodiment is provided, in which the dense optical flow method is used to register the good sample images, and the background model is constructed using the mixed Gaussian background modeling method.
[0018] Furthermore, a preferred embodiment is provided, in which Gaussian filtering is performed on the target area image to remove noise and smooth the image.
[0019] Furthermore, a preferred embodiment is provided, in which the gradients in the x-direction and the y-direction are calculated based on the filtered image to obtain a composite gradient image, and the first suspected defect area is extracted according to a preset threshold.
[0020] Furthermore, a preferred embodiment is provided, in which the first suspected defect area and the second suspected defect area are cross-compared, and the misjudgment area is filtered out based on a preset defect area standard to obtain a final defect detection result.
[0021] A device for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm is also provided, comprising:
[0022] A module that collects images of the cylinder block and cylinder head and selects images that meet preset conditions as reference template images;
[0023] A module for constructing a background model based on the reference template image;
[0024] A module that performs registration and mask area extraction on the image to be detected, obtains the target area image, removes noise from the target area image, and smoothes the image;
[0025] Based on the filtered image, extracting a module of the first suspected defect area according to a preset threshold;
[0026] A module for performing foreground detection on the filtered image based on the background model and extracting an abnormal change area as a second suspected defect area;
[0027] A module for obtaining a final defect detection result based on the first suspected defect area and the second suspected defect.
[0028] A computer storage medium is also provided for storing a computer program, and when the computer program is read by a computer, the computer executes the method.
[0029] A computer is also provided, comprising a processor and a storage medium, wherein when the processor reads a computer program stored in the storage medium, the computer executes the method.
[0030] A computer program product is also provided, which is a computer program that implements the method when the computer program is executed.
[0031] Compared with the prior art, the technical solution provided by the present invention is beneficial in that:
[0032] By selecting images with minimal mechanical displacement differences as reference templates during the image acquisition phase and creating a mask, the accuracy of subsequent image registration and defect detection can be effectively enhanced. In actual industrial applications, the numerous image locations and subtle differences in workpiece posture can easily lead to shifts in the inspection area. This solution shields non-target areas using a template reference and mask, improving the consistency of image registration and reducing the false defect detection rate. Compared to conventional methods that do not use a template reference, the overall detection accuracy is more stable.
[0033] By registering images using dense optical flow and combining it with mixed Gaussian background modeling to construct background models for different image locations, this method effectively distinguishes structural features from abnormal disturbances on the workpiece surface. Compared to some fixed-threshold background subtraction methods, the mixed Gaussian model exhibits greater dynamic adaptability, including the ability to accommodate changes in surface texture or illumination between batches. Even when new defect samples are unavailable, this method relies on the statistical variability of background modeling to initially identify suspected abnormal areas, improving its ability to respond to first-time defect detection.
[0034] Using Gaussian filtering for image preprocessing and smoothing after extracting the ROI from the masked area effectively removes high-frequency noise and enhances the coherence of image edge information. Compared to traditional processes that directly perform edge detection, this processing step significantly reduces the false alarm rate, especially in the presence of uneven grayscale, reflective, or particulate backgrounds. It also maintains image quality and provides clear input for subsequent gradient calculations.
[0035] The Sobel operator is introduced to extract gradients in the x and y directions and calculate the composite gradient. A threshold is used to identify areas of significant change as defects, effectively extracting edge features from localized abnormal areas. This processing method is highly adaptable to cylinder block and head surfaces with prominent edge structures and complex textures. Compared to feature extraction methods such as convolutional neural networks, which require extensive training, it is more suitable for immediate response to initial defects.
[0036] By cross-comparing foreground anomaly regions derived from background modeling with gradient feature results and filtering using overlapping area ratios and regional criteria, false positives can be accurately eliminated and true defect results can be output. Unlike traditional methods that rely solely on edge or brightness mutations to determine defects, this method combines two independent detection mechanisms and introduces an area judgment criterion, enhancing the system's ability to identify false positives and significantly improving the reliability and practicality of defect detection.
[0037] It is suitable for automatic detection and quality control of surface abnormal defects on engine cylinder block and cylinder head production lines. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 Flow chart of the method. DETAILED DESCRIPTION
[0039] In order to make the advantages and benefits of the technical solution provided by the present invention more clearly reflected, the technical solution provided by the present invention is now further described in detail with reference to the accompanying drawings, specifically:
[0040] Embodiment 1: This embodiment provides a method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm, including:
[0041] The step of collecting images of the cylinder block and cylinder head, and selecting an image that meets preset conditions as a reference template image;
[0042] A step of constructing a background model based on the reference template image;
[0043] Perform registration and mask area extraction on the image to be detected, obtain the target area image, remove noise from the target area image and smooth the image;
[0044] Based on the filtered image, extracting a first suspected defect area according to a preset threshold;
[0045] performing foreground detection on the filtered image based on the background model, and extracting an abnormal change area as a second suspected defect area;
[0046] The step of obtaining a final defect detection result based on the first suspected defect area and the second suspected defect.
[0047] The image that meets the preset conditions is an image with small mechanical displacement difference.
[0048] The dense optical flow method is used to align the good sample images, and the background model is constructed using the mixed Gaussian background modeling method.
[0049] The target area image is subjected to Gaussian filtering to remove noise and smooth the image.
[0050] The gradients in the x-direction and the y-direction are calculated based on the filtered image to obtain a composite gradient image, and the first suspected defect area is extracted according to a preset threshold.
[0051] The first suspected defect area is cross-compared with the second suspected defect area, and the misjudgment area is filtered out based on a preset defect area standard to obtain a final defect detection result.
[0052] Implementation Method 2: This implementation method further elaborates on the technical solution provided in Implementation Method 1. Specifically:
[0053] In order to accurately detect unknown abnormal defects that appear for the first time on the surface of the engine cylinder block and cylinder head, this embodiment provides:
[0054] Step 1: Image acquisition and reference template creation
[0055] First, an industrial camera is used to capture images of the engine block and cylinder head at multiple locations and angles to obtain surface feature images. For each image capture location, an image with minimal mechanical displacement variability and clear, stable imaging is selected as a reference template image. Through manual or automatic annotation, the machined surface area is identified, and a mask is created on the template image. This mask blocks non-inspected areas, retaining only the target area, which serves as the basis for extracting the ROI region in subsequent image processing.
[0056] Step 2: Background modeling and sample preparation
[0057] Based on the reference template and mask obtained in step 1, multiple images of qualified workpieces are collected that align with the template position. Dense optical flow is used to perform pixel-level registration of the sample images, ensuring that their structural position is consistent with the template image. Using the registered image data, a background model is established for each photo location using a mixture of Gaussian background modeling algorithm. During the background modeling process, multiple individual models are dynamically maintained by evaluating the distribution of each pixel across different images, including the weight, mean, and variance parameters for each individual model. The models are then sorted and filtered based on their importance, retaining only background model parameters that meet stability requirements.
[0058] Step 3: Detection image preprocessing
[0059] Image preprocessing is performed on the cylinder block and cylinder head images to be inspected. First, dense optical flow registration is performed on the inspection image based on a reference template to align it with the background model. A mask is then used to extract the ROI region. Within the extracted image region, convolution smoothing is performed using a Gaussian filter. The standard deviation of the Gaussian kernel is selected based on the image's noise intensity and detail preservation requirements to remove high-frequency noise while preserving key contour information, providing a clear input image for subsequent gradient calculation and foreground extraction.
[0060] Step 4: Gradient feature extraction and preliminary labeling
[0061] For the image smoothed in step 3, the Sobel operator is applied to calculate the image's gradient changes in the x and y directions. The resulting gradient amplitude is then calculated to represent edge regions with significant grayscale changes. By setting a gradient amplitude threshold, regions with significant changes are marked as potential defect areas. This operation effectively extracts information about sudden abnormal structures in the image and forms a preliminary distribution map of suspected defects.
[0062] Step 5: Model detection and foreground extraction
[0063] The preprocessed inspection image from step 3 is fed into the background model established in step 2. The Gaussian background difference method is used to determine whether each pixel belongs to the normal state within the background model. If the pixel value matches a Gaussian sub-model within the model, it is considered background; otherwise, it is considered foreground, forming a foreground mask. The model update mechanism dynamically adjusts the matching model parameters based on the new image input, while simultaneously eliminating sub-models with low weights and low frequency of occurrence. Finally, the suspected abnormal area is output as the defect to be determined.
[0064] Step 6: Cross-comparison and defect confirmation
[0065] The two suspected defect areas obtained in steps 4 and 5 are cross-compared. The overlapping area of the two detection result rectangles is calculated and divided by the union area of the two. When the overlap ratio exceeds a set threshold (e.g., 0.5), the two results are considered to match and are merged as the final suspected defect area. Next, based on the defect area criteria corresponding to different areas of the engine block and cylinder head, falsely detected areas that are too small or not within the judgment area are screened out, and the final defect location results and classification information are output.
[0066] Implementation method three: combining Figure 1 This embodiment further describes the above technical solution in detail through specific examples, specifically:
[0067] In the context of engine parts processing, machine vision inspection equipment using AI faces challenges with data loss, invalid data, or insufficient data. This makes it difficult to intercept unknown new defects that first appear on the production line. To ensure that machine vision inspection equipment meets production inspection requirements in industrial scenarios, we developed and tested an abnormal defect detection method to intercept new defects as they first appear.
[0068] To achieve the above-mentioned object, the present invention provides the following technical solution: a method for detecting abnormal defects on the surface of a cylinder block and cylinder head, comprising the following steps:
[0069] S1: Image acquisition: For different photo locations of the cylinder block and cylinder head workpiece, images with minimal mechanical displacement differences are selected as reference templates to create masks.
[0070] S2: Collect sample data, transform the sample image data according to the positioning template and dense optical flow method, and then use mixed Gaussian background modeling to calculate and construct background models for different shooting points;
[0071] S3: Image preprocessing: Based on the positioning template, the detection image is transformed using the dense optical flow method, the ROI is extracted using the mask, and then Gaussian filtering is applied and convolution is performed using the Gaussian kernel to smooth the image and reduce noise.
[0072] S4: Feature extraction: Use the Sobel operator to calculate the gradients in the x and y directions of the image processed in step 3, calculate the composite gradient, set a threshold, and mark the areas with obvious gradient features as defects to be determined;
[0073] S5: Model calculation, using the background model made in step 2, performs model detection on the detection image processed in step 3, and returns the result marked as a defect to be determined
[0074] S6: performing cross-ratio calculation on the defects to be determined in steps 4 and 5, filtering according to defect size and area standards at different locations on the cylinder block and cylinder head surface to obtain final defect data.
[0075] In the engine parts processing scenario, this technology enables interception of unknown new defects as they first appear on the production line. This addresses, to a certain extent, the challenges of industrial AI applications with limited data foundations and stringent performance requirements. Traditional visual algorithms do not require a large number of defect samples to learn from, thus avoiding the long sample collection cycle for visual AI inspection of product defects.
[0076] Specifically:
[0077] S1: Image acquisition: For different photo locations of the cylinder block and cylinder head workpiece, images with minimal mechanical displacement differences are selected as reference templates to create masks.
[0078] Specifically, when creating the reference mask, the processing surface area is determined by manually marking points, the calculation threshold is adjusted, and the image is converted into a binary image;
[0079] S2: Collect sample data, transform the sample image data according to the positioning template and dense optical flow method, and then use mixed Gaussian background modeling to calculate and construct background models for different shooting points;
[0080] Specifically: Use the positioning template and the same-point sample to select good workpiece images, and use the calcOpticalFlowFarneback function encapsulated in OpenCV to perform dense optical flow transformation as modeling learning data. Use the BackgroundSubtractorMOG2 encapsulated function to perform mixed Gaussian background modeling. The basic steps are as follows:
[0081] Definition of pixel:
[0082] Each pixel is described by multiple single models P(p) = {[w i (x,y,t),u i (x,y,t),σ i (x,y,t) 2 ]}, i=1,2,…, the value of KK is generally between 3 and 5, indicating the number of single models included in the mixed Gaussian model, w i (x,y,t) represents the weight of each model, satisfying:
[0083]
[0084] Three parameters (weight, mean, and variance) determine a single model.
[0085] Update parameters and perform foreground detection
[0086] Step 1:
[0087] If the pixel at (x, y) in the picture of the newly read video image sequence satisfies I(x, y, t)-u for i=1,2,…,K i (x,y,t)≤λ·σ i (x, y, t), i = 1, 2, ..., K, then the new pixel matches the single model. If there is a single model that matches the new pixel, the point is judged to be background and the process goes to Step 2; if there is no model that matches the new pixel, the point is judged to be foreground and the process goes to Step 3.
[0088] Step 2:
[0089] Correct the weight of the single model that matches the new pixel, and the weight increment is dw = α (1-w i (x,y,t-1)), the new weights are expressed as follows:
[0090] w i (x,y,t)=w i (x,y,t-1)+dw=w i (x,y,t-1)+α·(1-w i (x,y,t-1))
[0091] Correct the mean and variance of the single model that matches the new pixel, similar to the single Gaussian model. After completing Step 2, proceed directly to Step 4.
[0092] Step 3:
[0093] If the new pixel does not match any single model, then:
[0094] If the number of current single models has reached the maximum allowed number, the single model with the least importance in the current multi-model set is removed, and the importance is calculated in step 3).
[0095] Add a new single model with a smaller weight, a mean of the new pixel value, and a given larger variance.
[0096] Step 4: Weight normalization
[0097]
[0098] Sorting and pruning multiple single Gaussian models
[0099] The model of each pixel in the mixed Gaussian background model is composed of multiple single Gaussian models. In order to improve the efficiency of the algorithm, the single Gaussian models are sorted according to their importance, and the non-background models are deleted in time.
[0100] It is assumed that the background model has the following characteristics: large weight; high frequency of background occurrence; small variance; and little change in pixel values.
[0101] Based on this,
[0102]
[0103] As a basis for ranking by importance.
[0104] The sorting and deletion process is as follows:
[0105] Calculate the importance value sort_key of each single model;
[0106] Each single model is sorted according to its importance, with the more important ones being ranked first.
[0107] If the weights of the first N single models satisfy Only these N single models are used as background models, and other models are deleted. Generally, T = 0.7.
[0108] S3: Image preprocessing: Based on the positioning template, the detection image is transformed using the dense optical flow method, the ROI is extracted using the mask, and then Gaussian filtering is applied and convolution is performed using the Gaussian kernel to smooth the image and reduce noise.
[0109] Specifically: When selecting the standard deviation of the Gaussian filter, it should be determined based on the noise level and detail requirements of the image. Initial filtering is performed when the standard deviation is 1.0 to remove high-frequency noise. Then, the standard deviation is adjusted to 1.5 or higher as needed for refinement to achieve a balance between smoothing and detail preservation.
[0110] S4: Feature extraction: Use the Sobel operator to calculate the gradients in the x and y directions of the image processed in step 3, calculate the composite gradient, set a threshold, and mark the areas with obvious gradient features as defects to be determined;
[0111] Specifically: When using the Sobel operator to calculate the gradient, the convolution kernel size is selected to be 3x3 to maintain computational efficiency and accuracy of the results. The gradient magnitude of each pixel is calculated as the Euclidean norm of the gradient calculated by the Sobel operator in the x and y directions.
[0112] S5: Model calculation, using the background model made in step 2, performs model detection on the detection image processed in step 3, and returns the result marked as a defect to be determined
[0113] S6: performing cross-ratio calculation on the defects to be determined in steps 4 and 5, filtering according to defect size and area standards at different locations on the cylinder block and cylinder head surface to obtain final defect data.
[0114] Specifically: the overlapping area of the two detection result rectangles / (the sum of the two rectangles' areas - the overlapping area of the two detection result rectangles). When the overlap ratio is greater than 0.5, the two results are considered to overlap, and then the region template is used to determine whether to filter them.
[0115] The above further describes the technical solution provided by the present invention in detail through several specific embodiments in order to highlight the advantages and benefits of the technical solution provided by the present invention. However, the several specific embodiments described above are not intended to limit the present invention. Any reasonable modification and improvement of the present invention, combination of embodiments and equivalent replacement based on the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm, characterized in that: include: The step of collecting images of the cylinder block and cylinder head, and selecting an image that meets preset conditions as a reference template image; A step of constructing a background model based on the reference template image; Perform registration and mask area extraction on the image to be detected, obtain the target area image, remove noise from the target area image and smooth the image; Based on the filtered image, extracting a first suspected defect area according to a preset threshold; performing foreground detection on the filtered image based on the background model, and extracting an abnormal change area as a second suspected defect area; The step of obtaining a final defect detection result based on the first suspected defect area and the second suspected defect.
2. The method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm according to claim 1, characterized in that: The image that meets the preset conditions is an image with small mechanical displacement difference.
3. The method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm according to claim 1, characterized in that: The dense optical flow method is used to align the good sample images, and the background model is constructed using the mixed Gaussian background modeling method.
4. The method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm according to claim 1, characterized in that: The target area image is subjected to Gaussian filtering to remove noise and smooth the image.
5. The method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm according to claim 1, characterized in that: The gradients in the x-direction and the y-direction are calculated based on the filtered image to obtain a composite gradient image, and the first suspected defect area is extracted according to a preset threshold.
6. The method for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm according to claim 1, characterized in that: The first suspected defect area is cross-compared with the second suspected defect area, and the misjudgment area is filtered out based on a preset defect area standard to obtain a final defect detection result.
7. A device for detecting abnormal defects on the surface of an engine cylinder block and cylinder head based on a traditional algorithm, characterized in that: include: A module that collects images of the cylinder block and cylinder head and selects images that meet preset conditions as reference template images; A module for constructing a background model based on the reference template image; A module that performs registration and mask area extraction on the image to be detected, obtains the target area image, removes noise from the target area image, and smoothes the image; Based on the filtered image, extracting a module of the first suspected defect area according to a preset threshold; A module for performing foreground detection on the filtered image based on the background model and extracting an abnormal change area as a second suspected defect area; A module for obtaining a final defect detection result based on the first suspected defect area and the second suspected defect.
8. A computer storage medium for storing a computer program, characterized in that When the computer program is read by a computer, the computer executes the method according to claim 1 .
9. A computer comprising a processor and a storage medium, characterized in that When the processor reads the computer program stored in the storage medium, the computer executes the method according to claim 1 .
10. A computer program product, being a computer program, characterized in that When the computer program is executed, the method according to claim 1 is implemented.
Citation Information
Patent Citations
Real-time weld defect detection method based on improved background difference method
CN106770318A
Defect detection method, defect detection equipment and storage medium
CN117392042A
Automobile sheet metal part crack detection method
CN118967604A
Motorcycle shell high-pressure casting mold defect detection system and method
CN119985172A
Cited By
Defect detection method and device for battery tab, electronic equipment and storage medium
CN121616563A