Vehicle lamp lens flaw detection method and system based on traditional image processing
Traditional image processing techniques are used to enhance car lamp defect detection by focusing on specific regions and adapting to ambient light, addressing the inefficiencies of current methods by reducing computational load and improving precision without the need for extensive data sets or frequent model updates.
Patent Information
- Application Number
- CN202411755556.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-12-03
AI Technical Summary
Current car lamp defect detection technologies require extensive data sets, time-consuming sample labeling, and frequent model retraining when background conditions change, limiting their applicability and efficiency.
A method and system utilizing traditional image processing techniques, including local binaryization, gradient analysis, and adaptive thresholding, to extract and evaluate car lamp lens defects, reducing computational load and enhancing accuracy by focusing on specific regions of interest and minimizing the impact of ambient light.
This approach effectively reduces computational burden, enhances defect detection precision, and avoids the need for large data sets and frequent model retraining, improving adaptability and efficiency compared to deep learning methods.
Smart Images

Figure CN119693324A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of industrial intelligent production detection technology, and in particular to a method and system for detecting defects in a headlight lens based on traditional image processing. Background Art
[0002] The technology of headlight defect detection mainly involves computer vision technology and image processing technology. Computer vision technology is a technology that obtains the image of an object through a camera or video camera, and then processes and analyzes the image to achieve object recognition, tracking, measurement and control. Image processing technology is a technology that analyzes, processes, extracts features and classifies images. In the detection of headlight defects, it is first necessary to design a lighting imaging scheme based on the material and structural characteristics of the part to be detected of the headlight, and design a supporting device structure for the scheme. This structure can work in conjunction with the processing and control module to perform a full range of inspections on the headlights.
[0003] Automobile lights play an important role in road lighting, driving status prompts, vehicle appearance and other aspects. Therefore, headlight detection is also an important part of automobile factory inspection. Headlight detection mainly detects the light distribution performance of automobile headlights and the functional status of the whole vehicle lights. With the rapid development of the automobile industry, headlight defect detection technology is also constantly updated and improved. At present, some advanced headlight defect detection systems have been able to achieve automatic and intelligent detection. These systems can not only improve detection efficiency, but also reduce human errors and improve the accuracy of detection results. For example, the automatic headlight defect detection system based on machine vision can automatically identify and locate headlight defects by performing high-speed and high-precision image acquisition of headlights, and then using computer vision technology and image processing technology to analyze and process the images.
[0004] In addition, with the development of artificial intelligence technology, deep learning technology has also been introduced into headlight defect detection. By training a large amount of headlight image data, the deep learning model can learn the characteristic representation of headlight defects, thereby achieving high-precision recognition of headlight defects. This method can not only improve the accuracy of detection, but also cope with various complex types of headlight defects, and has high practical value. However, this detection technology requires a large number of data sets and takes time to annotate samples, which is time-consuming and labor-intensive. When the background changes, the model needs to be retrained, and its applicability is not high.
[0005] The above problems need to be solved urgently. Summary of the invention
[0006] The purpose of the present invention is to provide a method and system for detecting defects in a headlight lens based on traditional image processing, so as to solve the technical problems existing in the prior art, such as the need for a large number of data sets, the need to spend time to label samples, the time-consuming and labor-intensive process, the need to retrain the model when the background changes, and the low applicability.
[0007] In order to solve the above technical problems, on the one hand, the present invention provides a method for detecting defects in a headlight lens based on traditional image processing, the method comprising: S1: collecting an original image of a headlight lens through a camera; S2: preprocessing the original image to obtain a first image; S3: extracting a region of interest in the first image using a local binarization method to generate an ROI image, wherein the ROI image only contains information about the headlight lens; S4: performing single-channel overlay processing on the ROI image to enhance the contrast of defects in the ROI image to obtain a second image; S5: using OpenCV to segment the target by taking the average threshold of three regions for the environment near the halo of the central light source of the second image. ; S6: stitching the three segmented target areas and removing the halo of the central light source of the second image to obtain the third image; S7: adaptively segmenting the third image through the image binarization segmentation threshold algorithm, and restoring the segmented information to the second image; S8: preliminarily judging whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with the preset pixel threshold; S9: in response to the headlight lens being a qualified product, grayscale processing is performed on the ROI image, and then the horizontal and vertical gradient information are extracted to obtain the fourth image and the fifth image respectively; S10: median filtering is performed on the fourth image and the fifth image to remove random noise respectively; S11: by using OpenCV The thresholding method of the big law in OpenCV is improved, and the fourth image and the fifth image after the noise is filtered out are respectively threshold segmented based on the custom threshold obtained by the improved big law thresholding method to obtain the sixth image and the seventh image; S12: the sixth image and the seventh image are ANDed to obtain the eighth image; S13: in response to the headlight lens being a qualified product, the ROI image is gray-scaled and the gradient information in the left oblique angle of 45° and the right oblique angle of 45° is extracted to obtain the ninth image and the tenth image respectively; S14: the ninth image and the tenth image are respectively median filtered to filter out random noise; S15: by improving the thresholding method of the big law in OpenCV, based on the improved big law thresholding method The custom threshold value obtained by the value method is used to perform threshold segmentation on the ninth image and the tenth image after the noise is filtered out to obtain the eleventh image and the twelfth image respectively; S16: performing an AND operation on the eleventh image and the twelfth image to obtain the thirteenth image; S17: performing an AND operation on the thirteenth image and the eighth image to obtain the fourteenth image; S18: morphologically processing the fourteenth image to merge the objects with similar distances in the fourteenth image to obtain the fifteenth image; S19: performing an AND operation on the fifteenth image through a custom mask to obtain the sixteenth image; S20: extracting the ROI information retained in the sixteenth image; S21: judging the qualification of the headlight lens based on the ROI information.
[0008] Furthermore, the step S2: preprocessing the original image to obtain the first image includes: S201: rotating the original image at a custom angle; S202: manually positioning the rotated original image to obtain the first image.
[0009] The further step S3: using the local binarization method to extract the region of interest in the first image to generate a ROI image, wherein the ROI image only contains the headlight lens information, includes: using OpenCv based on the first image to find the maximum connected domain, and performing ROI extraction on it to obtain the ROI image.
[0010] Furthermore, the step S6: splicing the three target areas after segmentation and then removing the halo of the central light source of the second image to obtain the third image includes: S601: using the existing interface of Opencv to obtain the three target areas; S602: when calculating the first target area, the grayscale values corresponding to the second target area and the third target area are set to black; S603: the grayscale of the first target area minus the zero component is the first target area to be obtained; S604: when calculating the second target area, the grayscale values corresponding to the first target area and the third target area are set to black; S605: the grayscale of the second target area minus the zero component is the second target area to be obtained; S606: when calculating the third target area, the grayscale values corresponding to the first target area and the second target area are set to black; S607: the grayscale of the third target area minus the zero component is the third target area to be obtained.
[0011] Furthermore, the step S8: preliminarily judging whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with the preset pixel threshold includes: S801: in response to the restored second image containing pixel points whose pixel values are greater than the preset pixel threshold, directly judging the headlight lens as an unqualified product; S802: in response to the pixel value corresponding to each pixel point in the restored second image being less than the preset pixel threshold, go to step S9.
[0012] Furthermore, the gradient information extraction formula in step S9 is:
[0013]
[0014] In the formula, f x (x,y) represents the pixel value on the x-axis corresponding to the pixel point (x, y). Represents the pixel variable in the x-axis direction, f y (x,y) represents the pixel value on the y-axis corresponding to the pixel point (x, y). A variable representing pixels in the y-axis direction.
[0015] Furthermore, the step S11: by improving the big law threshold method in OpenCV, based on the custom threshold value obtained by the improved big law threshold method, the fourth image and the fifth image after the noise is filtered out are respectively threshold segmented to obtain the sixth image and the seventh image, including: S1101: performing the operations of steps S1101-S1107 on the fourth image and the fifth image respectively; S1102: calculating the normalized histogram of the image, using P i , i=1,2,3,...255 represents each component of the histogram; S1103: Calculate the cumulative sum P I (k) S1104: Calculate the cumulative mean m(k), S1105: Calculate the global grayscale mean m G ; S1106: Calculate inter-class variance S1107: Obtaining a custom threshold k based on the inter-class variance * ,include: The maximum k value is the custom threshold k * If the maximum value is not unique, take the average value of each k value corresponding to each maximum value as the custom threshold k * ; S1108: Based on the custom threshold k * The fourth image and the fifth image after the noise is filtered out are respectively subjected to threshold segmentation to obtain the sixth image and the seventh image.
[0016] Furthermore, the step S21: judging the qualification of the headlight lens based on the ROI information includes: S2101: counting the number of pixels occupied by each ROI information and comparing it with a preset pixel threshold; S2102: judging the qualification of the headlight lens based on the comparison result.
[0017] Furthermore, the step S2102: judging the qualification of the headlight lens based on the comparison result includes: S21021: judging that the headlight lens is unqualified in response to the fact that the number of pixels occupied by each statistical ROI information is greater than a preset pixel threshold; S21022: judging that the headlight lens is qualified in response to the fact that the number of pixels occupied by each statistical ROI information is less than a preset pixel threshold.
[0018] In a second aspect, the present invention provides a headlight lens defect detection system based on traditional image processing, the system adopts the above-mentioned headlight lens defect detection method based on traditional image processing, and the system includes: an image acquisition module, suitable for acquiring the original image of the headlight lens through a camera; an image preprocessing module, suitable for preprocessing the original image to obtain a first image; a ROI image generation module, suitable for extracting the region of interest in the first image using a local binarization method to generate an ROI image, the ROI image only contains the headlight lens information; a second image generation module, suitable for performing single-channel overlay processing on the ROI image to enhance the contrast of defects in the ROI image to obtain a second image. The invention relates to a method for generating a third image of a vehicle headlamp; a target segmentation module, which is used to segment the environment near the halo of the central light source of the second image by taking the average threshold of three areas through OpenCV to segment the target; a module for generating a third image, which is used to splice the three segmented target areas and then remove the halo of the central light source of the second image to obtain the third image; an adaptive segmentation module, which is used to adaptively segment the third image through an image binarization segmentation threshold algorithm and restore the segmented information to the second image; a first judgment module, which is used to preliminarily judge whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with the preset pixel threshold; a gradient information extraction module, which is used to respond to the headlight lens being a qualified product and to perform a segmentation on the third image. After the ROI image is gray-scaled, the horizontal and vertical gradient information are extracted to obtain the fourth image and the fifth image respectively; in response to the headlight lens being a qualified product, the ROI image is gray-scaled, and the gradient information in the left oblique angle of 45° and the right oblique angle of 45° are extracted to obtain the ninth image and the tenth image respectively; a noise filtering module is used to perform median filtering on the fourth image and the fifth image to filter out random noise; and the ninth image and the tenth image are used to perform median filtering on the ninth image and the tenth image to filter out random noise; a threshold segmentation module is used to improve the large law threshold method in OpenCV, and obtain the custom threshold based on the improved large law threshold method to filter out the fourth image and the tenth image after the noise is filtered out. The fifth image is threshold segmented to obtain a sixth image and a seventh image; the great law threshold method in OpenCV is improved, and the custom threshold value obtained by the improved great law threshold method is used to perform threshold segmentation on the ninth image and the tenth image after the noise is filtered out to obtain an eleventh image and a twelfth image; a sum operation module is used to perform a sum operation on the sixth image and the seventh image to obtain an eighth image; the eleventh image and the twelfth image are summed to obtain a thirteenth image; the thirteenth image and the eighth image are summed to obtain a fourteenth image; a morphological processing module is used to perform morphological processing on the fourteenth image to merge objects with similar distances in the fourteenth image to obtain a fifteenth image;A mask processing module, adapted to process the fifteenth image through a custom mask to obtain a sixteenth image; a ROI information extraction module, adapted to extract the ROI information retained in the sixteenth image; a second judgment module, adapted to judge the qualification of the headlight lens based on the ROI information. ;
[0019] In a third aspect, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores one or more instructions, wherein the computer instructions are used to enable the computer to execute the above-mentioned vehicle headlight lens defect detection method based on traditional image processing.
[0020] In a fourth aspect, the present invention provides an electronic device, comprising: a memory and a processor; the memory stores at least one program instruction; the processor implements the above-mentioned vehicle headlight lens defect detection method based on traditional image processing by loading and executing the at least one program instruction.
[0021] The beneficial effects of the present invention are:
[0022] (1) The ROI image is obtained by finding the maximum connected domain in the image. By performing subsequent operations only on the region of interest, the amount of computational effort in subsequent image processing can be effectively reduced and the accuracy of image processing can also be improved.
[0023] (2) The three regions in the image are binarized and segmented using three thresholds. The halo removal operation can prevent the halo caused by reflected light from affecting subsequent image recognition and image processing.
[0024] (3) By summing up the gradient information in the four directions of horizontal, vertical, left angle 45°, and right angle 45°, the image is edge detected, which can effectively feedback the rate of change of the image grayscale.
[0025] (4) By removing a certain component to obtain the class segmentation threshold, we can effectively avoid the grayscale value of most backgrounds in the gradient information image being 0. If we directly use the Otsu method in OpenCV to obtain the threshold to segment the image, the segmentation effect will be unsatisfactory.
[0026] (5) By adopting traditional image processing methods, we can effectively avoid the problems brought about by the use of deep learning models in existing technologies to process images, such as the need for a large data set, the time required to label samples, the time-consuming and labor-intensive process, and the need to retrain the model when the background changes, and the low applicability. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0028] Figure 1 This is a flow chart of a method for detecting defects in a headlight lens based on traditional image processing provided in Example 1 of the present invention.
[0029] Figure 2 This is a schematic diagram of an original image of a headlight lens captured by a camera provided in Example 1 of the present invention.
[0030] Figure 3 This is a first image schematic diagram provided by Embodiment 1 of the present invention.
[0031] Figure 4 This is a schematic diagram of a ROI image provided by Example 1 of the present invention.
[0032] Figure 5 This is a schematic diagram of a second image provided by Embodiment 1 of the present invention.
[0033] Figure 6 This is a schematic diagram of a third image provided by Embodiment 1 of the present invention.
[0034] Figure 7 It is a schematic diagram of target segmentation using three target areas in the vicinity of the halo provided by Example 1 of the present invention.
[0035] Figure 8 It is a schematic diagram of a headlight lens provided by Embodiment 1 of the present invention when there are noise points in the headlight lens.
[0036] Figure 9a This is a fourth image schematic diagram provided by Embodiment 1 of the present invention.
[0037] Figure 9b This is a sixth image schematic diagram provided by Embodiment 1 of the present invention.
[0038] Fig.10a This is a fifth image schematic diagram provided by Embodiment 1 of the present invention.
[0039] Fig.10b This is a seventh image schematic diagram provided by Embodiment 1 of the present invention.
[0040] Fig.11 This is an eighth image schematic diagram provided by Embodiment 1 of the present invention.
[0041] Fig.12a This is a ninth image schematic diagram provided by Embodiment 1 of the present invention.
[0042] Figure 12b This is an eleventh image schematic diagram provided by Embodiment 1 of the present invention.
[0043] Fig.13aThis is a tenth image schematic diagram provided by Embodiment 1 of the present invention.
[0044] Fig.13b This is a twelfth image schematic diagram provided by Embodiment 1 of the present invention.
[0045] Fig.14 This is a thirteenth image schematic diagram provided by Embodiment 1 of the present invention.
[0046] Fig.15 This is a fourteenth image schematic diagram provided by Embodiment 1 of the present invention.
[0047] Fig.16 This is a fifteenth image schematic diagram provided by Example 1 of the present invention.
[0048] Fig.17 This is a schematic diagram of a custom mask shape provided in Example 1 of the present invention.
[0049] Fig.18 This is a sixteenth image schematic diagram provided by Embodiment 1 of the present invention.
[0050] Fig.19 This is a schematic diagram of a vehicle lamp lens defect detection result provided in Example 1 of the present invention.
[0051] Fig. 20 It is a schematic diagram of a vehicle headlight lens defect detection structure based on traditional image processing provided by Example 2 of the present invention.
[0052] Fig.21 This is a partial block diagram of an electronic device provided in Example 4 of the present invention. DETAILED DESCRIPTION
[0053] It should be mentioned before discussing the exemplary embodiments in more detail that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the operations as sequential processes, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0054] It should be understood that, although the terms "first", "second", etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are used only to distinguish one unit from another unit. For example, without departing from the scope of the exemplary embodiments, the first unit may be referred to as the second unit, and similarly the second unit may be referred to as the first unit. The term "and / or" used herein includes any and all combinations of one or more of the listed associated items.
[0055] The present invention will now be described in detail with reference to the accompanying drawings. This figure is a simplified schematic diagram, which only illustrates the basic structure of the present invention in a schematic manner, and therefore only shows the components related to the present invention.
[0056] In order to facilitate subsequent understanding, the professional terms appearing in the following embodiments are explained here:
[0057] OpenCV: (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. It provides a variety of image processing and computer vision functions and is widely used in academic research, industrial production, and commercial products.
[0058] Mask: Use a selected image, graphic or object to block the processed image (all or part) to control the area or process of image processing. The specific image or object used for covering is called a mask or template. In optical image processing, masks can be films, filters, etc.
[0059] ROI: (region of interest), region of interest.
[0060] Example 1
[0061] For ease of understanding, the invention concept is generally described before describing the embodiments of the present invention in detail: first, the original image of the lampshade surface is collected, and the angle of the original image is adaptively adjusted; the local adaptive binarization method is used to extract the sample ROI of interest in the original image; the contrast of the defect in the image background is increased by channel superposition; due to the limitations of the bright light environment, the light source forms a reflection area in the center of the inspected piece, and it is necessary to perform a preliminary detection on the area first. If no abnormal points or areas are found in the reflection area, all information in the area is filtered out and does not participate in the next step of detection. At this time, image T is obtained; image T is adaptively segmented, the binarized image is processed with the image ROI, and the inspected piece is detected for noise points through the pixel value of a certain pixel. If the pixel value of a certain pixel is greater than the set threshold, there are noise points, and the inspected piece is not a defective product. If not, a miscellaneous material area detection is performed.
[0062] The algorithm steps of foreign material detection are as follows: 1. Extract the transverse gradient information in the ROI of the inspected object, and then use the median filter to filter the random noise in the transverse gradient information map, and finally use the adaptive threshold to perform binary segmentation on the filtered gradient information map to obtain image X; 2. Extract the longitudinal gradient information in the ROI of the inspected object, and then use the median filter to filter the random noise in the longitudinal gradient information map, and finally use the adaptive threshold to perform binary segmentation on the filtered gradient information map to obtain image Y; 3. Extract the left oblique 45° gradient information in the ROI of the inspected object, and then use the median filter to filter the left oblique 45° gradient information. Filter the random noise in the 45° gradient information map at the right angle, and finally use the adaptive threshold to perform binary segmentation on the filtered gradient information map to obtain image L; 4. Extract the right oblique 45° gradient information in the ROI of the inspected part, and then use the median filter to filter the random noise in the right oblique 45° gradient information map, and finally use the adaptive threshold to perform binary segmentation on the filtered gradient information map to obtain image R; 5. Perform the sum operation on the four images X, Y, L, and R to form the final binary image to obtain image W; 6. Perform edge filtering on image W through a custom mask, and do not detect defects in the edge area. 7. Finally, the impurities are judged by calculating the area of each highlight block in the image. If there is a highlight block with an area greater than the set threshold, the inspected part is a defective product. If there is no highlight block with an area greater than the set threshold, the inspected part is a qualified part.
[0063] The specific implementation is as follows:
[0064] like Figure 1 As shown, it is a flow chart of a method for detecting defects of a headlight lens based on traditional image processing provided by the present invention.
[0065] As an example, the method includes:
[0066] S1: Collect the original image of the headlight lens through the camera.
[0067] Preferably, reference Figure 2 Schematic diagram of the original image, the step S1: collecting the original image of the headlight lens by means of a camera includes: collecting the original image of the entire lens by means of a high-precision industrial camera.
[0068] S2: Preprocess the original image to obtain a first image.
[0069] Preferably, the step S2: preprocessing the original image to obtain the first image comprises: S201: rotating the original image by a custom angle; S202: manually positioning the rotated original image to obtain the first image. Figure 3The figure shows a schematic diagram of the first image. The original image is rotated at a custom angle, usually 60°. The sample in the original image is manually positioned. This positioning is a rough positioning, and pixel cropping is performed with the center after rotation in step S202 as the origin.
[0070] S3: extracting a region of interest in the first image by using a local binarization method to generate a ROI image, wherein the ROI image only contains the headlight lens information.
[0071] Preferably, reference Figure 4 The figure shows a schematic diagram of the ROI image, wherein the step S3: extracting the region of interest in the first image by using the local binarization method to generate the ROI image, wherein the ROI image only contains the headlight lens information, comprises: finding the maximum connected domain based on the first image by using OpenCv, and performing ROI extraction on it to obtain the ROI image.
[0072] S4: performing single-channel overlay processing on the ROI image to enhance the contrast of defects in the ROI image to obtain a second image.
[0073] S5: Using OpenCV, an average threshold of three regions is taken to perform target segmentation on the environment near the halo of the central light source of the second image.
[0074] S6: splicing the three segmented target areas and removing the halo of the central light source of the second image to obtain a third image.
[0075] Preferably, reference Figure 5-6 They are respectively the schematic diagram of the second image and the schematic diagram of the third image, combined Figure 7 As shown, the step S6: splicing the three target areas after segmentation and then removing the halo of the central light source of the second image to obtain the third image includes: S601: using the existing interface of Opencv to obtain the three target areas; S602: when calculating the first target area, the grayscale values corresponding to the second target area and the third target area are set to black; S603: the grayscale of the first target area minus the zero component is the first target area to be obtained; S604: when calculating the second target area, the grayscale values corresponding to the first target area and the third target area are set to black; S605: the grayscale of the second target area minus the zero component is the second target area to be obtained; S606: when calculating the third target area, the grayscale values corresponding to the first target area and the second target area are set to black; S607: the grayscale of the third target area minus the zero component is the third target area to be obtained. That is, when removing the halo noise, the average grayscale value near the halo is calculated. Due to the limitations of tooling conditions, it is necessary to take the average threshold of the three areas near the halo to segment the target, and finally splice the three segmented areas.
[0076] S7: Adaptively segment the third image using an image binarization segmentation threshold algorithm, and restore the segmented information to the second image.
[0077] S8: Preliminarily determine whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with a preset pixel threshold.
[0078] Preferably, the step S8: preliminarily judging whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with the preset pixel threshold value includes: S801: in response to the pixel point having a pixel value greater than the preset pixel threshold value in the restored second image, directly judging the headlight lens as a unqualified product; S802: in response to the pixel value corresponding to each pixel point in the restored second image being less than the preset pixel threshold value, going to step S9. Figure 8 It is a schematic diagram of detected noise defects, wherein the preset pixel threshold is 160, that is, the third image is adaptively segmented, the segmented information is restored to the second image, and the custom threshold 160 is used to judge whether there are noise points in the sample. If it is greater than the threshold, it is directly judged as a defective product, otherwise step S9 is performed.
[0079] S9: In response to the vehicle headlight lens being a qualified product, grayscale processing is performed on the ROI image, and then horizontal and vertical gradient information are extracted to obtain a fourth image and a fifth image respectively.
[0080] Preferably, the gradient information extraction formula in step S9 is:
[0081]
[0082] In the formula, f x (x,y) represents the pixel value on the x-axis corresponding to the pixel point (x, y). Represents the pixel variable in the x-axis direction, f y (x,y) represents the pixel value on the y-axis corresponding to the pixel point (x, y). Represents the pixel variable in the y-axis direction. Specifically, refer to Figure 9a The fourth image is shown as a schematic diagram, reference Fig.10a The fifth image is shown as a schematic diagram. For a specific example, the horizontal and vertical gradient information of the image is obtained. The gradient information can reflect the rate of change of the image grayscale. The principles of obtaining the horizontal, vertical, left angle 45°, and right angle 45° gradients are the same. Taking the horizontal gradient information as an example, a specific explanation is given:
[0083] The gradient information is as follows:
[0084]
[0085]
[0086] S10: Perform median filtering on the fourth image and the fifth image respectively to remove random noise.
[0087] S11: By improving the big law thresholding method in OpenCV, based on the custom threshold obtained by the improved big law thresholding method, the fourth image and the fifth image after the noise is filtered out are respectively threshold segmented to obtain the sixth image and the seventh image.
[0088] Preferably, reference Figure 9b The sixth image is shown as a schematic diagram, refer to Fig.10b The seventh image is shown as a schematic diagram. The step S11: by improving the thresholding method of the big law in OpenCV, based on the custom threshold obtained by the improved big law thresholding method, the fourth image and the fifth image after the noise is filtered out are respectively subjected to threshold segmentation to obtain the sixth image and the seventh image, including: S1101: performing the operations of steps S1101-S1107 on the fourth image and the fifth image respectively; S1102: calculating the normalized histogram of the image, using P i , i=1,2,3,...255 represents each component of the histogram; S1103: Calculate the cumulative sum P I (k) S1104: Calculate the cumulative mean m(k), m(k)=∑ i k =1 iP i ; S1105: Calculate the global grayscale mean m G ; S1106: Calculate inter-class variance S1107: Obtaining a custom threshold k based on the inter-class variance * ,include: The maximum k value is the custom threshold k * If the maximum value is not unique, take the average value of each k value corresponding to each maximum value as the custom threshold k * ; S1108: Based on the custom threshold k * The fourth image and the fifth image after filtering out noise are respectively subjected to threshold segmentation to obtain the sixth image and the seventh image. Since the gray value of most backgrounds in the gradient information image is 0, if the Otsu method in OpenCV is directly used to find the threshold to segment the image, the segmentation effect will be unsatisfactory. Therefore, a method is proposed to remove a certain component and then find the class segmentation line.
[0089] S12: performing a sum operation on the sixth image and the seventh image to obtain an eighth image.
[0090] Preferably, reference Fig.11 The figure shows a schematic diagram of the eighth image. The eighth image can be obtained by adding the sixth image and the seventh image through the cv.add() function in OpenCV.
[0091] S13: In response to the vehicle headlight lens being a qualified product, grayscale processing is performed on the ROI image, and gradient information is extracted in the directions of a left oblique angle of 45° and a right oblique angle of 45° to obtain a ninth image and a tenth image respectively.
[0092] S14: Perform median filtering on the ninth image and the tenth image respectively to remove random noise.
[0093] S15: By improving the big law thresholding method in OpenCV, based on the custom threshold obtained by the improved big law thresholding method, the ninth image and the tenth image after the noise is filtered out are threshold segmented to obtain the eleventh image and the twelfth image.
[0094] S16: performing an AND operation on the eleventh image and the twelfth image to obtain a thirteenth image.
[0095] Preferably, reference Fig.12a , 12b 13a, 13b, and 14 are respectively the ninth image schematic diagram, the eleventh image schematic diagram, the tenth image schematic diagram, the twelfth image schematic diagram, and the thirteenth image schematic diagram. The operation method of steps S13-S16 is the same as the principle of steps S9-S12, so they are not repeated here.
[0096] S17: performing an AND operation on the thirteenth image and the eighth image to obtain a fourteenth image.
[0097] Preferably, reference Fig.15 , which is a schematic diagram of the fourteenth image. Specifically, the thirteenth image and the eighth image are added by the cv.add() function in OpenCV to obtain the fourteenth image.
[0098] S18: Processing the fourteenth image by morphology to merge objects with similar distances in the fourteenth image to obtain a fifteenth image.
[0099] Preferably, reference Fig.16 Shown is a schematic diagram of the fifteenth image.
[0100] S19: Processing the fifteenth image by using a custom mask to obtain a sixteenth image.
[0101] Preferably, reference Fig.17 Custom mask shapes are shown, see Fig.18 The figure shows a schematic diagram of the sixteenth image. The custom mask is added to the fifteenth image by the cv.add() function in OpenCV to obtain the sixteenth image.
[0102] S20: extracting the ROI information retained in the sixteenth image.
[0103] S21: judging the qualification status of the headlight lens based on the ROI information.
[0104] Preferably, reference Fig.19 The figure shows a schematic diagram of the defect detection result of the headlight lens. The step S21: judging the qualification of the headlight lens based on the ROI information includes: S2101: counting the number of pixels occupied by each ROI information and comparing it with the preset pixel threshold; S2102: judging the qualification of the headlight lens based on the comparison result. The step S2102: judging the qualification of the headlight lens based on the comparison result includes: S21021: judging the headlight lens to be unqualified in response to the fact that the number of pixels occupied by each ROI information is greater than the preset pixel threshold; S21022: judging the headlight lens to be qualified in response to the fact that the number of pixels occupied by each ROI information is less than the preset pixel threshold.
[0105] The above embodiment obtains the ROI image by obtaining the maximum connected domain in the image, and by performing subsequent operations only on the region of interest, the amount of calculation for subsequent image processing can be effectively reduced and the accuracy of image processing can be improved. The three regions in the image are binarized and segmented by three thresholds, and the halo is removed to avoid the halo caused by reflected light from affecting subsequent image recognition and image processing. By summing the gradient information in the four directions of horizontal, vertical, left oblique angle 45°, and right oblique angle 45°, the image is edge detected, and the rate of change of the image grayscale can be effectively fed back. By removing a certain component to obtain the class segmentation threshold, the grayscale value of most backgrounds in the gradient information image can be effectively avoided to be 0. If the Otsu method in opencv is directly used to obtain the threshold to segment the image, the segmentation effect will be unsatisfactory. By adopting the traditional image processing method, the problems of using a deep learning model to process the image in the prior art, the need for a large number of data sets, the need to consume time to mark samples, time-consuming and labor-intensive, and the need to retrain the model when the background changes, and the low applicability can be effectively avoided.
[0106] Example 2
[0107] See also Fig. 20, this embodiment provides a structural schematic diagram of a vehicle headlight lens defect detection system based on traditional image processing.
[0108] As an example, the system includes:
[0109] The image acquisition module 2010 is adapted to acquire the original image of the headlight lens through a camera.
[0110] The image preprocessing module 2011 is adapted to preprocess the original image to obtain a first image.
[0111] The ROI image generating module 2012 is adapted to extract the region of interest in the first image by using a local binarization method to generate a ROI image, wherein the ROI image only contains the vehicle headlight lens information.
[0112] The second image generating module 2013 is adapted to perform single-channel overlay processing on the ROI image to enhance the contrast of defects in the ROI image to obtain a second image.
[0113] The target segmentation module 2014 is adapted to perform target segmentation on the environment near the halo of the central light source of the second image by taking the average threshold of three regions through OpenCV.
[0114] The third image generating module 2015 is adapted to stitch the three segmented target areas and remove the halo of the central light source of the second image to obtain the third image.
[0115] The adaptive segmentation module 2016 is adapted to adaptively segment the third image by using an image binarization segmentation threshold algorithm, and restore the segmented information to the second image.
[0116] The first judgment module 2017 is adapted to preliminarily judge whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with a preset pixel threshold.
[0117] The gradient information extraction module 2018 is adapted to, in response to the headlight lens being a qualified product, perform grayscale processing on the ROI image and extract the horizontal and vertical gradient information to obtain the fourth image and the fifth image respectively; in response to the headlight lens being a qualified product, perform grayscale processing on the ROI image and extract the gradient information in the directions of 45° left oblique angle and 45° right oblique angle to obtain the ninth image and the tenth image respectively.
[0118] The noise filtering module 2019 is adapted to perform median filtering on the fourth image and the fifth image to remove random noise respectively; and perform median filtering on the ninth image and the tenth image to remove random noise respectively.
[0119] The threshold segmentation module 2020 is suitable for improving the big law threshold method in OpenCV, and performing threshold segmentation on the fourth image and the fifth image after the noise is filtered out based on the custom threshold obtained by the improved big law threshold method to obtain the sixth image and the seventh image; by improving the big law threshold method in OpenCV, and performing threshold segmentation on the ninth image and the tenth image after the noise is filtered out based on the custom threshold obtained by the improved big law threshold method to obtain the eleventh image and the twelfth image.
[0120] The sum operation module 2021 is adapted to perform a sum operation on the sixth image and the seventh image to obtain an eighth image; perform a sum operation on the eleventh image and the twelfth image to obtain a thirteenth image; and perform a sum operation on the thirteenth image and the eighth image to obtain a fourteenth image.
[0121] The morphological processing module 2022 is adapted to process the fourteenth image by morphological methods, so as to merge objects with similar distances in the fourteenth image to obtain a fifteenth image.
[0122] The mask processing module 2023 is adapted to process the fifteenth image through a custom mask to obtain a sixteenth image.
[0123] The ROI information extraction module 2024 is adapted to extract the ROI information retained in the sixteenth image.
[0124] The second judgment module 2025 is adapted to judge whether the headlight lens is qualified based on the ROI information.
[0125] It is not difficult to find that this embodiment is a system embodiment corresponding to the first embodiment, and this embodiment can be implemented in conjunction with the first embodiment. The relevant technical details mentioned in the first embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the first embodiment.
[0126] It is worth mentioning that all modules involved in this embodiment are logical units. In practical applications, a logical unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, this embodiment does not introduce units that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other units in this embodiment.
[0127] Example 3
[0128] The embodiment of the present invention further provides a storage medium, on which a method for detecting defects in a headlight lens based on traditional image processing is stored, and when the program for detecting defects in a headlight lens based on traditional image processing is executed by a processor, the steps of the method for detecting defects in a headlight lens based on traditional image processing as described above are implemented. Since the storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought by the technical solutions of the above embodiments, which will not be described one by one here.
[0129] Example 4
[0130] See also Fig.21 An embodiment of the present invention further provides an electronic device, comprising: a memory and a processor; the memory stores at least one program instruction; the processor implements the vehicle headlight lens defect detection method based on traditional image processing provided in Example 1 by loading and executing the at least one program instruction.
[0131] The memory 702 and the processor 701 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 701 and the memory 702 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 701 is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor 701.
[0132] The processor 701 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 702 can be used to store data used by the processor 701 when performing operations.
[0133] The above is only an embodiment of the present invention. The common sense such as the known specific structure and characteristics in the scheme is not described in detail here. The ordinary technicians in the relevant field know all the common technical knowledge in the technical field of the invention before the application date or priority date, can know all the existing technologies in the field, and have the ability to apply the conventional experimental means before that date. The ordinary technicians in the relevant field can improve and implement this scheme in combination with their own abilities under the enlightenment given by this application. Some typical known structures or known methods should not become obstacles for ordinary technicians in the relevant field to implement this application. It should be pointed out that for those skilled in the art, without departing from the structure of the present invention, several deformations and improvements can be made, which should also be regarded as the scope of protection of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent. The scope of protection required by this application shall be based on the content of its claims, and the specific implementation methods and other records in the specification can be used to interpret the content of the claims.
Claims
1. A method for detecting defects in vehicle headlight lenses based on traditional image processing, characterized in that: The method comprises: S1: Collect the original image of the headlight lens through the camera; S2: Preprocessing the original image to obtain a first image; S3: extracting a region of interest in the first image by using a local binarization method to generate a ROI image, wherein the ROI image only contains information about a headlight lens; S4: performing single-channel overlay processing on the ROI image to enhance the contrast of defects in the ROI image to obtain a second image; S5: using OpenCV to segment the target by taking the average threshold of three regions for the environment near the halo of the central light source of the second image; S6: stitching the three segmented target areas and removing the halo of the central light source of the second image to obtain a third image; S7: Adaptively segmenting the third image using an image binarization segmentation threshold algorithm, and restoring the segmented information to the second image; S8: Preliminarily determine whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with a preset pixel threshold; S9: in response to the vehicle headlight lens being a qualified product, grayscale processing is performed on the ROI image, and then horizontal and vertical gradient information are extracted to obtain a fourth image and a fifth image respectively; S10: performing median filtering on the fourth image and the fifth image respectively to filter out random noise; S11: by improving the big law threshold method in OpenCV, based on the custom threshold obtained by the improved big law threshold method, the fourth image and the fifth image after the noise is filtered out are respectively threshold segmented to obtain the sixth image and the seventh image; S12: performing a sum operation on the sixth image and the seventh image to obtain an eighth image; S13: in response to the vehicle headlight lens being a qualified product, grayscale processing is performed on the ROI image, and gradient information in the directions of a left oblique angle of 45° and a right oblique angle of 45° are extracted to obtain a ninth image and a tenth image respectively; S14: performing median filtering on the ninth image and the tenth image respectively to filter out random noise; S15: by improving the big law threshold method in OpenCV, based on the custom threshold obtained by the improved big law threshold method, the ninth image and the tenth image after the noise is filtered out are respectively threshold segmented to obtain the eleventh image and the twelfth image; S16: performing a sum operation on the eleventh image and the twelfth image to obtain a thirteenth image; S17: performing an AND operation on the thirteenth image and the eighth image to obtain a fourteenth image; S18: morphologically processing the fourteenth image to merge objects with close distances in the fourteenth image to obtain a fifteenth image; S19: Processing the fifteenth image by using a custom mask to obtain a sixteenth image; S20: extracting ROI information retained in the sixteenth image; S21: judging the qualification status of the headlight lens based on the ROI information.
2. The vehicle lamp lens defect detection method based on traditional image processing according to claim 1 is characterized in that: The step S2: preprocessing the original image to obtain the first image comprises: S201: rotating the original image by a custom angle; S202: Manually positioning the rotated original image to obtain a first image.
3. The vehicle lamp lens defect detection method based on traditional image processing according to claim 1 is characterized in that: The step S3: extracting the region of interest in the first image by using the local binarization method to generate an ROI image, wherein the ROI image only contains the headlight lens information, includes: finding the maximum connected domain based on the first image by using OpenCv, and performing ROI extraction on it to obtain the ROI image.
4. The vehicle lamp lens defect detection method based on traditional image processing according to claim 1 is characterized in that: The step S6: stitching the three segmented target areas to remove the halo of the central light source of the second image to obtain a third image includes: S601: using the existing interface of Opencv to obtain three target areas; S602: when calculating the first target area, setting the gray values corresponding to the second target area and the third target area to black; S603: the grayscale of the first target area minus the zero component is the first target area to be acquired; S604: when calculating the second target area, setting the gray values corresponding to the first target area and the third target area to black; S605: the grayscale of the second target area minus the zero component is the second target area to be acquired; S606: when calculating the third target area, setting the gray values corresponding to the first target area and the second target area to black; S607: The grayscale of the third target area without the zero component is the third target area to be obtained.
5. The vehicle lamp lens defect detection method based on traditional image processing according to claim 1 is characterized in that: The step S8: preliminarily judging whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with a preset pixel threshold value includes: S801: In response to the restored second image containing a pixel point whose pixel value is greater than a preset pixel threshold, directly determining that the headlight lens is a defective product; S802: In response to the pixel value corresponding to each pixel point in the restored second image being less than a preset pixel threshold, go to step S9.
6. The vehicle lamp lens defect detection method based on traditional image processing according to claim 1, characterized in that: The gradient information extraction formula in step S9 is: In the formula, f x (x,y) represents the pixel value on the x-axis corresponding to the pixel point (x, y). Represents the pixel variable in the x-axis direction, f y (x,y) represents the pixel value on the y-axis corresponding to the pixel point (x, y). A variable representing pixels in the y-axis direction.
7. The vehicle lamp lens defect detection method based on traditional image processing according to claim 1 is characterized in that: The step S11: by improving the big law threshold method in OpenCV, based on the custom threshold obtained by the improved big law threshold method, the fourth image and the fifth image after the noise is filtered out are respectively threshold segmented to obtain the sixth image and the seventh image, including: S1101: performing steps S1101 to S1107 on the fourth image and the fifth image respectively; S1102: Calculate the normalized histogram of the image using P i , i = 1, 2, 3, ... 255 represents each component of the histogram; S1103: Calculate the cumulative sum P I (k) S1104: Calculate the cumulative mean m(k), S1105: Calculate the global grayscale mean m G ; S1106: Calculate inter-class variance S1107: Obtaining a custom threshold k based on the inter-class variance + ,include: The maximum k value is the custom threshold k * If the maximum value is not unique, take the average value of each k value corresponding to each maximum value as the custom threshold k * ; S1108: Based on the custom threshold k * The fourth image and the fifth image after the noise is filtered out are respectively subjected to threshold segmentation to obtain the sixth image and the seventh image.
8. The vehicle lamp lens defect detection method based on traditional image processing according to claim 1 is characterized in that: The step S21: judging the qualification of the headlight lens based on the ROI information includes: S2101: Count the number of pixels occupied by each ROI information and compare it with a preset pixel threshold; S2102: Determine whether the headlight lens is qualified based on the comparison result.
9. The vehicle lamp lens defect detection method based on traditional image processing according to claim 8 is characterized in that: The step S2102: judging the qualification of the headlight lens based on the comparison result includes: S21021: In response to the situation that the number of pixels occupied by each piece of ROI information counted is greater than a preset pixel threshold, determining that the headlight lens is unqualified; S21022: In response to the fact that the number of pixels occupied by each statistical ROI information is less than a preset pixel threshold, the headlight lens is determined to be qualified.
10. A vehicle lamp lens defect detection system based on traditional image processing, characterized in that: The system adopts the vehicle headlight lens defect detection method based on traditional image processing as described in any one of claims 1 to 9, and the system comprises: An image acquisition module, adapted to acquire the original image of the headlight lens through a camera; An image preprocessing module, adapted to preprocess the original image to obtain a first image; A ROI image generating module is adapted to extract a region of interest in the first image by using a local binarization method to generate a ROI image, wherein the ROI image only contains the headlight lens information; A second image generating module is adapted to perform single-channel overlay processing on the ROI image to enhance the contrast of defects in the ROI image to obtain a second image; A target segmentation module, adapted to perform target segmentation on an environment near the halo of the central light source of the second image by taking an average threshold of three regions through OpenCV; A third image generation module is used to stitch the three segmented target areas and remove the halo of the central light source of the second image to obtain the third image; An adaptive segmentation module, adapted to adaptively segment the third image by using an image binarization segmentation threshold algorithm, and restore the segmented information to the second image; A first judgment module is adapted to preliminarily judge whether the headlight lens is a qualified product by comparing the pixel value corresponding to each pixel point in the restored second image with a preset pixel threshold; a gradient information extraction module, adapted to, in response to the vehicle headlight lens being a qualified product, respectively extracting transverse and longitudinal gradient information from the ROI image after grayscale processing to obtain a fourth image and a fifth image; and, in response to the vehicle headlight lens being a qualified product, respectively extracting gradient information in the directions of a left oblique angle of 45° and a right oblique angle of 45° from the ROI image after grayscale processing to obtain a ninth image and a tenth image; A noise filtering module, adapted to perform median filtering on the fourth image and the fifth image to remove random noise respectively; and perform median filtering on the ninth image and the tenth image to remove random noise respectively; The threshold segmentation module is suitable for performing threshold segmentation on the fourth image and the fifth image after the noise is filtered out by improving the big law threshold method in OpenCV, and obtaining the sixth image and the seventh image based on the custom threshold value obtained by the improved big law threshold method; performing threshold segmentation on the ninth image and the tenth image after the noise is filtered out by improving the big law threshold method in OpenCV, and obtaining the eleventh image and the twelfth image based on the custom threshold value obtained by the improved big law threshold method; a sum operation module, adapted to perform a sum operation on the sixth image and the seventh image to obtain an eighth image; perform a sum operation on the eleventh image and the twelfth image to obtain a thirteenth image; and perform a sum operation on the thirteenth image and the eighth image to obtain a fourteenth image; a morphological processing module, adapted to process the fourteenth image by morphological processing, so as to merge objects with similar distances in the fourteenth image to obtain a fifteenth image; a mask processing module, adapted to process the fifteenth image through a custom mask to obtain a sixteenth image; A ROI information extraction module, adapted to extract the ROI information retained in the sixteenth image; The second judgment module is adapted to judge the qualification of the headlight lens based on the ROI information.
Citation Information
Patent Citations
A high-speed and accurate LED defect detection method based on machine vision
CN109215026A
SAR image target positioning method, system and device based on ROI region
CN110031843A
Video-based camera lens shielding detection method and system
CN112927262A
Image-based lens production process supervision method, device, equipment and medium
CN114782288A
Lens flaw detection system and detection method using structured light, structured light generation method and image processing method thereof
CN116429691A