Image processing method for detecting casting defects
By constructing a priori defect probability distribution of castings and using heuristic algorithms to plan acquisition angles, multi-angle image acquisition and enhancement processing are performed, solving the problems of blindness and low efficiency in casting defect detection, and achieving efficient and comprehensive defect identification and detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGDONG OCEAN UNIVERSITY
- Filing Date
- 2026-03-25
- Publication Date
- 2026-06-19
AI Technical Summary
Existing technologies for casting defect detection suffer from problems such as high blindness in image acquisition, low completeness of defect identification, and insufficient overall efficiency and accuracy of defect detection.
By constructing a priori defect probability distribution of the target casting, a set of candidate acquisition angles is obtained. A heuristic algorithm is used to plan the acquisition angle strategy, multi-angle image acquisition is performed, and image enhancement processing is carried out. Defect detection is then performed in conjunction with the priori defect probability distribution.
It improves the efficiency, completeness, and accuracy of casting defect detection, ensuring efficient and comprehensive defect identification and detection.
Smart Images

Figure CN122238338A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to an image processing method for detecting defects in castings. Background Technology
[0002] During the casting process, due to fluctuations in process parameters, changes in material properties, and environmental factors, various defects such as porosity, cracks, inclusions, and shrinkage porosity are easily generated on the surface or inside of castings. These defects not only affect the appearance quality of the product but also significantly reduce its mechanical properties and service life, and may even lead to serious safety accidents. Traditional casting defect detection methods are insufficient to meet the demands of modern industry for high-precision, high-efficiency, and automated inspection. With the development of machine vision and image processing, vision-based non-destructive testing has gradually become mainstream. This involves acquiring images of the casting surface using image acquisition equipment and automatically identifying and classifying defects using image processing algorithms. However, the complex structure, diverse surface textures, and varied defect morphologies of castings pose significant challenges to automated inspection. The visibility of defects is highly dependent on the acquisition angle, lighting conditions, and background noise. Images from a single angle often cannot completely capture all potential defects, leading to a decrease in recognition rate and an increase in false detection rate. Furthermore, the acquisition angle lacks adaptive planning for specific casting models and defect distributions, affecting the accuracy and completeness of defect detection.
[0003] Current technologies suffer from several technical problems, including high blindness in image acquisition, low completeness of defect identification, and insufficient overall efficiency and accuracy in defect detection. Summary of the Invention
[0004] This application provides an image processing method for detecting casting defects, which solves the technical problems of high blindness in image acquisition, low completeness of defect identification, and insufficient overall efficiency and accuracy of defect detection in the prior art, and achieves the technical effect of improving the efficiency, completeness and accuracy of defect detection.
[0005] This application provides an image processing method for detecting casting defects. The method includes: constructing a priori defect probability distribution of a target casting, wherein the priori defect probability distribution is obtained by analyzing the historical defect distribution of castings of the same model as the target casting; obtaining a set of candidate acquisition angles for the target casting; evaluating the defect recognition completeness of the candidate acquisition angle set according to the priori defect probability distribution to determine a first acquisition angle; setting an optimization objective; using a heuristic algorithm to plan the remaining acquisition angles of the target casting based on the first acquisition angle to obtain an acquisition angle strategy that satisfies the optimization objective; controlling an image acquisition device to acquire images of the target casting from multiple angles according to the acquisition angle strategy to obtain a set of casting images; calling the priori defect probability distribution to perform image enhancement processing on the set of casting images to obtain a set of enhanced casting images; performing defect detection on the set of enhanced casting images and outputting the casting defect detection result.
[0006] In a possible implementation, the image processing method for detecting casting defects further performs the following processing: acquiring casting samples, wherein the casting samples are castings of the same model as the target casting; collecting the historical defect distribution corresponding to the casting samples, including historical defect types and defect location regions; constructing a digital casting simulation model, dividing the surface of the digital casting simulation model into multiple grid regions, using the digital casting simulation model to map the defect location region of each casting sample, and constructing a priori defect probability distribution based on the defect probability of defects appearing in each grid region.
[0007] In a possible implementation, the image processing method for detecting casting defects further includes the following steps: the candidate acquisition angle set is obtained by analyzing the degree-of-freedom range of the image acquisition device; ray projection is performed on the digital casting simulation model based on each candidate acquisition angle to obtain a corresponding binary visibility mask, the binary visibility mask being used to characterize the visible surface under the corresponding candidate acquisition angle; the visibility defect probability distribution corresponding to the binary visibility mask is calculated according to the prior defect probability distribution, and the defect recognition completeness of each candidate acquisition angle is output by normalizing the visibility defect probability distribution; and a first acquisition angle is determined according to the defect recognition completeness of each candidate acquisition angle.
[0008] In a possible implementation, the image processing method for detecting casting defects further performs the following processing: defining a set of view quality weights corresponding to the candidate acquisition angle set, wherein the set of view quality weights corresponds one-to-one with the candidate acquisition angle set; wherein each view quality weight is obtained by comprehensively calculating the incident angle weight, defect type weight, illumination uniformity weight, and acquisition resolution weight.
[0009] In a possible implementation, the image processing method for detecting casting defects further performs the following processing: defining a marginal coverage gain; calculating a first-round marginal coverage gain index relative to the first acquisition angle based on the set of remaining candidate acquisition angles, obtaining a second acquisition angle, the second acquisition angle belonging to the set of remaining candidate acquisition angles, and simultaneously updating the set of remaining candidate acquisition angles; calculating a second-round marginal coverage gain index relative to the first acquisition angle and the second acquisition angle based on the updated set of remaining candidate acquisition angles, obtaining a third acquisition angle, until an acquisition angle strategy that satisfies the optimization objective is obtained, wherein the optimization objective includes a preset global coverage gain index.
[0010] In a possible implementation, the image processing method for detecting casting defects further performs the following processing: sorting the first-round edge coverage gain indexes to obtain the top-of-the-stack acquisition angle and the second-top-of-the-stack acquisition angle; calculating the top-of-the-stack edge coverage gain and the second-top-of-the-stack edge coverage gain of the top-of-the-stack acquisition angle and the second-top-of-the-stack acquisition angle; if the top-of-the-stack edge coverage gain is greater than the second-top-of-the-stack edge coverage gain, outputting the top-of-the-stack acquisition angle as the third acquisition angle; and if the top-of-the-stack edge coverage gain is less than the second-top-of-the-stack edge coverage gain, reselecting the top-of-the-stack acquisition angle.
[0011] In a possible implementation, the image processing method for casting defect detection further performs the following processing: pixel conversion of each image in the casting image set to output a casting pixel image set; identifying the defect probability value of each pixel in each casting pixel image according to the prior defect probability distribution; configuring an enhancement weight map for each casting pixel image based on the defect probability value of each pixel in each casting pixel image; performing adaptive enhancement processing on each casting pixel image according to the enhancement weight map to obtain a casting enhanced image set; wherein the adaptive enhancement processing is obtained by calling an enhancement operation library, which is a mapping relationship library including defect types and various image enhancement algorithms.
[0012] In a possible implementation, the image processing method for casting defect detection further performs the following processing: inputting the enhanced image set of the casting into the defect detection model for multi-scale feature convolution to obtain multi-scale defect feature vectors; setting prior defect detection weights according to the prior defect probability distribution; and using the prior defect detection weights to identify the multi-scale defect feature vectors to obtain the casting defect detection result.
[0013] This application proposes an image processing method for casting defect detection. The method constructs a priori defect probability distribution of the target casting by analyzing historical defect distributions of castings of the same model. It then acquires a set of candidate acquisition angles for the target casting, evaluates the completeness of defect recognition, and determines the first acquisition angle. An optimization target is set, and a heuristic algorithm is used to plan the remaining acquisition angles, resulting in an acquisition angle strategy. An image acquisition device is controlled to acquire images of the target casting from multiple angles, obtaining a set of casting images, which are then enhanced to obtain an enhanced set of casting images. Defect detection is performed on the enhanced image set, and the casting defect detection results are output. This method solves the technical problems of high blindness in image acquisition, low defect recognition completeness, and insufficient overall efficiency and accuracy of defect detection in existing technologies, achieving the technical effect of improving the efficiency, completeness, and accuracy of defect detection. Attached Figure Description
[0014] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings of the embodiments of the present invention will be briefly described below. Flowcharts are used in this application to illustrate the operations performed by the system according to the embodiments of the present application. It should be understood that the preceding or following operations are not necessarily performed precisely in sequence. Instead, various steps can be processed in reverse order or simultaneously as needed. Furthermore, other operations can be added to these processes, or one or more steps can be removed from these processes.
[0015] Figure 1 This is a flowchart illustrating an image processing method for detecting casting defects, provided in an embodiment of this application.
[0016] Figure 2 This is a schematic diagram illustrating the process of defect identification integrity assessment in an image processing method for detecting casting defects provided in an embodiment of this application. Detailed Implementation
[0017] The above description is merely an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, specific embodiments of this application are given below.
[0018] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description of this application will be provided in conjunction with the accompanying drawings. The described embodiments should not be considered as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0019] In the following description, references to "some embodiments" describe a subset of all possible embodiments. However, it is understood that "some embodiments" can be the same or different subsets of all possible embodiments and can be combined with each other without conflict. The terms "first" and "second" are used merely to distinguish similar objects and do not represent a specific ordering of objects. The terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, product, or server that includes a series of steps is not necessarily limited to those steps explicitly listed, but may include other steps not explicitly listed or inherent to such processes, methods, products, or devices. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only.
[0020] This application provides an image processing method for detecting casting defects, such as... Figure 1 As shown, the method includes: Step S100: Construct the prior defect probability distribution of the target casting. The prior defect probability distribution is obtained by analyzing the historical defect distribution of castings of the same model as the target casting.
[0021] Step S100 further includes step S110, obtaining a casting sample, wherein the casting sample is a casting of the same model as the target casting; step S120, collecting the historical defect distribution corresponding to the casting sample, including historical defect types and defect location regions; step S130, constructing a digital casting simulation model, dividing the surface of the digital casting simulation model into multiple grid regions, using the digital casting simulation model to map the defect location region of each casting sample, and constructing a priori defect probability distribution based on the defect probability of defects appearing in each grid region.
[0022] Preferably, a priori defect probability distribution for the target casting is constructed based on a large amount of defect distribution data accumulated from previous production and inspection of castings of the same model as the target casting. Specifically, a large amount of defect data recorded in previous inspections of castings of the same model as the target casting is collected. This typically includes the type of each defect, such as porosity, shrinkage cavities, cracks, inclusions, etc., as well as precise location information through three-dimensional coordinates or relative to the casting reference point. Then, a digital casting simulation model of the target casting is created, and its surface is divided into countless small grid regions. The collected historical defect data is then mapped to the corresponding grid regions according to its location information. For example, if a historical defect record shows porosity at a certain location, the porosity count in the grid region where that location is located increases. Then, statistical analysis is performed on all grid regions, and the ratio of the number of times the defect has occurred in each grid region in history to the total number of castings of the same model that have been inspected is calculated as the prior probability of the defect occurring in the grid region. The probability of the defect occurring in each grid region is determined, and finally, a priori defect probability distribution is generated, which quantitatively represents the expected probability that the target casting has a defect at the corresponding location.
[0023] Step S200: Obtain the candidate acquisition angle set of the target casting, evaluate the defect identification completeness of the candidate acquisition angle set according to the prior defect probability distribution, and determine the first acquisition angle.
[0024] Preferably, the casting is observed from every possible angle using computer simulation, and the total defect risk value that each angle can cover is calculated using the prior defect probability distribution. The angle that covers the maximum defect risk value is selected as the optimal starting detection viewpoint. Specifically, a set of candidate acquisition angles for the target casting is obtained, that is, the set of all possible shooting angles that the image acquisition device can reach. By analyzing the mechanical degrees of freedom of the image acquisition device, such as the range of motion of the robotic arm joints, the rotation and pitch angles of the gimbal, and the constraints to avoid collisions with the casting or the environment, a discrete set of angles covering all possible viewpoints is generated. Then, the defect recognition completeness of the candidate acquisition angle set is evaluated according to the prior defect probability distribution, that is, a completeness score is calculated for each candidate acquisition angle, quantifying the extent to which high-probability defects can be covered when shooting from that angle. Specifically, for any candidate angle, the visible and invisible surface meshes of the digital casting model are identified by ray casting in computer graphics, simulating the view from that perspective. These meshes are then combined to generate a binary visibility mask, where 1 represents visible and 0 represents invisible. Next, the completeness of defect identification is evaluated based on the prior defect probability distribution, i.e., the amount of valuable surface area visible. The completeness score for that angle is the sum of the defect probability values of each visible mesh. If multiple high-probability defect areas are visible from a given acquisition angle, the total score is high; if only low-probability areas are visible, even a large visible area will result in a low total score. Finally, the angle with the highest defect completeness evaluation score is selected as the first acquisition angle to ensure the most likely defects are captured with the highest efficiency.
[0025] Furthermore, such as Figure 2 As shown, step S200 further includes step S210, wherein the candidate acquisition angle set is obtained by analyzing the degree of freedom range of the image acquisition device; step S220, ray projection is performed on the digital casting simulation model based on each candidate acquisition angle to obtain a corresponding binary visibility mask, the binary visibility mask being used to characterize the visible surface under the corresponding candidate acquisition angle; step S230, the visibility defect probability distribution corresponding to the binary visibility mask is calculated according to the prior defect probability distribution, and the defect recognition completeness of each candidate acquisition angle is output by normalizing the visibility defect probability distribution; step S240, the first acquisition angle is determined according to the defect recognition completeness of each candidate acquisition angle.
[0026] Preferably, the set of candidate acquisition angles is obtained by analyzing the degree of freedom range of the image acquisition device. Specifically, the degree of freedom parameters of the physical motion of the image acquisition device are read, including the rotation range of its joints, the pitch and yaw limits of the gimbal, etc. By analyzing the degree of freedom range and combining it with collision detection, that is, ensuring that the mechanical device will not collide with the casting or itself, multiple discrete, all safe and reachable shooting angles are calculated and generated to form the set of candidate acquisition angles. Then, ray projection is performed on the digital casting simulation model based on each candidate acquisition angle, that is, simulating the field of view of each angle, including emitting a large number of virtual rays from the simulated camera focus to the surface of the digital casting simulation model. If a ray hits the model surface and there are no other objects obstructing the surface point between the surface point and the camera, it means that the surface point is visible, and it is marked as 1 at the corresponding image pixel position. If the surface point is obstructed by other parts of the casting itself, that is, there is self-occlusion, it is marked as 0. Thus, a binary visibility mask with the same resolution as the image is generated, clearly defining the visible and invisible casting surfaces at that acquisition angle.
[0027] Preferably, the visible defect probability distribution corresponding to the binary visibility mask is calculated based on the prior defect probability distribution. Specifically, the binary visibility mask is used as a filter in the prior defect probability distribution. That is, the defect probability value of the grid area corresponding to each visible point in the binary visibility mask is extracted, while the defect probability value of the grid area corresponding to the invisible point is counted as 0. The defect probability of all visible areas at that angle is obtained, and the defect probability values of all visible areas are summed. Then, by normalizing the visible defect probability distribution, the ratio of the sum of the defect probabilities of all visible areas at each angle to the sum of the defect probabilities of all surface grids is calculated and transformed into the range of 0 to 1. This ratio is used as the defect identification completeness of the candidate angle, indicating what proportion of potential defect risks can be detected from the acquisition angle. The closer it is to 1, the greater the detection value of the acquisition angle. The defect identification completeness of each candidate acquisition angle is then output. The defect identification completeness of all candidate acquisition angles is compared, and the candidate acquisition angle corresponding to the largest defect identification completeness is selected as the first acquisition angle. This prioritizes the capture of the area with the highest defect probability, improving the efficiency, completeness, and accuracy of casting defect detection.
[0028] Furthermore, step S230 also includes defining a set of view quality weights corresponding to the candidate acquisition angle set, wherein the set of view quality weights corresponds one-to-one with the candidate acquisition angle set; wherein each view quality weight is obtained by comprehensively calculating the incident angle weight, defect type weight, illumination uniformity weight, and acquisition resolution weight.
[0029] Preferably, a set of viewpoint quality weights is defined corresponding to the candidate acquisition angle set, containing a comprehensive quality score for each candidate acquisition angle. This is used to correct the completeness of defect recognition, making the visibility assessment of defect recognition from candidate angles more accurate. The set of viewpoint quality weights corresponds one-to-one with the candidate acquisition angle set. Each viewpoint quality weight is obtained by comprehensively weighting and summing the incident angle weight, defect type weight, illumination uniformity weight, and acquisition resolution weight. Specifically, the incident angle weight represents the angle between the camera optical axis and the normal to the object surface. The smaller the angle, the clearer the surface texture and defect features are displayed; the larger the angle, the more geometric distortion occurs, and details become blurred. The defect type weight represents the priority of the defect types visible from this angle. Different defects have different severity. Based on the prior distribution, the defect types in the visible area of this angle are weighted and summed, with high-severity defect types assigned a higher priority. Higher weighting; Illumination uniformity weighting represents the uniformity of light illuminating the target surface at this acquisition angle. Uniform illumination avoids overexposure and shadows, which is beneficial for image processing algorithms to accurately extract features. Non-uniform illumination will produce artifacts and interfere with defect identification. By simulating the illumination model at this angle, the variance of the illumination intensity of the visible surface is calculated. The smaller the variance, the higher the weighting. Acquisition resolution weighting represents the number of pixels per unit area of the target surface in the image when shooting from this angle. The higher the resolution, the more likely the details of the defects are to be captured. Long distances or tilted angles will cause a decrease in resolution, making it impossible to identify small defects. By calculating the average or minimum pixel projection area of the visible surface grid on the imaging plane, the more pixels per unit area, the higher the weighting. This ensures that the selected first acquisition angle can not only see high-probability defect areas, but also clearly capture casting defects, and prioritize the capture of severe defect types.
[0030] Step S300: Set an optimization target, and use a heuristic algorithm to plan the remaining acquisition angles of the target casting based on the first acquisition angle to obtain an acquisition angle strategy that satisfies the optimization target.
[0031] Preferably, the optimization objective is set, which may include maximizing the overall defect coverage probability, reaching a preset coverage threshold, maximizing marginal benefits, and minimizing acquisition time / path length. Then, a heuristic algorithm is used to plan the remaining acquisition angles of the target casting based on the first acquisition angle. That is, the search direction is guided by empirical rules, and a very good approximate optimal solution is found with an acceptable computational cost. Specifically, the selected angle set formed by the first acquisition angle is used as the initial state. Each remaining candidate acquisition angle of the target casting is evaluated. The extent to which adding it to the selected angle set can help optimize the objective is assessed, such as how much the coverage probability will be increased. Then, based on the evaluation results, the remaining candidate angle that contributes the most to the optimization objective is selected and added to the selected angle set. The selected angle set is continuously expanded through iterative loops until the optimization objective is met. The acquisition angle strategy is determined, including the selected candidate acquisition angles and the acquisition order. An ordered acquisition angle sequence is output, and the image acquisition device is controlled to perform automated scanning.
[0032] Furthermore, step S300 also includes step S310, defining marginal coverage gain; step S320, calculating a first-round marginal coverage gain index with the first acquisition angle based on the set of remaining candidate acquisition angles, obtaining a second acquisition angle, the second acquisition angle belonging to the set of remaining candidate acquisition angles, and updating the set of remaining candidate acquisition angles; step S330, calculating a second-round marginal coverage gain index with the first acquisition angle and the second acquisition angle based on the updated set of remaining candidate acquisition angles, obtaining a third acquisition angle, until an acquisition angle strategy that satisfies the optimization objective is obtained, wherein the optimization objective includes a preset global coverage gain index.
[0033] Preferably, the marginal coverage gain refers to the additional defect probability value that can be covered by each newly added acquisition angle. That is, the marginal coverage gain is the difference between the total defect probability that can be covered after selecting a new angle and the total defect probability already covered by the currently selected angles. This effectively avoids selecting redundant angles that, while good in themselves, have a high degree of overlap with the field of view of the currently selected angles. For each candidate acquisition angle in the remaining candidate acquisition angle set, its one-round marginal coverage gain is calculated. Multiple one-round marginal coverage gain indices corresponding to the remaining candidate acquisition angle set are obtained and compared. The candidate angle that brings the maximum marginal coverage gain is determined as the second acquisition angle. The second acquisition angle is one of the remaining candidate acquisition angles in the set. Simultaneously, the remaining candidate acquisition angle set is updated. The second acquisition angle is removed from the set of remaining candidate acquisition angles. Similarly, the marginal coverage gain index of the first and second acquisition angles is calculated based on the updated set of remaining candidate acquisition angles. The candidate angle that brings the maximum marginal coverage gain is determined as the third acquisition angle. This process is repeated until the preset optimization objective is met. The corresponding acquisition angle strategy is determined, including multiple acquisition angles and acquisition order. The optimization objective includes a preset global coverage gain index, which means that if the maximum marginal coverage gain brought by all candidate angles in the next iteration is less than a preset threshold, it indicates that the benefit of adding more angles is negligible. The iteration is then stopped to avoid over-acquiring images and ensure the efficiency of image acquisition and defect detection.
[0034] Furthermore, step S320 also includes step S321, sorting the first-round edge coverage gain index to obtain the top-of-the-stack acquisition angle and the second-top-of-the-stack acquisition angle; step S322, calculating the top-of-the-stack edge coverage gain and the second-top-of-the-stack edge coverage gain of the top-of-the-stack acquisition angle and the second-top-of-the-stack acquisition angle; step S323, if the top-of-the-stack edge coverage gain is greater than the second-top-of-the-stack edge coverage gain, outputting the top-of-the-stack acquisition angle as the third acquisition angle, and if the top-of-the-stack edge coverage gain is less than the second-top-of-the-stack edge coverage gain, reselecting the top-of-the-stack acquisition angle.
[0035] Preferably, the marginal coverage gain indices are sorted, and the angles with the largest and second-largest current gain values are obtained from the top of the stack, serving as the top-of-the-stack acquisition angle and the second-largest-of-the-stack acquisition angle, respectively. Then, the marginal coverage gain of the top-of-the-stack acquisition angle and the second-largest-of-the-stack acquisition angle are calculated separately. The latest marginal coverage gain of the top-of-the-stack angle is then compared with the marginal coverage gain recorded for the second-largest-of-the-stack angle. If the marginal coverage gain of the top-of-the-stack angle is greater than that of the second-largest-of-the-stack angle, since marginal gain is monotonically decreasing, the latest marginal coverage gain values of all other angles are only lower than their previously recorded marginal coverage gain values. In this case, the top-of-the-stack acquisition angle is directly selected. The degree is output as the third acquisition angle; if the edge coverage gain of the top of the stack is less than the edge coverage gain of the second top of the stack, that is, the edge coverage gain of the top acquisition angle is lower than the old edge coverage gain value recorded by the second top acquisition angle, it means that the top acquisition angle is no longer the acquisition angle with the largest edge coverage gain. Then, the top acquisition angle is popped from the stack and re-inserted into the stack for sorting using its latest calculated edge coverage gain value. At this time, the top of the stack will be replaced by another acquisition angle. Then, the edge coverage gain of the top acquisition angle and the second top acquisition angle are calculated and compared until the edge coverage gain of the top of the stack is greater than the edge coverage gain of the second top of the stack.
[0036] Step S400: Control the image acquisition device to acquire the target casting from multiple angles according to the acquisition angle strategy, obtain a casting image set, call the prior defect probability distribution to perform image enhancement processing on the casting image set, and obtain a casting enhanced image set.
[0037] Preferably, the acquisition angle strategy is sent to the control system, and the optimal path for controlling the movement of the robotic arm is calculated based on the acquisition angle sequence. The robotic arm drives the image acquisition device to acquire images of the target casting from multiple angles, forming a casting image set. Then, the prior defect probability distribution is used to perform image enhancement processing on the casting image set. That is, important regions of the casting images are determined based on the prior defect probability distribution and enhanced accordingly. Specifically, a pixel-level mapping is established for each acquired casting image, that is, the digital casting model surface mesh region corresponding to each pixel in the image is calculated based on the acquisition angle and camera parameters. Then, the defect probability value of each pixel corresponding to the model surface mesh area is queried from the prior defect probability distribution. This value is used as the intensity weight that the pixel should be processed during the enhancement process. This generates an enhancement weight map of the same size for each casting image. Each pixel value in the enhancement weight map corresponds to the defect probability value of the original image pixel. Then, the enhancement operation library is called to perform adaptive enhancement processing on the casting image set to obtain the corresponding casting enhancement image set. The visual effect of the potential defect area in the casting enhancement image is maximized and optimized, significantly improving the image quality of the key area. This greatly reduces the difficulty of defect detection and recognition, and improves the defect detection accuracy and detection rate.
[0038] Further, step S400 also includes step S410, performing pixel conversion on each image in the casting image set to output a casting pixel image set; step S420, identifying the defect probability value of each pixel in each casting pixel image according to the prior defect probability distribution; step S430, configuring an enhancement weight map for each casting pixel image based on the defect probability value of each pixel in each casting pixel image, and performing adaptive enhancement processing on each casting pixel image according to the enhancement weight map to obtain a casting enhanced image set; step S440, wherein the adaptive enhancement processing is obtained by calling an enhancement operation library, which is a mapping relationship library including defect types and various image enhancement algorithms.
[0039] Preferably, pixel conversion is performed on each image in the casting image set. This may include converting from RGB color space to grayscale to better handle brightness and color information, normalizing pixel values to [0, 1] and correcting image distortion caused by lens distortion, etc., and outputting a standardized casting pixel image set. The position of each pixel image in the casting pixel image set on the physical casting is determined. Specifically, through camera calibration and 3D model rendering, pixel mapping is performed based on the prior defect probability distribution, the image acquisition angle and the digital casting simulation model of the target casting. That is, a mapping relationship is established between each pixel in the casting pixel image and the surface grid area of the digital casting simulation model. The corresponding defect probability value is retrieved from the prior defect probability distribution and assigned to the corresponding pixel in the casting pixel image, thereby generating an enhancement weight map of the casting pixel image. Among them, the region with a weight value close to 1 indicates that the pixel is located in a high defect probability area and needs to be enhanced. The region with a low weight value close to 0 indicates that the pixel is located in a low defect probability area and can be slightly enhanced or kept as is to avoid introducing unnecessary noise.
[0040] Preferably, adaptive enhancement processing is performed on each pixel image of the casting according to the enhancement weight map. This involves calling an enhancement operation library to perform enhancement processing, which traverses each pixel or region of the image, determines the enhancement intensity based on its enhancement weight value, and selects the image enhancement processing algorithm based on the defect type it maps to, generating processed pixel values. The image enhancement processing algorithm may include contrast stretching, adaptive histogram equalization, unsharpening masking, anisotropic diffusion filtering, etc. The enhancement operation library is a mapping library of defect types and various image enhancement algorithms. It intelligently selects the most suitable image enhancement processing algorithm based on the possible defect types in the region according to the prior defect probability distribution. For example, if a high-probability region has historically had a common defect of cracks, the enhancement operation library may prioritize sharpening or edge enhancement algorithms to make fine cracks more prominent; conversely, if a high-probability region has a common defect of pores, a contrast enhancement algorithm may be selected to make dark pores more distinct from the surrounding bright material. Finally, an enhanced image set of the casting is obtained, where the features of high-defect-risk regions are maximized, while the background regions remain natural, achieving optimal overall image quality for the defect detection task.
[0041] Step S500: Perform defect detection on the enhanced image set of the casting and output the casting defect detection result.
[0042] Step S500 further includes step S510, inputting the enhanced image set of the casting into the defect detection model for multi-scale feature convolution to obtain multi-scale defect feature vectors; step S520, setting prior defect detection weights according to the prior defect probability distribution, and using the prior defect detection weights to identify the multi-scale defect feature vectors to obtain the casting defect detection result.
[0043] Preferably, the defect detection model is a recognition model based on a pre-trained convolutional neural network, such as Faster R-CNN or YOLO. The set of enhanced casting images is input into the defect detection model for multi-scale feature convolution. Simultaneously, the feature maps from both deep and shallow layers of the network are utilized, and feature information at different scales is fused through a feature pyramid network and multi-scale convolutional kernels. For each candidate region in the enhanced casting image, the fused feature information at different scales is represented as a multi-scale defect feature vector, containing visual information describing the region from different scales. Then, prior defect detection weights are set according to the prior defect probability distribution, that is, the defect probability value at the query location in the prior defect probability distribution is converted into a weight factor to determine the prior defect detection weights. Then, the prior defect detection weights are... The prior defect detection weights are used to identify multi-scale defect feature vectors. Specifically, when the convolutional layer of the defect detection model determines whether a multi-scale defect feature vector belongs to a defect, the output result is modulated by the prior defect detection weights. In particular, during the training of the defect detection model, higher weights are assigned to candidate boxes in high-probability regions when calculating the loss function. When performing defect recognition and detection, the defect detection confidence score of the candidate box is directly multiplied by the prior defect detection weights. Finally, the casting defect detection results are obtained, including the defects present in the image, the defect type, the location of each defect, and the corresponding defect confidence score. This significantly improves the detection sensitivity in high-risk regions and reduces the false alarm rate in low-risk regions.
[0044] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application. In some cases, the actions or steps described in this application can be performed in a different order than that shown in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Claims
1. An image processing method for detecting defects in castings, characterized in that, The method includes: A priori defect probability distribution for the target casting is constructed, which is obtained by analyzing the historical defect distribution of castings of the same model as the target casting. Obtain a set of candidate acquisition angles for the target casting, evaluate the completeness of defect identification of the candidate acquisition angle set based on the prior defect probability distribution, and determine the first acquisition angle; Set an optimization target, and use a heuristic algorithm to plan the remaining acquisition angles of the target casting based on the first acquisition angle to obtain an acquisition angle strategy that satisfies the optimization target; The image acquisition device is controlled to acquire the target casting from multiple angles according to the acquisition angle strategy, and a set of casting images is obtained. The prior defect probability distribution is then used to perform image enhancement processing on the set of casting images to obtain an enhanced set of casting images. Defect detection is performed on the enhanced image set of the casting, and the casting defect detection results are output.
2. The image processing method for detecting casting defects as described in claim 1, characterized in that, Methods for constructing the prior defect probability distribution of the target casting include: Obtain a casting sample, wherein the casting sample is a casting of the same model as the target casting; Collect the historical defect distribution corresponding to the casting sample, including the historical defect type and defect location area; A digital casting simulation model is constructed, and the surface of the digital casting simulation model is divided into multiple grid regions. The digital casting simulation model is used to map the defect location region of each casting sample. Based on the defect probability of defects appearing in each grid region, a priori defect probability distribution is constructed.
3. The image processing method for detecting casting defects as described in claim 2, characterized in that, The method involves evaluating the completeness of defect identification based on the prior defect probability distribution of the candidate acquisition angle set. include: The candidate acquisition angle set is obtained by analyzing the degree of freedom range of the image acquisition device; The digital casting simulation model is ray-projected based on each candidate acquisition angle to obtain the corresponding binary visibility mask, which is used to characterize the visible surface at the corresponding candidate acquisition angle. The visual defect probability distribution corresponding to the binary visibility mask is calculated based on the prior defect probability distribution. The defect recognition completeness of each candidate acquisition angle is output by normalizing the visual defect probability distribution. The first acquisition angle is determined based on the degree of defect identification completeness of each candidate acquisition angle.
4. The image processing method for detecting casting defects as described in claim 3, characterized in that, The method further includes: normalizing the probability distribution of visible defects and outputting the defect identification completeness for each candidate acquisition angle; and also includes: Define a set of view quality weights corresponding to the set of candidate acquisition angles, wherein the set of view quality weights corresponds one-to-one with the set of candidate acquisition angles; The quality weight for each viewpoint is obtained by comprehensively calculating the incident angle weight, defect type weight, illumination uniformity weight, and acquisition resolution weight.
5. The image processing method for detecting casting defects as described in claim 1, characterized in that, A heuristic algorithm is used to plan the remaining acquisition angles of the target casting based on the first acquisition angle, thereby obtaining an acquisition angle strategy that satisfies the optimization objective. The method includes: Define marginal coverage gain; Calculate the marginal coverage gain index of the first acquisition angle based on the set of remaining candidate acquisition angles, obtain the second acquisition angle, the second acquisition angle belongs to the set of remaining candidate acquisition angles, and update the set of remaining candidate acquisition angles at the same time. Calculate the second-round marginal coverage gain index with respect to the first and second acquisition angles based on the updated set of remaining candidate acquisition angles, obtain the third acquisition angle, and continue until an acquisition angle strategy that satisfies the optimization objective is obtained, wherein the optimization objective includes a preset global coverage gain index.
6. The image processing method for detecting casting defects as described in claim 5, characterized in that, To obtain the third acquisition angle, other methods include: The edge coverage gain index of the first round is sorted to obtain the top-of-the-stack acquisition angle and the next-top-of-the-stack acquisition angle. Calculate the top edge coverage gain and the second-to-top edge coverage gain of the top acquisition angle and the second-to-top acquisition angle; If the top edge coverage gain is greater than the second top edge coverage gain, the top acquisition angle is output as the third acquisition angle; if the top edge coverage gain is less than the second top edge coverage gain, the top acquisition angle is reselected.
7. The image processing method for detecting casting defects as described in claim 1, characterized in that, The method involves applying the prior defect probability distribution to the casting image set for image enhancement processing to obtain an enhanced casting image set, the method of which includes: Perform pixel conversion on each image in the casting image set to output a casting pixel image set; Based on the prior defect probability distribution, identify the defect probability value of each pixel in each pixel image of the casting; For each pixel in each casting pixel image, an enhancement weight map is configured for each casting pixel image. Adaptive enhancement processing is performed on each casting pixel image according to the enhancement weight map to obtain a set of casting enhanced images. The adaptive enhancement processing is obtained by calling an enhancement operation library, which is a mapping library of defect types and various image enhancement algorithms.
8. The image processing method for detecting casting defects as described in claim 1, characterized in that, The method includes performing defect detection on the enhanced image set of the casting and outputting the casting defect detection results. The enhanced image set of the casting is input into the defect detection model for multi-scale feature convolution to obtain multi-scale defect feature vectors. Based on the prior defect probability distribution, a prior defect detection weight is set, and the multi-scale defect feature vector is identified using the prior defect detection weight to obtain the casting defect detection result.