Polishing scheme autonomous optimization method and system for surface defect detection and medium
By building a defect-lighting sequence database and intelligent optimization algorithm, we can independently find the best lighting solution, solve the problem of light source parameter debugging relying on manual experience, and achieve efficient and accurate industrial defect detection.
Patent Information
- Application Number
- CN202510717687.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2025-09-12
AI Technical Summary
In existing industrial defect detection, light source parameter debugging relies on manual experience, which is inefficient and difficult to cope with complex and changing detection environments. Traditional brute force search strategies consume large computing resources and are time-consuming, making it difficult to meet the needs of efficient real-time detection.
Based on the preset lighting parameter classification rules, a defect-lighting sequence database is constructed, and the decision tree and intelligent optimization algorithms (genetic algorithm and particle swarm optimization algorithm) are used to find the optimal lighting solution. The image segmentation model is combined to evaluate the light source parameters to achieve autonomous optimization.
The adaptability and detection efficiency, accuracy and stability of the lighting solution are significantly improved, the amount of data collection is reduced, the optimal solution is quickly approached, and the detection needs of different defect types are adapted.
Smart Images

Figure CN120634995A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine vision and industrial quality inspection technology, and in particular to a method, system and medium for autonomously optimizing a lighting scheme for surface defect detection. Background Art
[0002] Industrial parts are prone to various defects during the manufacturing process. Currently, the industrial inspection field relies primarily on two methods: traditional manual inspection and machine vision-based defect detection. Machine vision-based surface defect detection (SDD) offers significant advantages by using pixel-level prediction technology to identify defective areas in images, and has become a key tool in industrial quality inspection.
[0003] With the continuous development of deep learning and computer vision technologies, intelligent detection technology has been widely applied in various industrial scenarios. In such detection systems, light source conditions play a vital role as one of the key factors affecting detection results. Currently, industry generally relies on manual experience to debug light source parameters. This process is not only cumbersome and inefficient, but also highly dependent on expert experience, making it difficult to cope with complex and changing detection environments. Therefore, realizing intelligent adjustment of lighting schemes has important research value and application prospects.
[0004] Existing intelligent lighting optimization methods often employ a brute-force search strategy, traversing all possible light source parameter combinations and selecting the configuration with the highest score based on the corresponding defect highlighting effect. However, in practical applications, this approach consumes large amounts of computing resources, is time-consuming, and lacks specificity, making it difficult to meet the needs of efficient, real-time industrial inspection. Therefore, there is an urgent need to explore more efficient intelligent optimization algorithms to improve the adaptability of lighting solutions and overall inspection efficiency. Summary of the Invention
[0005] (1) Technical issues to be resolved
[0006] The main purpose of the present invention is to provide a method, system and medium for autonomously optimizing lighting schemes for surface defect detection, aiming to solve the above-mentioned technical problems.
[0007] (2) Technical solution
[0008] In order to achieve the above object, the present invention provides a method for autonomously optimizing a lighting scheme for surface defect detection, comprising the steps of:
[0009] S1. Based on a preset lighting parameter grading rule, detection data is collected to construct a defect-lighting sequence database: the brightness parameters and angle parameters of the dome light source are both graded according to preset levels, the brightness parameters and angle parameters are combined into multiple lighting parameter sequences according to different levels, different defect image data of the target object surface corresponding to the dome light source under each lighting parameter sequence is obtained, and the defect image data is associated with the lighting parameter sequence to establish a defect-lighting sequence database;
[0010] S2, segment the image and evaluate it, and build a mapping relationship model between various types of defects and lighting parameter sequences based on the decision tree:
[0011] S21, using a pre-trained image segmentation model to segment the defect image data in the defect-lighting sequence database to generate segmented images of various types of defects on the surface of the target object;
[0012] S22, performing quantitative comparison between the segmented image and a preset standard mask image, and evaluating the lighting quality of each lighting parameter sequence based on an evaluation index;
[0013] S23, screening out combinations of lighting parameter sequences corresponding to various types of defects that meet preset quality conditions based on a preset lighting quality threshold, and establishing a mapping relationship model between various types of defects and lighting parameter sequences using a decision tree algorithm;
[0014] S3, based on the mapping relationship model between various types of defects and lighting parameter sequences, uses an intelligent optimization algorithm to find the optimal lighting solution:
[0015] S31, based on the mapping relationship model between each type of defect and the lighting parameter sequence, according to the defect type to be detected, within the combination range of the lighting parameter sequences corresponding to the defect type, a group of lighting parameter sequences is selected as a population individual, and a genetic algorithm is used to optimize the parameters. After the termination condition is met, the optimal parameter sequence is obtained, wherein the fitness function of the genetic algorithm is determined by the evaluation result obtained by real-time acquisition of image data corresponding to the parameter lighting scheme, segmentation using an image segmentation model, and comparison evaluation with a preset mask image;
[0016] S32, using a particle swarm optimization algorithm to perform a local search within the parameter space of the optimal parameter sequence obtained by the genetic algorithm, and outputting a final light source parameter sequence after reaching a termination condition; wherein the fitness function of the particle swarm optimization algorithm is determined by an evaluation result obtained by real-time acquisition of image data corresponding to the parameter lighting scheme, segmentation using an image segmentation model, and comparison evaluation with a preset mask image;
[0017] S4, guiding the actual industrial defect detection task based on the lighting solution corresponding to the light source parameter sequence obtained in step S3.
[0018] Preferably, the termination conditions of step S31 and step S32 are both that a preset maximum number of iterations is reached.
[0019] Preferably, the various types of defect image data include: knock defects on the surface of industrial parts, scratch defects on the surface of industrial parts, and pitting defects on the surface of industrial parts.
[0020] Preferably, the pre-trained image segmentation model includes a SAM model.
[0021] Preferably, the step S31 includes:
[0022] S311, constructing an initial population using the selected lighting parameter sequence as a chromosome code;
[0023] S312, the fitness function is a weighted result of the confidence score and the intersection-over-union ratio in the evaluation results obtained by real-time acquisition of defect image data corresponding to the parameter lighting scheme, segmentation using the image segmentation model, and comparison evaluation with the preset mask image:
[0024] F(x)=w1·C(x)+w2·IoU(x)
[0025] Where x represents the current light source parameter combination, C(x) represents the defect detection confidence score output by the image segmentation model, IoU(x) represents the intersection over union (IoU) of the segmentation result and the standard mask image, and w1 and w2 both represent weight coefficients.
[0026] S313, iterative population evolution through selection, crossover, and mutation operations;
[0027] S314: Output the optimal parameter sequence after reaching the preset maximum number of iterations.
[0028] Preferably, the step S32 includes:
[0029] S321, randomly initializing a group of particles in the parameter space of the optimal parameter sequence domain;
[0030] S322, the fitness function is a weighted result of the confidence score and the intersection-over-union ratio in the evaluation results obtained by real-time acquisition of defect image data corresponding to the parameter lighting scheme, segmentation using the image segmentation model, and comparison evaluation with the preset mask image:
[0031] F(x)=w1·C(x)+w2·IoU(x)
[0032] Where x represents the current light source parameter combination, C(x) represents the defect detection confidence score output by the image segmentation model, IoU(x) represents the intersection over union (IoU) of the segmentation result and the standard mask image, and w1 and w2 both represent weight coefficients.
[0033] S323, parameter fine-tuning through dual guidance of individual optimality and group optimality;
[0034] S324: Output the final light source parameter sequence after the termination condition is met.
[0035] Preferably, before step S2, the following steps are further included:
[0036] Construct a mask image of the preset target object surface defects: manually mark the defect contours of the surface image of the target object to be inspected and generate a grayscale mask image.
[0037] Preferably, the evaluation indicators include: intersection-over-union ratio, Dice similarity coefficient, and pixel accuracy, wherein:
[0038] The calculation formula of the intersection-over-union ratio is:
[0039]
[0040] Where A represents the defect area segmented by the SAM model, B represents the defect area of the preset mask image, |A∩B| represents the number of pixels of the intersection of the defect area segmented by the SAM model and the defect area of the preset mask image, and |A∪B| represents the number of pixels of the union of the defect area segmented by the SAM model and the defect area of the preset mask image.
[0041] The calculation formula of the Dice similarity coefficient is:
[0042]
[0043] Where A represents the defect area segmented by the SAM model, B represents the defect area of the preset mask image, and |A∩B| represents the number of pixels of the intersection between the defect area segmented by the SAM model and the defect area of the preset mask image;
[0044] The calculation formula of the pixel accuracy is:
[0045]
[0046] Among them, TP represents the number of pixels correctly identified as defects, TN represents the number of pixels correctly identified as background, FP represents the number of pixels that mistakenly classify background as defects, and FN represents the number of pixels that mistakenly classify defects as background.
[0047] The present invention also provides a system for autonomously optimizing lighting schemes for surface defect detection, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the system implements the steps of a method for autonomously optimizing lighting schemes for surface defect detection as described in any one of the above items.
[0048] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method for autonomously optimizing a lighting scheme for surface defect detection as described in any one of the above items.
[0049] (3) Beneficial effects
[0050] This application proposes a method for autonomous optimization of lighting schemes for surface defect detection, which segments and evaluates images, and constructs a mapping relationship model between various types of defects and lighting parameter sequences based on a decision tree, which can optimize the most suitable lighting strategy according to different defect types. The accuracy of this "defect-oriented" further refinement of the lighting scheme has significantly improved the adaptability and stability of optimizing the most suitable lighting scheme. Based on the preset lighting parameter classification rules, detection data is collected to build a defect-lighting sequence database, which reduces the amount of collected data, and optimizes the light source parameters through intelligent algorithms to achieve the optimization of the lighting scheme. The evaluation results of the real-time collected data are used for training and iteration, and the optimal solution is quickly approached within a limited search space, which significantly improves the efficiency and accuracy of lighting parameter optimization. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 A schematic flow chart of a method for autonomously optimizing a lighting solution for surface defect detection provided in this embodiment;
[0052] Figure 2 A schematic diagram of a dome light source for an autonomous optimization method of lighting solutions for surface defect detection provided in this embodiment;
[0053] Figure 3 This is a structural diagram of a lighting solution autonomous optimization system for surface defect detection provided in this embodiment;
[0054] Figure 4 A schematic diagram of the hardware structure of a lighting solution autonomous optimization system for surface defect detection provided in this embodiment; DETAILED DESCRIPTION
[0055] In order to better explain the present invention and facilitate understanding, the present invention is described in detail below through specific implementation methods in conjunction with the accompanying drawings.
[0056] It should be noted that all directional indications in the embodiments of the present invention (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the various components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0057] In addition, in the present invention, the terms "first," "second," etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly specifying the number of the technical features indicated. Therefore, features specified as "first" or "second" may explicitly or implicitly include at least one of such features. In the description of the present invention, "plurality" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0058] In the present invention, unless otherwise specified or limited, the terms "connection" and "fixation" should be understood in a broad sense. For example, "fixation" can refer to fixed connection, detachable connection, or integration; "connection" can refer to mechanical connection or electrical connection; it can refer to direct connection or indirect connection through an intermediate medium; it can refer to internal communication between two elements or interaction between two elements, unless otherwise specified. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0059] like Figure 1 As shown, this embodiment provides a method for autonomously optimizing a lighting scheme for surface defect detection, which includes steps: S1, S2, S3 and S4.
[0060] S1. Based on the preset lighting parameter grading rules, detection data is collected to construct a defect-lighting sequence database: the brightness parameters and angle parameters of the dome light source are both graded according to preset levels, and the brightness parameters and the angle parameters are combined into multiple lighting parameter sequences according to different levels. Different defect image data of the target object surface corresponding to the dome light source under each lighting parameter sequence are obtained, and the defect image data are associated with the lighting parameter sequence to establish a defect-lighting sequence database.
[0061] Specifically, the dome light source includes a plurality of independent channel light sources arranged in the dome light source, the brightness parameter of the dome light source is the adjustable brightness of each independent channel light source, and the angle parameter of the dome light source is the angle of the position of each independent channel light source compared to the target object.
[0062] Optionally, the preset grading of the brightness parameters of the dome light source can be set according to actual conditions, for example, the brightness parameters of the dome light source are evenly divided into three, four or even more than four levels according to the brightness intensity amplitude; the preset grading of the angle parameters of the dome light source can be set according to actual conditions, for example, based on the hierarchical angles of the arrangement of the dome light sources, they are divided into multiple different levels of angle parameters, or the angle parameters of the dome light source are evenly divided into three, four or even more than four levels according to the angle amplitude.
[0063] S2, segment the image and evaluate it, and build a mapping relationship model between various types of defects and lighting parameter sequences based on the decision tree:
[0064] S21, using a pre-trained image segmentation model to segment the defect image data in the defect-lighting sequence database to generate segmented images of various types of defects on the surface of the target object;
[0065] Optionally, the pre-trained image segmentation model is a semantic segmentation network model based on deep learning, such as U-Net, Mask R-CNN, DeepLabv3+ and SAM model. The pre-trained image segmentation model can perform high-precision positioning and classification of various surface defects in the image (such as scratches, pits, cracks, bubbles, rust, stains, etc.).
[0066] S22, quantitatively compare the segmented image with a preset standard mask image, and evaluate the lighting quality of each lighting parameter sequence based on evaluation indicators; wherein, the evaluation indicators include but are not limited to: Dice Similarity Coefficient (DSC) measures the degree of overlap between the predicted segmentation image and the true mask image; Intersection over Union (IoU) reflects the matching degree between the segmentation result and the true defect area; Pixel Accuracy (PA) is used to measure the pixel-level matching degree between the segmentation result predicted by the model and the true label; Edge Matching Rate (EMR) is used to evaluate the clarity of the defect edge contour; Image contrast (Contrast) evaluates the overall contrast of the image through local grayscale differences; Signal-to-noise ratio (SNR) evaluates the ratio of effective signal to noise in the image; False detection rate and missed detection rate count the number of unrecognized defects and the number of incorrectly identified defects in the image.
[0067] Optionally, the “lighting quality score” corresponding to each set of lighting parameter sequences may be comprehensively calculated based on the evaluation indicators, or a single evaluation indicator may be selected for evaluation based on actual conditions.
[0068] S23, based on the preset lighting quality threshold, filter out the combination of lighting parameter sequences corresponding to each type of defect that meets the preset quality conditions, and use the decision tree algorithm to establish a mapping relationship model between each type of defect and the lighting parameter sequence. In this embodiment, one or more lighting quality thresholds can be set, specifically, for example, DSC>0.85, IoU>0.8, to filter all lighting parameter sequences, and only retain light source configurations that meet the quality requirements as candidate lighting solutions. Then, for each defect type, its imaging quality performance under different lighting parameter combinations is statistically analyzed, and the best one or more lighting parameter sequences are extracted as the combination of lighting parameter sequences for that defect type.
[0069] S3, based on the mapping relationship model between various types of defects and lighting parameter sequences, adopts an intelligent optimization algorithm to find the optimal lighting solution: wherein, the intelligent optimization algorithm includes Genetic Algorithm (GA) and Particle Swarm Optimization (PSO); by combining the Genetic Algorithm (GA) with strong global search capabilities and the Particle Swarm Optimization (PSO) with fast local convergence speed, a two-stage optimization process of "global first, local later" is constructed, which significantly improves the efficiency and stability of lighting parameter search.
[0070] S31. Based on the mapping relationship model between each defect type and the lighting parameter sequence, a set of lighting parameter sequences is selected as initial population individuals within the combination range of the lighting parameter sequences corresponding to the defect type to be detected. The selected initial population individuals can be manually set or randomly selected. A genetic algorithm (GA) is then used to optimize the parameters, and the optimal parameter sequence is obtained after the termination condition is met. The fitness function of the genetic algorithm is determined by the evaluation result obtained by real-time acquisition of image data corresponding to the parameter lighting scheme, segmentation using an image segmentation model, and comparison with a preset mask image.
[0071] Specifically, the fitness function is calculated based on quality evaluation metrics for image acquisition and segmentation results. Specifically, for each individual lighting parameter, the dome light source is controlled to illuminate according to that parameter and capture an image. This image is then processed using a pre-trained image segmentation model to generate a segmentation map of the defect area. This map is then compared with a standard mask map to calculate a comprehensive quality score (such as the Dice coefficient, IoU, edge matching rate, etc.). Ultimately, these scores are used as fitness values to evaluate the individual's "lighting quality."
[0072] Optionally, the termination condition can be selected according to actual conditions, and can be, for example, the maximum number of iterations (such as 50 generations), the change in fitness value is less than a threshold (such as no significant improvement for three consecutive generations), or the evolution is stopped when a preset quality target is reached.
[0073] S32, using a particle swarm optimization (PSO) algorithm to perform a local search within the parameter space of the optimal parameter sequence obtained by the genetic algorithm, and outputting a final light source parameter sequence after reaching a termination condition; wherein the fitness function of the particle swarm optimization algorithm is determined by an evaluation result obtained by real-time acquisition of image data corresponding to the parameter lighting scheme, segmentation using an image segmentation model, and comparison evaluation with a preset mask image;
[0074] Specifically, the optimal parameter sequence field parameter space is centered on the optimal parameter sequence output by the genetic algorithm and floats up and down within a certain range, specifically, for example, brightness ±1 level, angle ±1 level, to form a new parameter search area.
[0075] Optionally, the termination condition of the particle swarm optimization algorithm can be selected according to actual conditions, such as reaching a maximum number of iterations (such as 20 times), the overall adaptability value of the particle swarm tending to be stable, and the lighting quality score reaching a set threshold.
[0076] S4, guiding the actual industrial defect detection task based on the lighting solution corresponding to the light source parameter sequence obtained in step S3.
[0077] Preferably, the termination conditions of step S31 and step S32 are both reaching a preset maximum number of iterations. This clearly defines the upper limit of the algorithm's running time, making the entire optimization process well-controlled in time and deterministic in execution, and avoiding system response delays or resource waste due to algorithm non-convergence.
[0078] Preferably, the various types of defect image data include: image data of knock defects on the surface of industrial parts, image data of scratch defects on the surface of industrial parts, and image data of pitting defects on the surface of industrial parts.
[0079] Preferably, the pre-trained image segmentation model includes a SAM (SegmentAnything Model) model. SAM is an advanced general-purpose image segmentation model proposed by MetaAI that can perform high-quality segmentation on any image based on user-provided prompts (such as points, boxes, or masks). Using the SAM model can significantly simplify model deployment and maintenance processes, making it more suitable for dynamically changing industrial environments.
[0080] Preferably, the step S31 includes:
[0081] S311, constructing an initial population using the selected lighting parameter sequence as a chromosome code;
[0082] S312, the fitness function is a weighted result of the confidence score and the intersection-over-union ratio in the evaluation results obtained by real-time acquisition of defect image data corresponding to the parameter lighting scheme, segmentation using the image segmentation model, and comparison evaluation with the preset mask image:
[0083] F(x)=w1·C(x)+w2·IoU(x)
[0084] Where x represents the current light source parameter combination, C(x) represents the defect detection confidence score output by the image segmentation model, IoU(x) represents the intersection over union (IoU) of the segmentation result and the standard mask image, w1 and w2 both represent weight coefficients, w1 = 0.3, w2 = 0.7;
[0085] S313, iterative population evolution through selection, crossover, and mutation operations;
[0086] S314: After reaching the preset maximum number of iterations, the optimal parameter sequence is output. Using the weighted result of the confidence score and the intersection-over-union ratio as the fitness function can comprehensively evaluate the quality of the lighting solution and improve the accuracy of defect recognition.
[0087] Preferably, the step S32 includes:
[0088] S321, randomly initializing a group of particles in the parameter space of the optimal parameter sequence domain;
[0089] S322, the fitness function is a weighted result of the confidence score and the intersection-over-union ratio in the evaluation results obtained by real-time acquisition of defect image data corresponding to the parameter lighting scheme, segmentation using the image segmentation model, and comparison evaluation with the preset mask image:
[0090] F(x)=w1·C(x)+w2·IoU(x)
[0091] Where x represents the current light source parameter combination, C(x) represents the defect detection confidence score output by the image segmentation model, IoU(x) represents the intersection over union (IoU) of the segmentation result and the standard mask image, w1 and w2 both represent weight coefficients, w1 = 0.3, w2 = 0.7;
[0092] S323, parameter fine-tuning is performed through dual guidance of individual optimization and group optimization; through this dual guidance mechanism, particles can quickly converge to the local optimal solution, further improving the accuracy of lighting parameters and image quality.
[0093] S324: Output the final light source parameter sequence after the termination condition is met.
[0094] Preferably, before step S2, the following steps are further included:
[0095] Construct a mask image of the target object's surface defects: Manually annotate the defect outlines on the target object's surface image to generate a grayscale mask image. Manual annotation provides a reliable "standard answer" for model training, ensuring the model correctly learns the defect boundaries and morphological features, thereby improving segmentation accuracy.
[0096] Preferably, the evaluation indicators include: intersection-over-union ratio, Dice similarity coefficient, and pixel accuracy, wherein:
[0097] The calculation formula of the intersection-over-union ratio is:
[0098]
[0099] Where A represents the defect area segmented by the SAM model, B represents the defect area of the preset mask image, |A∩B| represents the number of pixels of the intersection of the defect area segmented by the SAM model and the defect area of the preset mask image, |A∪B| represents the number of pixels of the union of the defect area segmented by the SAM model and the defect area of the preset mask image, and the IoU value range is 0 to 1;
[0100] The calculation formula of the Dice similarity coefficient is:
[0101]
[0102] Where A represents the defect area segmented by the SAM model, B represents the defect area of the preset mask image, |A∩B| represents the number of pixels of the intersection between the defect area segmented by the SAM model and the defect area of the preset mask image, and the Dice value range is 0 to 1;
[0103] The calculation formula of the pixel accuracy is:
[0104]
[0105] Among them, TP represents the number of pixels correctly identified as defects, TN represents the number of pixels correctly identified as background, FP represents the number of pixels where background is mistakenly classified as defects, FN represents the number of pixels where defects are mistakenly classified as background, and PA ranges from 0 to 1.
[0106] The following describes a specific operation process to illustrate a method for autonomously optimizing a lighting scheme for surface defect detection in this embodiment:
[0107] Step 1: Install the dome light source and industrial camera, such as Figure 2As shown, the dome light source uses a 48-channel LED array, each with 1,000 adjustable brightness levels. The dome light source array is arranged horizontally, forming seven layers of independent LED channels. A hollow circular hole is located in the center of the light source. The industrial camera is located directly above the dome light source, capturing images of the object under the dome light through the hole. For optimal imaging, place the target object directly under the dome light source, ensuring the distance between the object and the dome light source is within 60mm.
[0108] Step 2. The target object in this embodiment is a linear guide rail, and the types of defects to be detected include scratches, gouges, and pits. When acquiring images, first move the defect sample to be detected to the center of the camera's field of view, adjust the light source array parameter settings through the serial communication protocol, and grade the brightness with a gradient of 100 to obtain a total of 10 levels of brightness parameters. In terms of light source distribution, each layer is used as a gradient to obtain a total of 7 angle parameters. Then, control the industrial camera to collect 70 pictures of each of the three defects in real time through the GigEVision protocol, for a total of 210 pictures, and finally establish a defect-lighting sequence database.
[0109] Step 3: Import a sample image of the defect to be detected into the LabelMe software and manually annotate the true outline of the defect. Then, export the annotation information as a JSON file. Finally, use a Python script to output the image and JSON file as a single-channel mask. In this mask, the pixel value of the defect outline area is 255 (completely black), and the pixel value outside the outline is 0 (completely white), which facilitates subsequent image segmentation and quality assessment.
[0110] Step 4: Based on the defect-lighting sequence database, a certain type of defect samples are sequentially imported into the SAM large model for image segmentation to obtain the segmentation contours of the defect type. Subsequently, the segmentation results are compared with the preset mask image, and quality assessment indicators such as intersection over union (IoU), Dice similarity coefficient, and pixel accuracy (PA) are calculated to measure the lighting scheme's effect on highlighting defect features. During the quality assessment process, the influence of different light source parameters (such as angle and light intensity) on the defect visualization effect is analyzed to find the range of lighting schemes suitable for the defect type.
[0111] Step 5. Use a genetic algorithm to perform a preliminary parameter search for the range of lighting solutions suitable for this defect type. Initialize a set of light source parameters (lighting angle, brightness) and use them as individuals in the population. The fitness of each individual is determined by the SAM model segmentation evaluation score. During the iterative process, operations such as selection, crossover, and mutation are performed to continuously optimize the light source parameters to improve the detection quality. Subsequently, based on the optimal solution obtained by the genetic algorithm, the particle swarm optimization algorithm (PSO) is further used for local search to more finely adjust the light source parameters until the lighting solution reaches the optimal one. Finally, the optimization algorithm outputs the optimal light source parameter combination, which will be used in actual industrial detection tasks.
[0112] This embodiment also provides a system for autonomously optimizing lighting schemes for surface defect detection, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of a method for autonomously optimizing lighting schemes for surface defect detection as described in any one of the above items are implemented.
[0113] like Figure 3 As shown, further, the autonomous optimization system for lighting schemes for surface defect detection described in this embodiment includes a surface defect image acquisition module, an image processing module, a SAM model segmentation evaluation module, and an optimization algorithm module.
[0114] The surface defect image acquisition module includes a stereo light source, an industrial camera, and computing equipment.
[0115] The stereoscopic light source in this embodiment can be a 48-channel multi-angle LED dome light source provided by Guangzhou Xuanshijia Electronic Technology Co., Ltd., model XZV-PFS62-18018085, with an illumination range of 0-20,000 lux (face-mounted) and a color temperature of 6,500k ± 200k. The complete light source includes a multi-angle dome light source and a light source controller. The 48 channels of the multi-angle dome light source are attached to the inner wall of the multi-angle dome structure. The light source controller uses the RS232 serial communication protocol to communicate with external devices and control each channel. The light source controller can pre-store light source array parameters to facilitate real-time control of the multi-angle dome light source on the production line. The control of the entire dome light source consists of 102 bytes, with each channel occupying two bytes. Up to 1,000 adjustable brightness levels can be configured. For example, a brightness level of 1,000 can be represented as "0x03e8." Ultimately, by adjusting the light intensity of each array, multi-angle and multi-brightness dimming is achieved, highlighting defects of different surface features of the object.
[0116] The industrial camera of this embodiment can be a Hikvision (MV-CS060-10GC-PRO) industrial camera, which has a GigE interface and meets the system's Gigabit Ethernet communication protocol. The lens uses MVL-HF5028M-6MPE. Both have 6 million pixels, a resolution of 3072×2048, and a frame rate of 30.7fps, which can meet the needs of most defect detection scenarios.
[0117] The computing device in this embodiment can be composed of a host computer equipped with an Intel Core™ i9-13900x CPU @ 5.8GHz (32GB of RAM) and an NVIDIA GeForce RTX-3060 graphics processing unit (GPU) with 12GB of RAM. A 2TB hard drive is used to store computer programs, defect images, SAM large model weights, and production line data. The CPU and GPU processors are used to implement the multimodal defect detection method when executing the computer program.
[0118] The image processing module first sets up the operating environment and script of the SAM model, then uses an industrial camera to collect defect images adjusted by the light source array in real time and inputs them into the SAM model for pixel-level segmentation processing, and finally outputs the segmented defect area mask image.
[0119] The SAM model segmentation evaluation module compares the preset single-channel mask image with the segmentation result, and calculates indicators such as intersection-over-union, score, Dice similarity coefficient, and pixel accuracy (PA) as the basis for optimization.
[0120] The optimization algorithm module uses the quality indicators obtained by real-time segmentation of defect images by the SAM large model based on the brute force search algorithm as a reference, and continuously adjusts the light source array parameter settings through genetic algorithms and particle swarm optimization algorithms (PSO), and finally feeds back to the surface defect image acquisition module for the next round of lighting scheme evaluation.
[0121] like Figure 4 The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of a method for autonomously optimizing a lighting scheme for surface defect detection as described in any one of the above items.
[0122] Figure 4 FIG. 1 is a schematic diagram of the hardware structure for running a method for autonomously optimizing a lighting scheme for surface defect detection provided by an embodiment of the present invention. Figure 4As shown, this embodiment / computer 6 includes: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60, such as a program for executing a method for autonomously optimizing a lighting scheme for surface defect detection. When the processor 60 executes the computer program 62, the steps of the aforementioned embodiments for executing a method for autonomously optimizing a lighting scheme for surface defect detection are implemented. Alternatively, when the processor 60 executes the computer program 62, the functions of the modules / units in the aforementioned device embodiments are implemented.
[0123] For example, the computer program 62 may be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 60 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, and the instruction segments are used to describe the execution process of the computer program 62 in the computer 6.
[0124] The computer 6 can be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer 6 device can include, but is not limited to, a processor 60 and a memory 61. It can be understood by those skilled in the art that Figure 4 This is only an example of computer 6 and does not constitute a limitation on computer 6. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer 6 may also include input and output devices, network access devices, buses, etc.
[0125] The processor 60 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0126] The memory 61 can be an internal storage unit of the computer 6, such as a hard disk or memory of the computer 6. The memory 61 can also be an external storage device of the computer 6, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. equipped on the terminal device. Furthermore, the memory 61 can also include both an internal storage unit of the computer 6 and an external storage device. The memory 61 is used to store the computer program and other programs and data required by the terminal device. The memory 61 can also be used to temporarily store data that has been output or is about to be output.
[0127] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0128] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0129] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0130] In the embodiments provided by the present invention, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0131] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0132] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0133] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, it can implement the steps of each of the above-mentioned method embodiments. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0134] The above are merely specific application examples of the present invention and do not constitute any limitation on the scope of protection of the present invention. In addition to the above embodiments, the present invention may also have other implementations. Any technical solution formed by equivalent replacement or equivalent transformation falls within the scope of protection claimed by the present invention.
Claims
1. A method for autonomously optimizing a lighting scheme for surface defect detection, characterized in that: Including steps: S1. Based on a preset lighting parameter grading rule, detection data is collected to construct a defect-lighting sequence database: the brightness parameters and angle parameters of the dome light source are both graded according to preset levels, the brightness parameters and angle parameters are combined into multiple lighting parameter sequences according to different levels, different defect image data of the target object surface corresponding to the dome light source under each lighting parameter sequence is obtained, and the defect image data is associated with the lighting parameter sequence to establish a defect-lighting sequence database; S2, segment the image and evaluate it, and build a mapping relationship model between various types of defects and lighting parameter sequences based on the decision tree: S21, using a pre-trained image segmentation model to segment the defect image data in the defect-lighting sequence database to generate segmented images of various types of defects on the surface of the target object; S22, performing quantitative comparison between the segmented image and a preset standard mask image, and evaluating the lighting quality of each lighting parameter sequence based on an evaluation index; S23, screening out combinations of lighting parameter sequences corresponding to various types of defects that meet preset quality conditions based on a preset lighting quality threshold, and establishing a mapping relationship model between various types of defects and lighting parameter sequences using a decision tree algorithm; S3, based on the mapping relationship model between various types of defects and lighting parameter sequences, uses an intelligent optimization algorithm to find the optimal lighting solution: S31, based on the mapping relationship model between each type of defect and the lighting parameter sequence, according to the defect type to be detected, within the combination range of the lighting parameter sequences corresponding to the defect type, a group of lighting parameter sequences is selected as a population individual, and a genetic algorithm is used to optimize the parameters. After the termination condition is met, the optimal parameter sequence is obtained, wherein the fitness function of the genetic algorithm is determined by the evaluation result obtained by real-time acquisition of image data corresponding to the parameter lighting scheme, segmentation using an image segmentation model, and comparison evaluation with a preset mask image; S32, using a particle swarm optimization algorithm to perform a local search within the parameter space of the optimal parameter sequence obtained by the genetic algorithm, and outputting a final light source parameter sequence after reaching a termination condition; wherein the fitness function of the particle swarm optimization algorithm is determined by an evaluation result obtained by real-time acquisition of image data corresponding to the parameter lighting scheme, segmentation using an image segmentation model, and comparison evaluation with a preset mask image; S4, guiding the actual industrial defect detection task based on the lighting solution corresponding to the light source parameter sequence obtained in step S3.
2. The method for autonomously optimizing a lighting scheme for surface defect detection according to claim 1, characterized in that: The termination conditions of step S31 and step S32 are both that the preset maximum number of iterations is reached.
3. The method for autonomously optimizing a lighting scheme for surface defect detection according to claim 2, characterized in that: The various defect image data include: knock defects on the surface of industrial parts, scratch defects on the surface of industrial parts, and pitting defects on the surface of industrial parts.
4. The method for autonomously optimizing a lighting scheme for surface defect detection according to claim 3, characterized in that: The pre-trained image segmentation model includes a SAM model.
5. The method for autonomously optimizing a lighting scheme for surface defect detection according to claim 4, characterized in that: The step S31 includes: S311, constructing an initial population using the selected lighting parameter sequence as a chromosome code; S312, the fitness function is a weighted result of the confidence score and the intersection-over-union ratio in the evaluation results obtained by real-time acquisition of defect image data corresponding to the parameter lighting scheme, segmentation using the image segmentation model, and comparison evaluation with the preset mask image: F(x)=w1·C(x)+w2·IoU(x) Where x represents the current light source parameter combination, C(x) represents the defect detection confidence score output by the image segmentation model, IoU(x) represents the intersection over union (IoU) of the segmentation result and the standard mask image, and w1 and w2 both represent weight coefficients. S313, iterative population evolution through selection, crossover, and mutation operations; S314: Output the optimal parameter sequence after reaching the preset maximum number of iterations.
6. The method for autonomously optimizing a lighting scheme for surface defect detection according to claim 5, characterized in that: The step S32 includes: S321, randomly initializing a group of particles in the parameter space of the optimal parameter sequence domain; S322, the fitness function is a weighted result of the confidence score and the intersection-over-union ratio in the evaluation results obtained by real-time acquisition of defect image data corresponding to the parameter lighting scheme, segmentation using the image segmentation model, and comparison evaluation with the preset mask image: F(x)=w1·C(x)+w2·IoU(x) Where x represents the current light source parameter combination, C(x) represents the defect detection confidence score output by the image segmentation model, IoU(x) represents the intersection over union (IoU) of the segmentation result and the standard mask image, and w1 and w2 both represent weight coefficients. S323, parameter fine-tuning through dual guidance of individual optimality and group optimality; S324: Output the final light source parameter sequence after the termination condition is met.
7. The method for autonomously optimizing a lighting scheme for surface defect detection according to claim 6, characterized in that: Before step S2, the following steps are also included: Construct a mask image of the preset target object surface defects: manually mark the defect contours of the surface image of the target object to be inspected and generate a grayscale mask image.
8. The method for autonomously optimizing a lighting scheme for surface defect detection according to claim 7, characterized in that: The evaluation indicators include: intersection-over-union ratio, Dice similarity coefficient, and pixel accuracy, among which, The calculation formula of the intersection-over-union ratio is: Where A represents the defect area segmented by the SAM model, B represents the defect area of the preset mask image, |A∩B| represents the number of pixels of the intersection of the defect area segmented by the SAM model and the defect area of the preset mask image, and |A∪B| represents the number of pixels of the union of the defect area segmented by the SAM model and the defect area of the preset mask image. The calculation formula of the Dice similarity coefficient is: Where A represents the defect area segmented by the SAM model, B represents the defect area of the preset mask image, and |A∩B| represents the number of pixels of the intersection between the defect area segmented by the SAM model and the defect area of the preset mask image; The calculation formula of the pixel accuracy is: Among them, TP represents the number of pixels correctly identified as defects, TN represents the number of pixels correctly identified as background, FP represents the number of pixels that mistakenly classify background as defects, and FN represents the number of pixels that mistakenly classify defects as background.
9. A system for autonomously optimizing lighting schemes for surface defect detection, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method for autonomously optimizing a lighting scheme for surface defect detection according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for autonomously optimizing a lighting scheme for surface defect detection according to any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Full-appearance detection method and system for automobile hexagonal anti-loosening fastening nut
CN121049275A