Light building material surface defect detection method and system
Through the improved YOLOv12 target detection model and preprocessing algorithm, the automation and accuracy issues of surface defect detection of lightweight building materials were solved, efficient defect detection was achieved, and detection accuracy and production efficiency were improved.
Patent Information
- Application Number
- CN202510705533.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-09-09
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing methods for detecting surface defects in building materials have low automation levels, limited detection range, and need to improve detection accuracy and efficiency, especially for lightweight building materials.
An improved YOLOv12 target detection model is used, combined with a contrast enhancement algorithm based on spatial entropy and bilateral filtering, to preprocess the surface images of lightweight building materials. Windmill convolution and attention mechanism are used to enhance feature extraction capabilities, achieving high-precision defect detection.
It improves the accuracy and efficiency of surface defect detection of lightweight building materials, reduces the damage to materials caused by human operation, and ensures the accuracy of detection and production efficiency.
Smart Images

Figure CN120612299A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields related to image recognition and target detection, and in particular to a method and system for detecting surface defects of lightweight building materials. Background Art
[0002] Surface defect detection of building materials is a critical step in ensuring their quality and performance. Surface defects can affect a material's aesthetics, durability, and connection to other materials. Surface defect detection allows for the timely detection and treatment of cracks, bubbles, scratches, and uneven coatings, thereby improving the overall quality and service life of the material.
[0003] Traditional methods for detecting surface defects in building materials, including visual inspection, microscopy, laser scanning, and infrared inspection, rely primarily on manual operation, utilizing inspection equipment, optical imaging principles, and physical properties. These methods have low automation levels and limited detection ranges. Existing inspection methods incorporate clustering algorithms and convolutional neural networks to process building material surface image data, achieving high-precision inspection. However, these algorithms are complex, computationally complex, and lack sufficient feature extraction capabilities, leaving much room for improvement in detection accuracy.
[0004] Lightweight building materials such as fly ash products are more susceptible to the influence of the environment and production operations, resulting in a large number of surface defects, affecting production efficiency and causing irreversible losses. There is an urgent need for a surface defect detection method with a high level of automation to ensure detection accuracy and efficiency, improve the yield rate of lightweight building materials, and avoid damage to the surface of lightweight building materials caused by improper human operation. Summary of the Invention
[0005] In response to the technical problems of the above-mentioned prior art, the present application provides a method and system for detecting surface defects of lightweight building materials. Based on the YOLOv12 target detection model, an improved feature extraction method is adopted to classify and locate defects in the pre-processed surface images of lightweight building materials, thereby achieving high-precision defect detection while effectively reducing the complexity of the model.
[0006] The present application provides a method for detecting surface defects of lightweight building materials, comprising:
[0007] (1) Obtain surface image data of lightweight building materials with defects from actual production environments and mark the surface defects;
[0008] (2) Preprocess the acquired surface images of lightweight building materials and use a contrast enhancement algorithm based on spatial entropy to improve image quality;
[0009] (3) The pre-processed surface image of lightweight building materials is input into the pre-trained improved YOLOv12 target detection model, and an efficient module is used to extract feature information to achieve the classification and location of surface defects of lightweight building materials;
[0010] (4) Based on the output results of the model, collect feedback information, adjust the model hyperparameters, and optimize and update the data set and model structure.
[0011] Furthermore, the process of collecting and annotating the surface image of lightweight building materials includes the following steps:
[0012] Place the lightweight building material with defects on a white background cloth;
[0013] Fix the industrial camera vertically above the material to capture its surface image, ensuring full coverage of defective areas;
[0014] Import the captured surface images of lightweight building materials into the annotation tool;
[0015] Use the rectangle tool to draw a bounding box around each defect and record the location coordinates of the bounding box;
[0016] Select corresponding defect category and defect attribute information for each bounding box;
[0017] The annotation results are saved in XML format and the data is stored in the local server.
[0018] Furthermore, the pre-processing steps of the collected lightweight building material surface images include cropping, contrast enhancement and noise suppression:
[0019] The collected surface images of lightweight building materials are cropped into graphics of the same size to meet the size requirements of the target detection model for input features.
[0020] The cropped image is processed using a contrast enhancement algorithm based on spatial entropy. This algorithm enhances the contrast of the image by considering the spatial distribution information of pixels, preventing image detail loss and noise amplification. The main steps of the algorithm are as follows:
[0021] Calculate the spatial histogram of each gray level of the image;
[0022] Calculate the spatial entropy of each gray level based on the spatial histogram;
[0023] Generate a distribution function through spatial entropy and map it to a uniform distribution function;
[0024] Mapping gray levels to new gray levels through cumulative distribution function to achieve global contrast enhancement;
[0025] Perform two-dimensional discrete cosine transform on the globally enhanced image;
[0026] The transformed coefficients are weighted to enhance the high-frequency components and achieve local contrast enhancement;
[0027] Finally, the enhanced image is obtained by inverse two-dimensional discrete cosine transform.
[0028] Bilateral filtering is used to combine spatial distance and pixel value difference weights to calculate the weighted average of the pixel value of each pixel in the image and the pixel values in its neighborhood to achieve noise suppression. For the pixel value I(x) of pixel x in the image, its filtered value I′(x) is expressed as:
[0029]
[0030] Among them, Ω is the neighborhood centered on x; x i are other pixels in the center neighborhood, I(x i ) represents its pixel value; is the spatial Gaussian kernel, used to calculate the spatial weight, and its standard deviation is σ s ; is the Gaussian kernel, which is used to calculate the pixel value weight, and its standard deviation is σ r ;W p is a normalization constant used to ensure that the weights sum to 1.
[0031] Since the weight of bilateral filtering takes into account the difference in pixel values, the pixels at the edge of the defect will not be over-smoothed, and more edge details of the surface defects of building materials will be retained.
[0032] Furthermore, the steps of obtaining a pre-trained object detection model include:
[0033] Apply data enhancement methods to process pre-processed surface images of lightweight building materials, expand the number of samples, and generate a data set;
[0034] Divide the dataset into training set, validation set and test set; build an improved target detection model based on YOLOv12;
[0035] The model is trained using the stochastic gradient descent method, with IoU loss selected as the positioning loss and focal loss as the classification loss.
[0036] Select the Adam optimizer, set the initial learning rate, and dynamically adjust the learning rate during training. Save the model parameters with the best performance as the pre-trained object detection model.
[0037] Furthermore, the improved YOLOv12 object detection model, primarily composed of a backbone network, a neck network, and a head network, utilizes attention as its core, replacing the convolutional neural network at the heart of the YOLO architecture. This model utilizes pinwheel convolutions to replace the convolution operations in the original YOLOv12 architecture, which better matches the Gaussian distribution of pixels found on the surfaces of small defects in lightweight building materials. This further enhances the convolutional feature extraction capabilities and increases the receptive field.
[0038] Furthermore, the backbone network improves the model's feature extraction capabilities through pinwheel convolution modules, C3K2 modules, and A2K2f modules. These modules all adopt a bottleneck structure consisting of three convolutional layers. The first convolution layer halves the number of channels in the input feature map, the second convolution layer extracts features, and the final convolution layer restores the number of channels before adding the result to the original input feature map for output.
[0039] The neck network is located between the backbone network and the head network, and uses upsampling and concatenation operations to achieve feature fusion and enhancement. The upsampling method is nearest neighbor interpolation, and the concatenation operation concatenates features of different scales along the channel dimension.
[0040] The head network is the decision-making part of the model, responsible for generating the final detection results. It receives multi-scale feature maps from the neck network and, through a decoupled detection head, processes bounding box regression and class prediction, respectively. For each location on each feature map, the head network generates bounding box coordinates, class probability, and confidence score. Non-maximum suppression is used to remove redundant bounding boxes, ultimately outputting the detection results.
[0041] The present application also provides a lightweight building material surface defect detection system, comprising:
[0042] Image acquisition and annotation module: used to obtain surface image data of lightweight building materials with defects from actual production environments and annotate surface defects;
[0043] Image preprocessing module: used to preprocess the acquired surface images of lightweight building materials and improve image quality using a contrast enhancement algorithm based on spatial entropy;
[0044] Surface Defect Detection Module: This module feeds pre-processed images of lightweight building material surfaces into a pre-trained improved YOLOv12 object detection model. It uses an efficient module to extract feature information to classify and locate surface defects in lightweight building materials.
[0045] Model optimization module: used to collect feedback information, adjust model hyperparameters, and optimize and update the data set and model structure based on the model's output results.
[0046] The present invention discloses the following technical effects:
[0047] The present invention proposes a method and system for detecting surface defects of lightweight building materials, and applies advanced target detection models to improve detection accuracy and efficiency. For the collected surface images of lightweight building materials, a contrast enhancement algorithm based on spatial entropy is adopted to increase the contrast by calculating the spatial distribution of pixels; a bilateral filtering method is adopted to remove noise in the image, and the edge details of the surface defect image of lightweight building materials are highlighted by calculating the weighted average value within the pixel neighborhood. The application of the above preprocessing method provides high-quality training samples for the model, which is the basis for ensuring detection accuracy. The present invention is based on the YOLOv12 target detection model, and introduces windmill convolution to replace the ordinary convolution in the structure, which only adds a very small amount of parameters to achieve the effect of expanding the receptive field and enhance the feature extraction ability of the model; YOLOv12 introduces an attention mechanism to replace the convolutional neural network in the traditional YOLO structure, which is used as the core module to implement temporal context modeling, provide global feature information for the target detection task, and further improve the classification and positioning accuracy of surface defects of lightweight building materials. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings of the embodiments of the present invention are briefly introduced 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 in precise order. Instead, various steps may be processed in reverse order or simultaneously as needed. Furthermore, other operations may be added to these processes, or one or more operations may be removed from these processes.
[0049] Figure 1 A schematic flow chart of a method for detecting surface defects of lightweight building materials provided in an embodiment of the present application.
[0050] Figure 2 Detailed structure diagram of the YOLOv12 target detection model provided in the embodiments of this application.
[0051] Figure 3 A schematic diagram of the structure of the key modules in the target detection model provided in the embodiment of the present application.
[0052] Figure 4 A schematic structural diagram of a lightweight building material surface defect detection system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below.
[0054] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0055] In the following description, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or modules that are not explicitly listed or are inherent to these processes, methods, products, or devices. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application belongs. The terms used herein are for the purpose of describing the embodiments of this application only.
[0056] Example 1: This application provides a method for detecting surface defects of lightweight building materials. Figure 1 As shown, the method includes:
[0057] Step S10: acquiring surface image data of lightweight building materials with defects from an actual production environment, and marking the surface defects.
[0058] In this embodiment, the process of collecting and annotating the surface image of the lightweight building material includes the following steps:
[0059] Place the lightweight building material with defects on a white background cloth;
[0060] Fix the industrial camera vertically above the material to capture its surface image, ensuring full coverage of defective areas: During the shooting process, set the light intensity, camera exposure time and resolution according to the reflective characteristics of the building material surface;
[0061] Import the captured surface image of the lightweight building material into the labeling tool: In this embodiment, professional labeling software Labeling is used to label the image data;
[0062] Use the rectangle tool to draw a bounding box around each defect and record the position coordinates of the four vertices of the bounding box;
[0063] Select the corresponding defect category and defect attribute information for each bounding box: defect categories include cracks, voids, and spalling, and assign a unique numeric identifier to each defect category as the category label; the boundary attributes include the length and width of the defect;
[0064] The annotation results are saved in XML format, and the data is stored in the local server, classified and stored according to material type, and an index system is established to achieve fast retrieval and call.
[0065] Step S20 , preprocessing the acquired surface image of the lightweight building material, and improving the image quality by using a contrast enhancement algorithm based on spatial entropy.
[0066] In this embodiment, the steps of preprocessing the collected lightweight building material surface image include cropping, contrast enhancement and noise suppression:
[0067] The collected surface images of lightweight building materials are cropped into graphics of the same size. All images are cropped to a size of 256×256 to meet the size requirements of the target detection model for input features.
[0068] The cropped image is processed using a contrast enhancement algorithm based on spatial entropy. This algorithm enhances the contrast of the image by considering the spatial distribution information of pixels, preventing image detail loss and noise amplification. The main steps of the algorithm are as follows:
[0069] Calculate the spatial histogram of each gray level of the image: divide the image evenly into M×N blocks, where M and N are the number of rows and columns of the spatial grid, and the size of each block is H and W are the height and width of the image, respectively, H = W = 256; for each gray level x k , calculate the number of occurrences in each block and generate a two-dimensional space histogram h k (m,n), where m and n represent the row index and column index respectively;
[0070] Calculate the spatial entropy of each gray level based on the spatial histogram: for each gray level x k , calculate its spatial entropy S k :
[0071]
[0072] in, is the normalized spatial histogram;
[0073] Generate a distribution function through spatial entropy and map it to a uniform distribution function: spatial entropy distribution function f k The calculation formula is as follows:
[0074]
[0075] Where K is the total number of gray levels in the image;
[0076] The grayscale is mapped to a new grayscale through the cumulative distribution function to achieve global contrast enhancement: the enhanced pixel value is obtained by the following calculation formula:
[0077]
[0078] Among them, x g (i, j) represents the pixel value after global enhancement, x(i, j) is the original pixel value, (i, j) represents the pixel coordinate, and round represents the rounding operation;
[0079] Perform two-dimensional discrete cosine transform on the globally enhanced image:
[0080]
[0081] Among them, d(k,l) represents the value of each pixel in the transformation image generated by two-dimensional discrete cosine transform, k,l are high-frequency components, c k and c l is the normalization coefficient;
[0082] The transformed coefficients are weighted to enhance the high-frequency components and achieve local contrast enhancement:
[0083]
[0084] in, is the cosine transform value after local enhancement, ω(k,l) is the weighting coefficient, and the higher the frequency of the high-frequency component, the higher the weight;
[0085] Finally, the enhanced image is obtained by inverse two-dimensional discrete cosine transform, and the value of each pixel in the enhanced image is y(i,j):
[0086]
[0087] Bilateral filtering is used to calculate the weighted average of the pixel value of each pixel in the image and the pixel values in its neighborhood by combining spatial distance and pixel value difference weights. For the pixel value I(x) of pixel x in the image, its filtered value I∑(x) is expressed as:
[0088]
[0089] Among them, Ω is the neighborhood centered on x; x i are other pixels in the center neighborhood, I(x i ) represents the pixel values of other pixels in the center neighborhood; is the spatial Gaussian kernel, used to calculate the spatial weight, and its standard deviation is σs ; is the Gaussian kernel, which is used to calculate the pixel value weight, and its standard deviation is σ r ;W p is a normalization constant used to ensure that the weights sum to 1.
[0090] Since the weight of bilateral filtering takes into account the difference in pixel values, the pixels at the edge of the defect will not be over-smoothed, and more edge details of the surface defects of building materials will be retained.
[0091] In step S30 , the pre-processed surface image of the lightweight building material is input into the pre-trained improved YOLOv12 target detection model, and an efficient module is used to extract feature information to achieve classification and positioning of surface defects of the lightweight building material.
[0092] In this embodiment, the step of obtaining a pre-trained object detection model includes:
[0093] Data augmentation methods are applied to the pre-processed surface images of lightweight building materials to expand the number of samples and generate a dataset. The data augmentation methods include:
[0094] Rotation: Rotate the image at random angles in the range of [-30°, 30°];
[0095] Flip: flip the image horizontally and vertically;
[0096] Random erasing: Randomly erase part of the defective image and set the pixel values of the defective part to 0 to simulate occlusion;
[0097] Mixing enhancement: Mix two images in a certain proportion to generate a new image;
[0098] The dataset is divided into training set, validation set and test set with a ratio of 7:1:1. The training set is used to train the model, the validation set is used to adjust the model's hyperparameters and select the best model, and the test set is used to evaluate the model's performance.
[0099] Build an improved target detection model based on YOLOv12;
[0100] The model is trained using the stochastic gradient descent method. The IoU loss is selected as the positioning loss of the model, and the focal loss is selected as the classification loss of the model. The calculation formula of the focal loss is as follows:
[0101]
[0102] Among them, α is the category weight, γ is the adjustment parameter, is the predicted category probability, and y is the true label;
[0103] Select the Adam optimizer, set the initial learning rate, and dynamically adjust the learning rate during training. Save the model parameters with the best performance as the pre-trained object detection model.
[0104] In this embodiment, the improved YOLOv12 object detection model is primarily composed of a backbone network, a neck network, and a head network. It uses attention as its core, replacing the convolutional neural network at the heart of the YOLO architecture, resulting in faster inference speed and higher detection accuracy. The model replaces the convolution operation in the original YOLOv12 architecture with a pinwheel convolution, which better matches the Gaussian distribution of pixels typical of small defects on the surfaces of lightweight building materials. This further enhances the convolutional feature extraction capability and increases the receptive field.
[0105] Step S40: Based on the output results of the model, feedback information is collected, model hyperparameters are adjusted, and the data set and model structure are optimized and updated.
[0106] Example 2: This application embodiment provides a method for detecting surface defects of lightweight building materials, and the detailed structure of the improved YOLOv12 target detection model, such as Figure 2 As shown:
[0107] In this embodiment, the backbone network improves the model's feature extraction capabilities through the pinwheel convolution module, the C3K2 module, and the A2K2f module. These modules all employ a bottleneck architecture consisting of three convolutional layers. The first convolution layer halves the number of channels in the input feature map. The second convolution layer extracts features, and the final convolution layer restores the number of channels before adding the result to the original input feature map.
[0108] Pinwheel convolution uses asymmetric padding to create horizontal and vertical convolution kernels for different areas of the image. The convolution kernels spread outward to increase the receptive field:
[0109] Assume that the input features are h1, w1, c1 represent the height, width and channel size respectively. To stabilize the training process and accelerate the training, batch normalization and SiLU activation function are applied after each convolution layer;
[0110] The first convolution layer of the windmill convolution module uses a parallel approach to output four feature maps of size h′×w′×c∑ to Acquire feature information in different directions, and the receptive field area is shaped like a windmill. The calculation formula is as follows:
[0111]
[0112] in, is the convolution operator, SiLU represents the activation function, BN represents the batch normalization operation, W1 (1,3,c′) 、W2 (3 ,1,c′) 、W3 (1,3,c′) and W4 (3,1,c′) They are asymmetric convolution kernels of sizes 1 × 3, 3 × 1, 1 × 3, and 3 × 1. The padding parameter P(0, 1, 0, 3) represents the number of padding pixels in the left, right, top, and bottom directions, respectively;
[0113] The output results of the first layer of convolution are concatenated and the output is calculated as:
[0114]
[0115] Among them, Cat represents the channel splicing operation; the spliced features are normalized by convolution without padding, and the height and width of the output feature map are adjusted to the preset values h2 and w2. The final output The calculation is as follows:
[0116]
[0117] in, represents a convolution kernel of size 2×2, s is the convolution stride.
[0118] The convolution module in YOLOv12 is replaced with a pinwheel convolution module, which acts as a channel attention mechanism to calculate the contribution of different convolution directions. This utilizes grouped convolutions to significantly increase the receptive field while minimizing the number of parameters. Furthermore, the effectiveness of the receptive field gradually decreases from the outside, similar to a Gaussian distribution. Smaller objects have more concentrated features, highlighting the importance of central features and enabling the model to detect small defects.
[0119] The detailed structure of the C3K2 module is as follows Figure 3 As shown in the upper part, the module primarily consists of a bottleneck structure and residual units. All convolutions in the module use standard convolutions, compressing and expanding the number of channels. The input features are first split into two parts. One part is passed through three stacked residual units to extract feature information, while the other part is concatenated with the output features of the residual units as a residual connection to form the output features of the C3K2 module.
[0120] The detailed structure of the A2K2f module is as follows Figure 3As shown in the lower part, an efficient regional attention mechanism is introduced to reduce computational complexity. The feature map is divided into multiple regions horizontally or vertically. A simple reshape operation is used to calculate the attention weight for each region, avoiding complex window partitioning. The weighted sum of the features in each region is then used to generate the global feature. Regional attention reduces computational cost by a factor of four, enabling the model to dynamically identify and focus on the most informative regions within the feature map, focusing on defect characteristics and further improving defect detection accuracy.
[0121] The neck network is located between the backbone network and the head network, and uses upsampling and concatenation operations to achieve feature fusion and enhancement. The upsampling method is nearest neighbor interpolation, and the concatenation operation concatenates features of different scales along the channel dimension.
[0122] The head network is the decision-making part of the model, responsible for generating the final detection results. It receives multi-scale feature maps from the neck network and, through a decoupled detection head, processes bounding box regression and class prediction, respectively. For each location on each feature map, the head network generates bounding box coordinates, class probability, and confidence score. Non-maximum suppression is used to remove redundant bounding boxes, ultimately outputting the detection results.
[0123] Example 3: A light-weight building material surface defect detection system provided by an embodiment of the present invention can execute a light-weight building material surface defect detection method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. The system structure is as follows: Figure 4 As shown:
[0124] Image acquisition and annotation module: used to obtain surface image data of lightweight building materials with defects from actual production environments and annotate surface defects;
[0125] Image preprocessing module: used to preprocess the acquired surface images of lightweight building materials and improve image quality using a contrast enhancement algorithm based on spatial entropy;
[0126] Surface Defect Detection Module: This module feeds pre-processed images of lightweight building material surfaces into a pre-trained improved YOLOv12 object detection model. It uses an efficient module to extract feature information to classify and locate surface defects in lightweight building materials.
[0127] Model optimization module: used to collect feedback information, adjust model hyperparameters, and optimize and update the data set and model structure based on the model's output results.
[0128] Although the present application makes various references to certain modules in the system according to the embodiments of the present application, any number of different modules may be used and run on the user terminal and / or server, and the various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other and are not used to limit the scope of protection of the present invention.
[0129] The above specific embodiments do not constitute a limitation to the scope of protection of this application. It should be understood by those skilled in the art that various modifications, combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of this application should be included in the scope of protection of this application. In some cases, the actions or steps recorded in this application can be performed in an order different from that in the embodiments and can still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Claims
1. A method for detecting surface defects of lightweight building materials, characterized in that: The method comprises: (1) Obtain surface image data of lightweight building materials with defects from actual production environments and mark the surface defects; (2) Preprocess the acquired surface images of lightweight building materials and use a contrast enhancement algorithm based on spatial entropy to improve image quality; (3) The pre-processed surface image of lightweight building materials is input into the pre-trained improved YOLOv12 target detection model, and an efficient module is used to extract feature information to achieve the classification and location of surface defects of lightweight building materials; (4) Based on the output results of the model, collect feedback information, adjust the model hyperparameters, and optimize and update the dataset and model structure.
2. A method for detecting surface defects of lightweight building materials according to claim 1, characterized in that: In step (1), the process of collecting and annotating the surface image of the lightweight building material includes the following steps: Place the lightweight building material with defects on a white background cloth; Fix the industrial camera vertically above the material to capture its surface image, ensuring full coverage of defective areas; Import the captured surface images of lightweight building materials into the annotation tool; Use the rectangle tool to draw a bounding box around each defect and record the location coordinates of the bounding box; Select corresponding defect category and defect attribute information for each bounding box; The annotation results are saved in XML format and the data is stored in the local server.
3. A method for detecting surface defects of lightweight building materials according to claim 1, characterized in that: In step (2), the steps of preprocessing the collected surface image of the lightweight building material include cropping, contrast enhancement and noise suppression.
4. A method for detecting surface defects of lightweight building materials according to claim 3, characterized in that: The collected surface image of lightweight building materials is cropped to a specified size. The cropped image is processed using a contrast enhancement algorithm based on spatial entropy. This algorithm enhances the contrast of the image by considering the spatial distribution information of pixels. The main steps of the algorithm are as follows: Calculate the spatial histogram of each gray level of the image; Calculate the spatial entropy of each gray level based on the spatial histogram; Generate a distribution function through spatial entropy and map it to a uniform distribution function; Mapping gray levels to new gray levels through cumulative distribution function to achieve global contrast enhancement; Perform two-dimensional discrete cosine transform on the globally enhanced image; The transformed coefficients are weighted to enhance the high-frequency components and achieve local contrast enhancement; Finally, the enhanced image is obtained by inverse two-dimensional discrete cosine transform.
5. A method for detecting surface defects of lightweight building materials according to claim 3, characterized in that: Bilateral filtering is used to combine spatial distance and pixel value difference weights to calculate the weighted average of the pixel value of each pixel in the image and the pixel values in its neighborhood to achieve noise suppression; for the pixel value I(x) of the x pixel in the image, its filtered value I ′ (x) is expressed as: Among them, Ω is the neighborhood centered on x; x i are other pixels in the center neighborhood, I(x i ) represents the pixel values of other pixels in the center neighborhood; is the spatial Gaussian kernel, used to calculate the spatial weight, and its standard deviation is σ s ; is the Gaussian kernel, which is used to calculate the pixel value weight, and its standard deviation is σ r ;W p is a normalization constant used to ensure that the weights sum to 1.
6. A method for detecting surface defects of lightweight building materials according to claim 1, characterized in that: In step (3), the step of obtaining a pre-trained target detection model includes: Apply data enhancement methods to process pre-processed surface images of lightweight building materials, expand the number of samples, and generate a data set; Divide the dataset into training, validation, and test sets; Build an improved target detection model based on YOLOv12; The model is trained using the stochastic gradient descent method, with IoU loss selected as the positioning loss and focal loss as the classification loss. Select the Adam optimizer, set the initial learning rate, and dynamically adjust the learning rate during training. Save the model parameters with the best performance as the pre-trained object detection model.
7. A method for detecting surface defects of lightweight building materials according to claim 6, characterized in that: The improved YOLOv12 target detection model is mainly composed of a backbone network, a neck network, and a head network. It takes attention as the core and replaces the core position of the convolutional neural network in the YOLO structure. The model uses windmill convolution to replace the convolution operation in the original YOLOv12 structure, which conforms to the Gaussian distribution of tiny target defect pixels on the surface of lightweight building materials.
8. A method for detecting surface defects of lightweight building materials according to claim 7, characterized in that: The backbone network extracts feature representations through the pinwheel convolution module, the C3K2 module, and the A2K2f module. These modules all adopt a bottleneck structure consisting of three convolutional layers. The first convolution layer halves the number of channels in the input feature map, the second convolution layer extracts features, and the last convolution layer restores the number of channels and adds them to the original input feature map for output. The neck network is located between the backbone network and the head network, and applies upsampling and splicing operations to achieve feature fusion and enhancement; the upsampling method is nearest neighbor interpolation; the splicing operation splices features of different scales along the channel dimension; The head network is the decision-making part of the model, responsible for generating the final detection results. The head network receives multi-scale feature maps from the neck network and processes bounding box regression and category prediction separately through a decoupled detection head. For each position on each feature map, the head network generates bounding box coordinates, category probability, and confidence score. Non-maximum suppression is used to remove redundant bounding boxes and finally output the detection results.
9. A system for detecting surface defects of lightweight building materials, characterized in that: The system is used to implement the method for detecting surface defects of lightweight building materials according to any one of claims 1 to 8, and the system comprises: Image acquisition and annotation module: used to obtain surface image data of lightweight building materials with defects from actual production environments and annotate surface defects; Image preprocessing module: used to preprocess the acquired surface images of lightweight building materials and improve image quality using a contrast enhancement algorithm based on spatial entropy; Surface Defect Detection Module: This module feeds pre-processed images of lightweight building material surfaces into a pre-trained improved YOLOv12 object detection model. It uses an efficient module to extract feature information to classify and locate surface defects in lightweight building materials. Model optimization module: used to collect feedback information, adjust model hyperparameters, and optimize and update the data set and model structure based on the model's output results.
Citation Information
Cited By
Battery shell surface defect detection method based on frequency domain enhancement and dynamic region attention
CN122244020A