A pin forging quality detection method and system
By improving the active contour model, using local gradient direction dispersion and defect edge structure enhancement indicators to generate adaptive external energy scaling factors, the problem that traditional Snakes algorithm is difficult to distinguish real defects from background textures on the surface of pin forgings, and achieving higher precision defect detection.
Patent Information
- Application Number
- CN202510813252.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-18
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2045-06-18
AI Technical Summary
The traditional Snakes algorithm is difficult to effectively distinguish the true defect edges and background textures of the surface of the distribution shaft forging, resulting in insufficient accuracy and robustness of defect detection in complex backgrounds, especially poor identification of tiny defects.
By calculating the local gradient direction dispersion and defect edge structure enhancement indicators, adaptive external energy scaling adjustment factors are generated, the active contour model is improved, the ability to identify weak and irregular defect edges is enhanced, and the interference of background texture and noise is suppressed.
It significantly improves the accuracy and robustness of surface defect detection of pin shaft forgings, can accurately identify small defects in complex backgrounds, reduce noise interference, and improves detection accuracy and adaptability.
Smart Images

Figure CN120339278B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a pin forging quality detection method and system. Background Art
[0002] Pins, a key connecting and load-bearing component widely used in mechanical equipment, primarily function to achieve rotational connection between mechanisms, transmit torque, and withstand shear and bending stresses. To meet stringent service conditions, pins are typically made from high-quality alloy steel and forged to achieve their initial blank shape. Forging eliminates the metal's as-cast porosity, welds internal pores, and breaks up coarse as-cast structures, forming a dense, fibrous structure with a specific streamline distribution. This significantly improves the material's mechanical properties, such as strength, toughness, fatigue strength, and wear resistance. Therefore, forging is a key step in ensuring the pin's ultimate performance.
[0003] In response to this, automated surface defect detection technology using machine vision has emerged and has become a hot topic in research and application. Among numerous image processing algorithms, active contour models (Snakes) have shown promise in object segmentation and defect extraction due to their ability to adaptively evolve contours based on image content to approximate target boundaries. However, traditional Snakes algorithms still suffer from inherent flaws: their external energy term primarily depends on the global or local gradient amplitude of the image. For pin forgings, their surfaces are often not uniformly smooth but may contain natural textures and scale patches formed by metal flow and oxidation. These non-defective feature areas may also produce strong gradient responses. Furthermore, some small but critical defects (such as early cracks and fine scratches) may generate relatively weak gradient signals due to their inherent low contrast or blurred edges.
[0004] In this case, the external energy term of the traditional Snakes model is difficult to effectively distinguish the real defect edges from the pseudo edges generated by background texture / noise, resulting in the contour line evolving: the energy weight parameters in the model usually need to be adjusted a lot empirically according to the specific scenario and defect type, which makes it difficult to stably cope with the diversity of forging surface conditions and defect morphologies. Summary of the Invention
[0005] In response to the above-mentioned problem of difficulty in stably dealing with the diversity of forging surface conditions and defect morphologies, in the first aspect, the present invention proposes a pin forging quality inspection method, comprising: obtaining a surface image of the pin forging to be inspected; determining the total energy function of the active contour model, wherein the total energy function includes an internal energy term and an external energy term; determining a pixel neighborhood window, and obtaining a structure tensor based on the gradient amplitude of each pixel in the pixel neighborhood window, and then calculating the local gradient direction discreteness of each pixel point; calculating the defect edge structure enhancement index of each pixel point based on the spatial distribution and local morphological characteristics of the local gradient direction discreteness; setting the minimum and maximum values of the adaptive external energy scaling adjustment factor and calculating the minimum value The method comprises the following steps: taking the defect edge structure enhancement index as the independent variable of a preset nonlinear mapping function to obtain a mapping value, calculating the product of the mapping value and the difference and summing it with the minimum value to obtain an adaptive external energy scaling adjustment factor; taking the adaptive external energy scaling adjustment factor as a multiplicative weight, directly acting on the basic external energy term in the total energy function of the active contour model, obtaining an improved total energy function, and thus obtaining an improved active contour model; adopting the improved active contour model to perform contour segmentation and extraction on the potential defects in the surface image; performing feature extraction and quantification on the segmented defect area, and judging the processing and forming quality of the pin forging based on a preset quality acceptance standard.
[0006] Compared with the traditional active contour model that only relies on image gradient information for defect segmentation, the present invention improves the active contour model by enhancing the local gradient direction discreteness and defect edge structure index, and generating an adaptive external energy scaling adjustment factor. It can significantly enhance the model's recognition ability and segmentation accuracy for weak and irregular defect edges under the complex background of the forging surface, effectively suppress the interference of background texture and noise, and improve the accuracy of defect detection and the robustness to different forging surface conditions.
[0007] Furthermore, the local gradient direction discreteness is recorded as , the calculation method is as follows: for pixel points and its neighborhood window , the set of valid gradient vectors whose gradient amplitude in the statistical window is greater than the preset threshold ;like Number of vectors If the number of valid gradients is less than the minimum set, the local gradient direction discreteness is set to 0; otherwise, Each valid gradient vector in Normalized to get the direction vector ,have , and construct the structure tensor ;calculate The two eigenvalues of and ,but ,in To avoid small positive numbers with zero denominator.
[0008] The degree of discreteness of the local gradient direction is quantified by the eigenvalue of the structure tensor. Compared with simple gradient statistics, this indicator can more robustly reflect the true inconsistency of the local image structure direction caused by defects, providing a more reliable underlying feature foundation for the subsequent accurate enhancement of defect edges.
[0009] Furthermore, the calculation method of the defect edge structure enhancement index is specifically as follows: ;in Represents pixel points Defect edge structure enhancement index; Represents the local gradient direction discreteness; Indicates a point In this setting Direction line segment The average of the values; and They represent the maximum value function and the minimum value function respectively.
[0010] Furthermore, the calculation method of the adaptive external energy scaling adjustment factor is specifically as follows:
[0011] ;
[0012] in and Respectively represent the minimum and maximum values of the set scaling factor; Represents pixel points Defect edge structure enhancement index; is a nonlinear mapping function whose parameters include the lower threshold used to calibrate the mapping interval , upper threshold and an exponent that controls the shape of the curve .
[0013] By nonlinearly mapping the defect edge structure enhancement index to a preset scaling factor range, the adjustment factor can change smoothly and adaptively according to the size of the defect edge structure enhancement index (i.e., the degree of significance of the defect edge). Compared with a fixed external energy weight or simple linear adjustment, it can more finely control the intensity of the influence of external energy on the active contour evolution, thereby improving the model's adaptability to defect edges of different intensities.
[0014] Furthermore, the nonlinear mapping function includes a Sigmoid function or at least one of the following piecewise functions, specifically:
[0015] ;
[0016] in represents a reference symbol used to refer to the defect edge structure enhancement index.
[0017] A specific, parameterized nonlinear mapping function implementation method is provided, so that the generation of the adaptive adjustment factor has a clear mathematical expression and adjustable response characteristics, which facilitates the optimal configuration of different sensitive intervals of defect edge significance according to actual application scenarios, enhancing the flexibility and practicality of the algorithm.
[0018] Furthermore, the improved energy function is specifically defined as:
[0019] ;
[0020] in Represents the improved energy function definition expression; , represents the parameterized contour curve; Represents internal energy, ,in and is the set weight; Indicates at the contour point The adaptive external energy scaling adjustment factor calculated at the location; is a basic external energy term, constructed based on the image gradient amplitude, ,in is the Gaussian smoothing kernel, is the set gradient energy weight constant.
[0021] The spatially adaptive scaling adjustment factor is multiplicatively applied to the basic external energy term, so that the active contour model can dynamically adjust its sensitivity to image gradients according to the defect edge confidence of each contour point during iterative solution. Compared with traditional models, this greatly enhances the driving force of the contour to converge to the real and significant defect edge, while effectively avoiding erroneous attraction in complex background or noisy areas.
[0022] Furthermore, before obtaining the surface image of the pin forging to be inspected, it also includes: cleaning, cooling and precisely positioning the surface of the pin forging to be inspected; using at least one industrial camera in combination with a telecentric lens and a programmable combined light source system to capture images of the surface to be inspected of the pin forging under multi-angle or multi-mode lighting, and performing necessary camera calibration and light field calibration.
[0023] Furthermore, the method further includes preprocessing the surface image: gray-scaling the surface image; processing the gray-scaling image using adaptive histogram equalization; and performing median filtering to denoise the gray-scaling image.
[0024] Furthermore, after using the improved active contour model to perform contour segmentation and extraction on potential defects in the surface image, the method also includes: automatically calculating the geometric feature parameters of each segmented defect area, wherein the geometric feature parameters include at least the area, perimeter, equivalent diameter, length and width of the minimum circumscribed rectangle, main axis direction angle, elongation, and circularity; and calculating its grayscale feature parameters, wherein the grayscale feature parameters include at least the average grayscale in the area, the grayscale standard deviation, and the average contrast with the adjacent background area.
[0025] In a second aspect, the present invention provides a pin forging quality inspection system, comprising a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, a pin forging quality inspection method of the present invention is implemented.
[0026] The technical effects of the present invention are:
[0027] The local gradient direction dispersion analyzes the statistical properties of the gradient direction in a pixel neighborhood to initially identify discontinuous regions in the image structure. Based on this, the defect edge structure enhancement index further examines the linear structural characteristics of high-value signals in these regions, thereby specifically enhancing the saliency of true defect edges and effectively suppressing interference from background texture and isolated noise points.
[0028] Based on the defect edge structure enhancement index, the present invention derives a spatially adaptive external energy scaling adjustment factor. This factor dynamically adjusts the weight of the external energy term in the traditional active contour model based on the likelihood that each pixel belongs to a true defect edge structure. In areas where the defect edge structure enhancement index indicates a strong defect signal, the external energy scaling adjustment factor significantly enhances the attraction of external energy; conversely, it weakens the effect. This decision support enables the improved active contour model to intelligently focus on high-confidence defect edges, thereby achieving more accurate defect contour localization in complex backgrounds. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 is a flow chart schematically illustrating a method for inspecting the quality of a pin forging according to an embodiment of the present invention;
[0030] Figure 2 The figure schematically shows a structural block diagram of a pin forging quality inspection system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0031] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work shall fall within the scope of protection of the present invention.
[0032] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
[0033] A pin forging quality inspection method embodiment:
[0034] like Figure 1 As shown, a pin forging quality inspection method of the present invention includes:
[0035] S1. Preparation and image acquisition of pin forgings.
[0036] First, the pin forging to be inspected is cleaned, for example, by using ultrasonic cleaning with an environmentally friendly industrial cleaning agent to remove oil and emulsion residues on the surface, and then blown dry with compressed air. Then, ensure that the forging has cooled naturally to a stable ambient temperature (for example, controlled at ) to eliminate the effects of thermal deformation on inspection accuracy. Furthermore, the cleaned and cooled forging is clamped on a rotatable workbench using a high-precision pneumatic three-jaw chuck. Finally, in this embodiment, a camera array is used consisting of four high-resolution (e.g., each camera has 2448×2048 effective pixels) global shutter industrial CMOS cameras. Each camera is equipped with a high-quality telecentric lens and a programmable combined light source system consisting of multiple groups of independently controllable high-brightness white light LED units (e.g., including a coaxial light source, a low-angle ring light source, and a dome diffuse light source, which can switch or combine lighting modes according to inspection requirements).
[0037] Prior to testing, the image acquisition equipment must be precisely calibrated. For example, for a two-dimensional camera array, each camera's intrinsic parameters (such as focal length, principal point, and distortion coefficient) and extrinsic parameters (the camera's position and orientation relative to the rotary table coordinate system) are calibrated separately. Furthermore, the programmable combined light source system undergoes light field uniformity calibration and light intensity response calibration in multi-light source mode.
[0038] After completing the above steps, image data of the pin forging is next collected. During the forging's rotation (or after stepping through multiple preset angles), a central controller synchronously triggers one or more cameras in the two-dimensional camera array to capture the image. After acquiring the camera image, the color image is first converted into a single-channel grayscale image. Subsequently, to mitigate the effects of uneven illumination, adaptive histogram equalization is applied to the grayscale image. Finally, a median filter is applied for denoising to smooth random noise and preserve edge detail. The aforementioned preprocessing algorithms are well-known and will not be detailed here.
[0039] S2. Determine the total energy function of the active contour model.
[0040] Pin forgings are formed under high temperature and high pressure, and their surfaces will inevitably develop complex characteristics that are different from the ideal machined surface. For example, there may be fine flow lines formed by uneven metal flow, surface oxide scale patches or color differences caused by oxidation and decarburization, etc.
[0041] The active contour model (Snakes) algorithm, as a classic image segmentation tool, is driven by the gradient information of the image and the total energy function. Usually expressed as:
[0042] ;
[0043] in , represents the internal energy, which is used to constrain the geometry of the contour, where the first term (given by the weight control) penalizes the stretching of the contour, making it tend to shorten; the second term (by weight Control) penalizes the curvature of the contour, making it tend to be smooth; Indicates that the contour points follow the parameters The coordinate position of the change.
[0044] Represents image energy or external energy, which comes from the characteristic information of the image itself and is used to guide the contour to move towards the target features of interest in the image (such as high gradient edges, specific grayscale areas, etc.). It is often set to be negatively correlated with the square of the image gradient magnitude, that is, ,in represents the edge weight; Indicates the image coordinate position gradient.
[0045] Represents external constraint energy, allowing implementers or high-level semantic information to impose additional guidance or constraints on the contour. The algorithm's solution process is to find a contour Make Minimum. The weight parameter that controls the internal and external energy balance in the Snakes algorithm (such as and external energy weights) are crucial to the segmentation results, but the optimization of these parameters often relies on experience, and it is difficult to find a universal parameter set that can adapt to different types of defects, different surface conditions and different lighting conditions.
[0046] S3. Determine the neighborhood window and obtain the structure tensor based on the gradient amplitude within the neighborhood window, and further calculate the local gradient direction discreteness; construct and calculate the defect edge structure enhancement index; calculate the adaptive external energy scaling adjustment factor based on the defect edge structure enhancement index; define the energy function and iterative solution strategy of the improved active contour model.
[0047] S3.1. Determine a neighborhood window, obtain a structure tensor based on the gradient amplitude within the neighborhood window, and further calculate the local gradient direction discreteness.
[0048] Even if there are forging textures on the surface of the pin forging due to metal flow, the texture direction of the normal area usually shows a certain direction dominance or smooth transition within a small local range (for example, a few pixels to a dozen pixels). In contrast, the appearance of defects (especially fine cracks, sharp edges of early folding, or boundaries of irregular pits) will suddenly interrupt this local direction continuity, causing the pixel gradient direction of the defect edge and its adjacent area to show a significant, concentrated, and multi-directional discrete distribution. Therefore, in this embodiment, the local gradient direction dispersion is constructed. , which aims to quantitatively describe each pixel in the image The degree of chaos or divergence of the gradient direction in its neighborhood is used as a preliminary basis for screening candidate areas of potential defects. The higher the value, the more inconsistent the microstructural direction within the region is, and the more likely it is that a structural mutation occurs.
[0049] For the two-dimensional grayscale image obtained in step S2, any pixel in it is preprocessed (for example, slight Gaussian smoothing to suppress random noise but retain edge details). , in its size (For example, or pixels) neighborhood window Inside, Preferably, the calculation is performed as follows:
[0050] First, the window Every pixel within , calculate its gradient vector For example, the Sobel operator or the Scharr operator can be used; then a gradient amplitude threshold is set (For example, it can be set to 0.25 times the mean of the global gradient magnitude of the image, or dynamically determined on the gradient magnitude map by, for example, the Otsu method) to filter out weak gradients caused by noise in flat areas. Only those gradient magnitudes are considered. Greater than The effective gradient vector of , the set of these vectors is recorded as , the number of which is ; Further if (For example , that is, the number of effective gradients is too small), then Otherwise, Each valid gradient vector in , calculate its normalized direction vector ; Then construct the structure tensor (Structure Tensor) or second-order moment matrix of these direction vectors ,have:
[0051] ;
[0052] in , represents the normalized gradient direction vector; based on the above matrix calculation matrix The two eigenvalues of and ( ). Finally, the local gradient direction discreteness is calculated have:
[0053] ;
[0054] in is a small positive number, such as 1e-6, to avoid zero denominator.
[0055] reflects the energy (or consistency strength) of the gradient in the main direction, and reflects the energy (or inconsistency strength) in the direction orthogonal to the main direction. When the gradient direction within is highly consistent (for example, along a clear straight edge), Larger, and Very small, at this time The value of approaches 0. When the gradient direction in the neighborhood is completely random or isotropically distributed (for example, at an ideal corner point or isotropic texture center), ,at this time The value of approaches 1. When there are significant gradients in multiple directions in the neighborhood (for example, in the center of complex cross-textures or certain defects such as star-shaped cracks), Relatively large, Also larger but probably not overwhelming, It will take an intermediate value, but significantly greater than 0.
[0056] therefore, The higher the value, the better the pixel The more divergent the gradient direction within a neighborhood, the less uniform it is. For forging surfaces, defects (such as crack endpoints, bifurcations, or the edges of irregular pits) usually lead to significant dispersion of the local gradient direction.
[0057] In one embodiment, for a forging surface image containing fine network cracks, its corresponding Atlas (i.e. each pixel point The image composed of the values of the crack network itself and its intersection nodes shows, for example, a high values (for example, after normalization to the range [0,1], the values in these areas may be between 0.6-0.9); while in the relatively flat or uniform texture areas between cracks, The value is lower (for example, less than 0.2).
[0058] S3.2. Construction and calculation of defect edge structure enhancement index.
[0059] Although the atlas can preliminarily identify areas of inconsistent structural orientation in the image, these areas may contain both real defect edges and some rough textures inherent in the forging surface (for example, the edges of oxide scale patches or non-defective micro-undulations formed by material flow) as well as some image noise.
[0060] Real defect edges, especially linear defects (such as cracks, scratches, fold lines, etc.), have high In addition, these high The value usually forms a ridge or band distribution with a certain spatial continuity and directionality along the direction of the defect. Therefore, in this embodiment, the defect edge structure enhancement index is further constructed. , aims to analyze The local linear structural features of the high-value areas in the spectrum are used to specifically enhance the signals that are more likely to correspond to the edges of real defects, while suppressing isolated, non-structural high-value areas. Noise point.
[0061] For pixels and its corresponding value, and by all Image of values , Preferably, the calculation is performed as follows:
[0062] First of all, The image is enhanced by applying a multi-directional linear structure filter. For example, a series of predefined directions can be used. (For example, a direction is taken every 22.5°, a total of 8 directions) linear structure elements (for example, a length of pixels, 1 or 3 pixels wide, where 7 or 9) can be used to perform a morphological opening-closing joint operation (Opening-by-Reconstruction followed by Closing-by-Reconstruction, or a simplified line segment detection filter) or directly perform multi-directional linear filtering (such as mean or Gaussian weighting).
[0063] In one embodiment, an enhanced method based on the eigenvalues of the Hessian matrix can be used to detect Ridge structure in the image, such as variants of the Steger or Frangi vessel enhancement algorithms.
[0064] In another embodiment, for each direction , calculation point In this direction, the line segment (length ,by Centered on Average of the values , calculated for:
[0065] ;
[0066] The meaning of this formula is that, using the original The value is multiplied by its neighborhood along different directions The maximum difference in means. If a point is located On the ridge line formed by high values, the mean value along the ridge direction will be higher, while the mean value perpendicular to the ridge direction will be lower, and the difference between the two is large.
[0067] If the pixel of The value is high, and its neighborhood is high The distribution of values shows obvious linear extension along a certain direction (i.e. is larger, and the difference from the mean in other directions is also larger), then will be significantly enhanced. This shows that It is likely to be located at the edge of a well-defined, directional defect (such as the main body of a crack).
[0068] If the pixel of Although the value is high, the surrounding If the distribution is more diffuse and lacks obvious directionality (for example, an isolated noise point or a small isotropic rough area), then the The value difference is not large, resulting in Relative to The enhancement is not obvious and may even be suppressed due to the small multiplicative factor.
[0069] therefore, Able to more efficiently The structural signals with continuous linear or curved shapes, which are more likely to be real defect edges, are purified and enhanced from the background.
[0070] Exemplary explanation: For the forging surface that previously contained fine network cracks, the corresponding The graph will show: the “linear” part of the crack network The value is greatly increased and becomes very prominent (for example, if Normalized, its value may be in the range of 1.5-2.5), while before There may be some diffuse highlight areas in the atlas caused by small surface bumps. The value will be significantly weakened in the spectrum (for example, the value drops below 0.5).
[0071] S3.3. Calculate the adaptive external energy scaling adjustment factor based on the defect edge structure enhancement index.
[0072] The weight of the external energy term in traditional active contour models is usually fixed globally or adjusted only once based on global image statistics. However, the complexity of forging surfaces and the diversity of defects require that the application of external energy should be more discriminative and adaptive.
[0073] Provides information about each pixel The quantitative information of the possibility (or significance) of belonging to the real defect edge structure. Therefore, the present invention constructs an adaptive external energy scaling adjustment factor , aiming to utilize The value of is used to finely and dynamically adjust the strength of the external energy term applied to the active contour on a pixel-by-pixel basis.
[0074] Its main purpose is to: The value indicates the area with strong defect edge signal, which significantly enhances the attraction of external energy and ensures that the contour can be accurately captured by these high-confidence edges; Regions with lower values (which may be normal surface textures or noise) will reduce the influence of external energy accordingly, preventing the contour from being misled by artifacts or stagnating prematurely at weak edges.
[0075] For pixels and its corresponding defect edge structure enhancement index value, Preferably through a nonlinear mapping function To calculate:
[0076] ;
[0077] in Indicates the minimum value of the adaptive external energy scaling adjustment factor, which can be set to an empirical value of 0.1 in this embodiment to ensure that even in In extremely low areas, external energy still has a weak effect; Indicates the maximum value of the adaptive external energy scaling adjustment factor. In this embodiment, it can be set to an empirical value of 2.0, which determines the maximum enhancement multiple of the external energy; and Respectively represent the lower threshold and upper threshold of the segmented mapping function. In this embodiment Can be set to The 10th percentile of all non-zero values in the spectrum, Can be set to The 90th percentile of all non-zero values in the spectrum; represents the exponent of the piecewise mapping function, which is used to control the shape of the curve, and ; Exemplarily, it can be an S-type function (such as a Sigmoid function or a piecewise cubic Hermite interpolation function) or a piecewise function with a threshold, which converts the input The values are smoothly mapped to interval.
[0078] In one embodiment:
[0079] ;
[0080] in Indicates a reference symbol to replace the above The calculation formula In another embodiment, a Sigmoid function is used, where:
[0081] ;
[0082] in Represents the midpoint parameter of the Sigmoid function, which corresponds to Input when output is 0.5 value; Represents the shape parameter of the Sigmoid function, which is used to control the steepness of the transition band.
[0083] When the pixel of A lower value (e.g., below ), it indicates that the point is unlikely to belong to a defect edge with a clear structure. The output is close to 0, making The value is close to its lower limit This means that in such regions, the external image energy applied to the active contour will be greatly weakened, and the contour evolution will be more dominated by its internal smoothness constraint, or more easily dominated by adjacent, higher-resolution active contours. are attracted by the area of values.
[0084] when Higher values (for example, higher than ), it indicates that the point is very likely to be located on the edge of a significant, structural defect. The output is close to 1, making The value is close to its upper limit This means that in such areas, the attraction of external image energy will be significantly enhanced, thereby strongly guiding the active contour to converge and fit closely to these high-confidence defect edges. and between value, Will be in and Smooth transition between.
[0085] therefore, The factor enables the active contour model to focus highly on those The indicator identifies the most structurally significant potential defect edges while effectively ignoring interference from background textures and random noise.
[0086] For example: For the previous The crack network part that is significantly enhanced in the atlas corresponds to The value will be raised to approximately (e.g. 2.0), which makes these crack edges have a strong attraction to the active contour. The background area with lower value The value remains close to (e.g. 0.1), the contribution of external energy is effectively suppressed.
[0087] S3.4. Energy function definition and iterative solution strategy of the improved active contour model.
[0088] Based on the above analysis and the constructed adaptive adjustment factor, the total energy function of the improved active contour model (IACM) of this embodiment is Preferably defined as:
[0089] ;
[0090] in It is still a parameterized contour curve; Still represents internal energy, In this embodiment, Set the experience value to 0.2, Set the experience value to 0.4; That is, at the contour point The adaptive external energy scaling adjustment factor calculated at the location; As a basic external energy term, for example, it can still be constructed based on the image gradient magnitude, or (in is the Gaussian smoothing kernel, is a basic gradient energy weight constant, such as 1.0. The basic external energy term is now subject to spatial variation. Direct modulation of the factor.
[0091] Furthermore, in order to solve Minimized outline In this embodiment, an iterative optimization strategy based on gradient descent is preferably adopted. The evolution equation of the contour can be expressed as:
[0092] ;
[0093] In specific implementation, the contour can be discretized into a series of control points , and then the contour is deformed by iteratively updating the position of each control point. In each iteration, each control point It will be affected by internal energy (making the distance between adjacent points uniform and the curve smooth) and Modulated external energy (pushing it to The valley of high gradient, high The iterative process continues until the contour energy change is less than a preset threshold, the contour morphology change tends to be stable, or the preset maximum number of iterations (for example, 300) is reached.
[0094] S4. Accurately segment and extract defects based on the improved active contour model; inspect the quality of pin forgings based on the extracted features.
[0095] After constructing the improved active contour model with adaptive external energy regulation mechanism, this step details its specific application in the segmentation of surface defects of pin forgings.
[0096] In order to improve the efficiency and accuracy of segmentation, the placement of the initial contour is preferably automated. For example, the defect edge structure enhancement index map generated in S3.2 is first (by all value composition) to perform threshold processing (for example, using Otsu method or preset empirical threshold, selecting The algorithm then identifies areas with high values (e.g., areas with high values) and performs a simple connected component analysis. For each connected component with an area greater than a certain threshold (e.g., 20 pixels), it calculates its bounding rectangle or minimum enclosing circle and uses this as the initial contour for evolving the improved active contour model. This approach concentrates computing resources on areas most likely to contain defects.
[0097] Each initial contour generated in step S3.1 is then placed into the improved active contour model defined in step S3.4. Under the guidance of the adaptive external energy field of information, each initial contour begins to evolve iteratively. Factor, the contours will be prioritized by those with high It is attracted by the edge of the defect with clear structure and can effectively resist the defect from low interference from high-value areas (such as background textures).
[0098] Next, the final defect area is extracted and identified. When all active contours have reached convergence, the resulting closed curves accurately outline the boundaries of each detected surface defect. Furthermore, the pixel areas enclosed by these closed contours are identified and extracted as individual defect targets. Each defect target is assigned a unique ID, and its precise coordinates and contour point set in the original image are recorded.
[0099] As an example, after this step, for an image region captured at S1 containing a microcrack approximately 3 mm long and 0.05 mm wide, and two pits approximately 0.3 mm in diameter, the improved active contour model can accurately segment the complete contour of the crack (even though some sections have low contrast) and the clear boundaries of the two pits, without mistakenly including surrounding normal forging flow lines or slight oxide scale patches. The output is a sequence of contour point coordinates for each defect and a binary mask image.
[0100] Based on the successful segmentation of each defect area in the above steps, this step quantitatively describes the characteristics of these defects and makes a preliminary type determination to facilitate the subsequent comprehensive evaluation. Specifically, for each segmented defect area (defined by its contour or mask):
[0101] First, a series of geometric parameters are calculated, including, for example: area (number of pixels or converted to actual physical units, such as mm²), perimeter, equivalent diameter, length of the minimum enclosing rectangle ( ) and width ( )、main axis direction angle、elongation( ), circularity (4π×area / perimeter2), compactness, Hu invariant moments, etc.
[0102] The statistical grayscale features of the pixels within the defect area (such as average grayscale, grayscale standard deviation, and grayscale entropy) are then calculated, along with the contrast features with the adjacent background area. Optionally, local texture features of the defect area (such as LBP features and gray-level co-occurrence matrix (GLCM) features) can also be extracted.
[0103] Finally, based on the extracted quantitative features, combined with a pre-established defect knowledge base (which contains typical characteristic parameter ranges for different types of forging defects) and a set of exemplary classification rules (for example, implemented through simple threshold logic or a lightweight traditional classifier such as a decision tree or K-nearest neighbor (KNN) algorithm):
[0104] If the defect elongation is greater than 8 and the area is less than (preset maximum allowable crack width × length), it is initially judged as a "linear defect (suspected crack)";
[0105] If the defect circularity is greater than 0.7 and the equivalent diameter is less than the preset maximum allowable point defect diameter, it is preliminarily determined to be a "point defect (suspected pit / pit)";
[0106] If the defect elongation is between 2 and 8 and has specific texture or grayscale characteristics, it may be judged as a "scratch" or "early fold".
[0107] For example, for the 3mm-long crack segmented above, its elongation might be calculated as 60, and its area as 0.15mm², successfully classified as a "linear defect." Two 0.3mm-diameter pits might have circularity calculated as 0.88 and 0.91, for example, and be classified as "point defects." Each defect is accompanied by a detailed list of characteristic parameters.
[0108] After completing precise segmentation and preliminary feature analysis of pin forging surface defects, this embodiment allows for a systematic and comprehensive evaluation of the inspection results. For example, based on the quality acceptance criteria pre-entered into the system for that specific pin forging model (e.g., criteria that may, for example, stipulate: cracks exceeding 1.5 mm in length are not permitted; point defects greater than 0.5 mm in diameter are limited to no more than 3 per dm²; and no detectable defects are permitted in critical stress-bearing areas (e.g., journal fillets),) the summarized defect information (type, size, location, quantity, density, etc.) is rigorously checked for conformity. An automated logic-based decision process then renders a final assessment of the pin forging's overall surface quality. For example, the verdict may be "acceptable," "unacceptable (with details of the major defects exceeding the standard noted)," or "pending manual review (e.g., defects of certain critical sizes or problematic types)."
[0109] An embodiment of a pin forging quality inspection system:
[0110] On the other hand, the present invention also provides a pin forging quality inspection system. Figure 2 As shown, a pin forging quality inspection system includes a processor and a memory, wherein the memory stores computer program instructions. When the computer program instructions are executed by the processor, a pin forging quality inspection method according to the first aspect of the present invention is implemented.
[0111] A pin forging quality inspection system also includes other components familiar to those skilled in the art, such as a communication interface. The configuration and functions of these components are known in the art and will not be described in detail here.
[0112] In the present invention, the aforementioned memory can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, the computer-readable storage medium can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc., or any other medium that can be used to store the required information and can be accessed by an application, module, or both. Any such computer storage medium can be part of, accessible to, or connectable to a device. Any application or module described in the present invention can be implemented using computer-readable / executable instructions stored or otherwise maintained by such a computer-readable medium.
Claims
1. A pin forging quality inspection method, characterized in that: The method comprises: Acquire a surface image of a pin forging to be inspected; determine a total energy function of an active contour model, wherein the total energy function includes an internal energy term and an external energy term; Determine a pixel neighborhood window, and obtain a structure tensor based on the gradient amplitude of each pixel in the pixel neighborhood window, and then calculate the local gradient direction dispersion of each pixel; calculate the defect edge structure enhancement index of each pixel based on the spatial distribution and local morphological characteristics of the local gradient direction dispersion; Setting a minimum value and a maximum value of the adaptive external energy scaling adjustment factor and calculating the difference between the minimum value and the maximum value; using the defect edge structure enhancement index as an independent variable of a preset nonlinear mapping function to obtain a mapping value, calculating the product of the mapping value and the difference and summing the result with the minimum value to obtain an adaptive external energy scaling adjustment factor; using the adaptive external energy scaling adjustment factor as a multiplicative weight, directly acting on the basic external energy term in the total energy function of the active contour model, obtaining an improved total energy function, and thereby obtaining an improved active contour model; The improved active contour model is used to segment and extract the contours of potential defects in the surface image; features are extracted and quantified for the segmented defect areas, and the processing and forming quality of the pin forging is determined based on preset quality acceptance standards.
2. A pin forging quality inspection method according to claim 1, characterized in that: The local gradient direction dispersion is recorded as , the calculation method is as follows: For pixels and its neighborhood window , the set of valid gradient vectors whose gradient amplitude in the statistical window is greater than the preset threshold ; like Number of vectors If the number of local gradients is less than the minimum valid gradient, the local gradient direction discreteness is set to 0; Otherwise, yes Each valid gradient vector in Normalized to get the direction vector ,have , and construct the structure tensor ; calculate The two eigenvalues of and ,but ,in To avoid small positive numbers with zero denominator.
3. A pin forging quality inspection method according to claim 2, characterized in that: The calculation method of the defect edge structure enhancement index is specifically as follows: ; in Represents pixel points Defect edge structure enhancement index; Represents the local gradient direction discreteness; Indicates a point In this setting Direction line segment The average of the values; and They represent the maximum value function and the minimum value function respectively.
4. A pin forging quality inspection method according to claim 1, characterized in that: The calculation method of the adaptive external energy scaling adjustment factor is specifically as follows: ; in and Respectively represent the minimum and maximum values of the set adaptive external energy scaling adjustment factor; Represents pixel points Defect edge structure enhancement index; is a nonlinear mapping function whose parameters include the lower threshold used to calibrate the mapping interval , upper threshold and an exponent that controls the shape of the curve .
5. A pin forging quality inspection method according to claim 4, characterized in that: The nonlinear mapping function includes a Sigmoid function or at least one of the following piecewise functions, specifically: ; in represents a reference symbol used to refer to the defect edge structure enhancement index.
6. A pin forging quality inspection method according to claim 1, characterized in that: The improved energy function is specifically defined as: ; in Represents the improved energy function definition expression; , represents the parameterized contour curve; Represents internal energy, ,in and is the set weight; Indicates at the contour point The adaptive external energy scaling adjustment factor calculated at the location; is a basic external energy term, constructed based on the image gradient amplitude, ,in is the Gaussian smoothing kernel, is the set gradient energy weight constant.
7. A pin forging quality inspection method according to claim 1, characterized in that: Before obtaining the surface image of the pin forging to be inspected, the following steps are also included: Clean the surface, cool and precisely position the pin forgings to be inspected; At least one industrial camera is used in conjunction with a telecentric lens and a programmable combined light source system to capture images of the surface to be inspected of the pin forging under multi-angle or multi-mode lighting, and necessary camera calibration and light field calibration are performed.
8. A pin forging quality inspection method according to claim 7, characterized in that: It also includes preprocessing the surface image: grayscale the surface image; Use adaptive histogram equalization to process grayscale images; Perform median filtering to denoise the grayscale image.
9. A pin forging quality inspection method according to claim 1, characterized in that: After using the improved active contour model to segment and extract the contours of potential defects in the surface image, the method further includes: For each defect area segmented, its geometric characteristic parameters are automatically calculated, and the geometric characteristic parameters include at least area, perimeter, equivalent diameter, length and width of the minimum circumscribed rectangle, main axis direction angle, elongation, and circularity; And calculate its grayscale characteristic parameters, which at least include the average grayscale in the area, the grayscale standard deviation, and the average contrast with the adjacent background area.
10. A pin forging quality inspection system, characterized in that: The invention comprises a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, a pin forging quality inspection method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Method for mounting large-sized rolling mills
CN101275400A
Mould plate quality detection method and system based on machine vision
CN118587226A
Cited By
Pin shaft surface hardness distribution real-time detection method based on machine vision
CN122312566A