Surface defect detection method and device, electronic equipment and medium

By capturing color images under ambient illumination at different angles and then breaking them down into R, G, and B channel grayscale images, the problem of complex AOI light source debugging was solved, achieving a simplified debugging process and stable detection results.

CN121962043APending Publication Date: 2026-05-01东莞康视达自动化科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
东莞康视达自动化科技有限公司
Filing Date
2026-01-05
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

AOI light sources are complex and unstable to debug in machine vision inspection, making it difficult to replicate the effect of a second set of images, and the debugging process is lengthy.

Method used

Color images were captured under ring illumination at different angles, decomposed into grayscale images of R, G, and B channels, and the grayscale values ​​were modified to synthesize the target color image to simulate the AOI ring light effect.

Benefits of technology

The debugging difficulty has been reduced, the process has been simplified, and the detection effect is ensured to be close to the effect of AOI ring light illumination, thus meeting the detection requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121962043A_ABST
    Figure CN121962043A_ABST
Patent Text Reader

Abstract

The invention discloses a surface defect detection method and device, electronic equipment and a medium, and relates to the field of machine vision detection. The surface defect detection method comprises the following steps: obtaining a first color image under annular light illumination at a first angle, and obtaining an R channel grey-scale image of the first color image; obtaining a second color image under ring light illumination at a second angle, and obtaining a G-channel grey-scale image of the second color image; obtaining a third color image under annular light illumination at a third angle, and obtaining a B-channel grey-scale image of the third color image; modifying the gray value of the R-channel gray-scale map into a first target gray value, modifying the gray value of the G-channel gray-scale map into a second target gray value, and modifying the gray value of the B-channel gray-scale map into a third target gray value; and synthesizing the R channel grey-scale map, the G channel grey-scale map and the B channel grey-scale map to obtain a target color map. The synthesized target color image can have an effect similar to that of AOI (Automated Optical Inspection) ring light irradiation.
Need to check novelty before this filing date? Find Prior Art

Description

Surface defect detection methods, devices, electronic equipment and media Technical Field

[0001] This invention relates to the field of machine vision inspection technology, and in particular to a surface defect detection method, apparatus, electronic device, and medium. Background Technology

[0002] In the field of machine vision, illumination from a light source is typically required when inspecting the appearance of a product. Among these, AOI (Automated Optical Inspection) light sources are a common type of inspection light source. The debugging and matching process for AOI light sources is quite complex. It requires not only matching the light source with the camera, lens, and object being inspected, but also adjusting a large number of parameters. Even after the first set of images has been debugged with the AOI light source, the effect of the second set of images obtained during subsequent debugging will still differ from the first set due to factors such as the voltage, current, quality of the light source LEDs, and camera color reproduction. It is difficult to completely replicate the first set of images. Therefore, even though the visual effect of illumination under AOI light sources is good, the stability of AOI light sources during use is poor, the debugging difficulty is high, and the debugging process is too long. Summary of the Invention

[0003] The purpose of this invention is to overcome the above-mentioned defects in the prior art and provide a surface defect detection method, device, electronic device and medium that can achieve an effect similar to that of AOI ring light illumination, with a lower adjustment difficulty and shorter adjustment process, and can meet the detection requirements.

[0004] To achieve the above objectives, a first aspect of the present invention provides a surface defect detection method, which includes the following steps:

[0005] Under ring illumination at a first angle, a first color image is obtained, and the R channel grayscale image of the first color image is obtained.

[0006] Under ring illumination at a second angle, a second color image is obtained, and the G channel grayscale image of the second color image is obtained.

[0007] Under ring illumination at a third angle, a third color image is obtained, and the B-channel grayscale image of the third color image is obtained.

[0008] Modify the grayscale value of the R channel grayscale image to the first target grayscale value, modify the grayscale value of the G channel grayscale image to the second target grayscale value, and modify the grayscale value of the B channel grayscale image to the third target grayscale value.

[0009] The target color image is obtained by combining the R-channel grayscale image, the G-channel grayscale image, and the B-channel grayscale image.

[0010] Further, before the steps of "obtaining a first color image under the annular light illumination at a first angle and obtaining the grayscale image of the R channel of the first color image", the following steps are also included:

[0011] Under the AOI annular light illumination, obtain a test color image;

[0012] Decompose the test color image to obtain the first target grayscale value, the second target grayscale value, and the third target grayscale value.

[0013] Further, under the annular light illumination at a first angle, obtaining a first color image and obtaining the grayscale image of the R channel of the first color image includes the following steps:

[0014] Under the annular light illumination at a first temporary angle, obtain a first temporary color image and obtain the grayscale image of the R channel of the first temporary color image;

[0015] Let the grayscale value of the grayscale image of the R channel of the first temporary color image be X, the first target grayscale value be X1, and the first difference be X2;

[0016] If |X - X1| < X2, the first temporary angle is the first angle, the first temporary color image is the first color image, and the grayscale image of the R channel of the first temporary color image is the grayscale image of the R channel of the first color image;

[0017] If |X - X1| ≥ X2, increase or decrease the first temporary angle, and again under the annular light illumination at the first temporary angle, obtain the first temporary color image and obtain the grayscale image of the R channel of the first temporary color image. Repeat this step until |X - X1| < X2, the first temporary angle is the first angle, the first temporary color image is the first color image, and the grayscale image of the R channel of the first temporary color image is the grayscale image of the R channel of the first color image;

[0018] Obtain the first angle, obtain the first color image, and obtain the grayscale image of the R channel of the first color image.

[0019] Further, under the annular light illumination at a second angle, obtaining a second color image and obtaining the grayscale image of the G channel of the second color image includes the following steps:

[0020] Under the annular light illumination at a second temporary angle, obtain a second temporary color image and obtain the grayscale image of the G channel of the second temporary color image;

[0021] Let the grayscale value of the grayscale image of the G channel of the second temporary color image be Y, the second target grayscale value be Y1, and the second difference be Y2;

[0022] If |Y - Y1| < Y2, the second temporary angle is the second angle, the second temporary color image is the second color image, and the grayscale image of the G channel of the second temporary color image is the grayscale image of the G channel of the second color image;

[0023] If |Y - Y1| ≥ Y2, increase or decrease the second temporary angle, and again under the ring light illumination at the second temporary angle, obtain the second temporary color image and the grayscale image of the G channel of the second temporary color image. Repeat this step until |Y - Y1| < Y2. Then, the second temporary angle is the second angle, the second temporary color image is the second color image, and the grayscale image of the G channel of the second temporary color image is the grayscale image of the G channel of the second color image;

[0024] Obtain the second angle, the second color image, and the grayscale image of the G channel of the second color image.

[0025] Further, under the ring light illumination at the third angle, obtain the third color image and the grayscale image of the B channel of the third color image, including the following steps:

[0026] Under the ring light illumination at the third temporary angle, obtain the third temporary color image and the grayscale image of the B channel of the third temporary color image;

[0027] Let the grayscale value of the grayscale image of the B channel of the third temporary color image be Z, the third target grayscale value be Z1, and the third difference be Z2;

[0028] If |Z - Z1| < Z2, the third temporary angle is the third angle, the third temporary color image is the third color image, and the grayscale image of the B channel of the third temporary color image is the grayscale image of the B channel of the third color image;

[0029] If |Z - Z1| ≥ Z2, increase or decrease the third temporary angle, and again under the ring light illumination at the third temporary angle, obtain the third temporary color image and the grayscale image of the B channel of the third temporary color image. Repeat this step until |Z - Z1| < Z2. Then, the third temporary angle is the third angle, the third temporary color image is the third color image, and the grayscale image of the B channel of the third temporary color image is the grayscale image of the B channel of the third color image;

[0030] Obtain the third angle, the third color image, and the grayscale image of the B channel of the third color image.

[0031] Further, the second angle is less than the first angle and greater than the third angle, or, the second angle is greater than the first angle and less than the third angle.

[0032] Furthermore, it also includes the following step: detecting the target color image.

[0033] A surface defect detection device according to a second aspect of the present invention includes: a low-angle ring light source; a medium-angle ring light source; a high-angle ring light source; the low-angle ring light source, the medium-angle ring light source, and the high-angle ring light source are stacked sequentially; a first camera located above the high-angle ring light source and used to acquire a first color image, a second color image, and a third color image; an AOI ring light source; a second camera located above the AOI ring light source and used to acquire a test color image; a target image determination module connected to the first camera and the second camera and used to acquire the first color image, the second color image, and the third color image, and to acquire a first target grayscale value, a second target grayscale value, and a third target grayscale value of the test color image, and capable of modifying and synthesizing the R channel grayscale image of the first color image, the G channel grayscale image of the second color image, and the B channel grayscale image of the third color image.

[0034] An electronic device according to a third aspect of the present invention includes: at least one processor; and a memory communicatively connected to at least one of the processors; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the surface defect detection method described in the first aspect of the present invention.

[0035] According to a fourth aspect of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, the computer instructions being used to cause a computer to perform the surface defect detection method described in the first aspect of the present invention.

[0036] Compared with existing technologies, the present invention has the following advantages: the workpiece to be inspected can be placed under ring light at different angles, and the workpiece to be inspected can be inspected using a camera inspection module. A first color image is obtained by illumination under the first angle of ring light, and the R-channel grayscale image can be obtained by disassembling the first color image. A second color image is obtained by illumination under the second angle of ring light, and the G-channel grayscale image can be obtained by disassembling the second color image. A third color image is obtained by illumination under the third angle of ring light, and the B-channel grayscale image can be obtained by disassembling the third color image. The first target grayscale value, the second target grayscale value, and the third target grayscale value can be determined based on the color image obtained by illumination under AOI ring light, so that the synthesized target color image can have an effect similar to that of illumination under AOI ring light, thereby reducing the debugging difficulty, shortening the debugging process, and meeting the inspection requirements. Attached Figure Description

[0037] To more clearly illustrate the technology in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0038] Figure 1 is a schematic flowchart of the surface defect detection method of the present invention;

[0039] Figure 2 is an R-channel grayscale image of an embodiment of the surface defect detection method of the present invention;

[0040] Figure 3 is a grayscale image of the G channel of an embodiment of the surface defect detection method of the present invention;

[0041] Figure 4 is a grayscale image of channel B of an embodiment of the surface defect detection method of the present invention;

[0042] Figure 5 is a target color image of an embodiment of the surface defect detection method of the present invention;

[0043] Figure 6 is a partially enlarged view of the target color image of an embodiment of the surface defect detection method of the present invention shown in Figure 5;

[0044] Figure 7 is a test color diagram of an embodiment of the surface defect detection method of the present invention;

[0045] Figure 8 is a schematic diagram of the structure of the low-angle ring light source, the medium-angle ring light source, the high-angle ring light source and the first camera of the surface defect detection device of the present invention.

[0046] Reference numerals: Low-angle ring light source 100; Medium-angle ring light source 200; High-angle ring light source 300; First camera 400. Detailed Implementation

[0047] The technology of this embodiment of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiment is one embodiment of the present invention, and not all embodiments thereof. Based on this embodiment of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0048] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indication will also change accordingly.

[0049] Furthermore, if the embodiments of the present invention involve descriptions such as "first" or "second", such descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated.

[0050] Please refer to Figures 1 to 8. Embodiments of the present invention provide a surface defect detection method, apparatus, electronic device, and medium.

[0051] Referring to Figures 1 to 7, this embodiment of the invention also provides a surface defect detection method, which includes the following steps:

[0052] Under ring illumination at a first angle, a first color image is obtained, and the R channel grayscale image of the first color image is obtained.

[0053] Under ring illumination at a second angle, a second color image is obtained, and the G channel grayscale image of the second color image is obtained.

[0054] Under ring illumination at a third angle, a third color image is obtained, and the B-channel grayscale image of the third color image is obtained.

[0055] Modify the grayscale value of the R channel grayscale image to the first target grayscale value, modify the grayscale value of the G channel grayscale image to the second target grayscale value, and modify the grayscale value of the B channel grayscale image to the third target grayscale value.

[0056] The target color image is obtained by combining the R-channel grayscale image, the G-channel grayscale image, and the B-channel grayscale image.

[0057] The workpiece to be inspected can be placed under ring lights at different angles. A camera inspection module can then inspect the workpiece. A first color image is obtained by illuminating it under the first angle of ring light. The R-channel grayscale image can be obtained by dissecting the first color image. A second color image is obtained by illuminating it under the second angle of ring light. The G-channel grayscale image can be obtained by dissecting the second color image. A third color image is obtained by illuminating it under the third angle of ring light. The B-channel grayscale image can be obtained by dissecting the third color image. The grayscale values ​​of the first, second, and third targets can be determined based on the color images obtained under AOI ring light illumination. This allows the synthesized target color image to have an effect similar to that of AOI ring light illumination, reducing debugging difficulty, shortening the debugging process, and meeting the inspection requirements.

[0058] Specifically, the grayscale values ​​of the R channel grayscale image of the first color image, the G channel grayscale image of the second color image, and the B channel grayscale image of the third color image are all 8-bit deep single-channel grayscale values, with a grayscale value range of 0 to 255. By increasing or decreasing the grayscale value, the grayscale values ​​of the R channel grayscale image, the G channel grayscale image, and the B channel grayscale image can be modified.

[0059] Specifically, in one embodiment of the present invention, Figure 2 is the R-channel grayscale image of the first color image obtained under ring illumination at a first angle, Figure 3 is the G-channel grayscale image of the second color image obtained under ring illumination at a second angle, Figure 4 is the B-channel grayscale image of the third color image obtained under ring illumination at a third angle, Figure 5 shows the target color image obtained by combining the R-channel grayscale image, G-channel grayscale image and B-channel grayscale image, wherein the R-channel grayscale image, G-channel grayscale image and B-channel grayscale image are the contents of Figures 2, 3 and 4, respectively, and Figure 6 shows the test color image obtained under AOI ring illumination.

[0060] In some embodiments of the present invention, the step of "obtaining a first color image under a first angle of ring illumination, and obtaining an R-channel grayscale image of the first color image" further includes the following steps:

[0061] Under AOI ring illumination, a test color image was obtained;

[0062] The test color image is disassembled to obtain the first target grayscale value, the second target grayscale value, and the third target grayscale value.

[0063] Under AOI ring illumination, a camera module is used to photograph the workpiece to be inspected, resulting in a test color image. This test color image is a 24-bit deep three-channel array. By decomposing this test color image, three 8-bit deep single-channel grayscale values ​​can be obtained, representing the red, green, and blue channels respectively. Based on the red, green, and blue channels, the first, second, and third target values ​​are determined respectively. Therefore, after modifying the R-channel grayscale image, G-channel grayscale image, and B-channel grayscale image to the target values, the target color image obtained by synthesizing the R-channel grayscale image, G-channel grayscale image, and B-channel grayscale image can have an effect similar to that under AOI ring illumination.

[0064] In some embodiments of the present invention, obtaining a first color image under ring illumination at a first angle, and obtaining the R channel grayscale image of the first color image, includes the following steps:

[0065] Under the ring illumination at the first temporary angle, a first temporary color image is obtained, and the R channel grayscale image of the first temporary color image is obtained.

[0066] Let the gray value of the R-channel grayscale image of the first temporary color image be X, the first target gray value be X1, and the first difference be X2;

[0067] If |X - X1| < X2, the first temporary angle is the first angle, the first temporary color image is the first color image, and the R-channel grayscale image of the first temporary color image is the R-channel grayscale image of the first color image;

[0068] If |X - X1| ≥ X2, increase or decrease the first temporary angle, and under the ring light illumination at the first temporary angle, obtain the first temporary color image again, and obtain the R-channel grayscale image of the first temporary color image. Repeat this step until |X - X1| < X2, at which time the first temporary angle is the first angle, the first temporary color image is the first color image, and the R-channel grayscale image of the first temporary color image is the R-channel grayscale image of the first color image.

[0069] Obtain the first angle, obtain the first color image, and obtain the R-channel grayscale image of the first color image.

[0070] During debugging, the first temporary angle, the first target gray value, and the first difference can be set first. Under the first temporary angle, use the camera module to capture the first temporary color image to obtain the R-channel grayscale image of the first temporary color image; then, obtain the absolute value of the difference between the gray value of the R-channel grayscale image of the first temporary color image and the first target gray value, and compare it with the first difference; if the absolute value of the difference between the gray value of the R-channel grayscale image of the first temporary color image and the first target gray value is greater than or equal to the first difference, adjust the first temporary angle, and then under the adjusted first temporary angle, repeat using the camera module to capture another first temporary color image to obtain the R-channel grayscale image of the another first temporary color image, and repeat the above judgment until the absolute value of the difference between the gray value of the R-channel grayscale image of the first temporary color image and the first target gray value is less than the first difference, then determine the first temporary angle as the first angle, the first temporary color image as the first color image, and the R-channel grayscale image of the first temporary color image as the R-channel grayscale image of the first color image. By continuously increasing or decreasing the first temporary angle, the difference between the gray value of the R-channel of the first temporary color image and the first target gray value can be reduced, so as to reduce the amplitude of subsequent gray value modification, making the target color image have an effect approximately under the illumination of the AOI ring light.

[0071] Moreover, in the actual detection process, due to factors such as the voltage and current of the ring light source, the quality of the light source lamp beads, and the color restoration of the camera, each judgment is made through the above method. When the deviation between the R-channel grayscale image of the first temporary color image and the first preset grayscale value is too large, it is convenient for the debugging personnel to judge whether the first angle needs to be adjusted. Thus, factors such as the voltage and current of the ring light source, the quality of the light source lamp beads, and the color restoration of the camera can be ignored, and the subsequent steps can still be combined to obtain a target color image with an effect approximately irradiated under the AOI ring light.

[0072] Therefore, by adjusting the first angle, the remaining cumbersome debugging steps can be replaced, and the first difference can be set according to the specific situation, so that the first difference has a certain redundancy to avoid frequent adjustment of the first angle in the future.

[0073] Specifically, if |X - X1| ≧ X2, increase or decrease the first temporary angle, and re-obtain the first temporary color image under the ring light illumination at the first temporary angle, and obtain the R-channel grayscale image of the first temporary color image. Repeat this step until |X - X1| < X2, where the first temporary angle is the first angle, the first temporary color image is the first color image, and the R-channel grayscale image of the first temporary color image is the R-channel grayscale image of the first color image. The following steps may also be included:

[0074] Set a preset number of steps A;

[0075] If |X - X1| ≧ X2, increase or decrease the first temporary angle, and re-obtain the first temporary color image under the ring light illumination at the first temporary angle, and obtain the R-channel grayscale image of the first temporary color image. Repeat this step and record the number of repeated steps A1. When A1 = A, increase the first difference to X2 until |X - X1| < X2, where the first temporary angle is the first angle, the first temporary color image is the first color image, and the R-channel grayscale image of the first temporary color image is the R-channel grayscale image of the first color image.

[0076] By the above steps, it is possible to avoid repeatedly and frequently adjusting the size of the first angle.

[0077] Specifically, when X is greater than X1, the first temporary angle can be decreased, and when X is less than X1, the first temporary angle can be increased.

[0078] In some embodiments of the present invention, under the ring light illumination at the second angle, a second color image is obtained, and the G-channel grayscale image of the second color image is obtained, including the following steps:

[0079] Under the ring light illumination at the second temporary angle, obtain a second temporary color image, and obtain the grayscale image of the G channel of the second temporary color image;

[0080] Let the grayscale value of the grayscale image of the G channel of the second temporary color image be Y, the second target grayscale value be Y1, and the second difference be Y2;

[0081] If |Y - Y1| < Y2, the second temporary angle is the second angle, the second temporary color image is the second color image, and the grayscale image of the G channel of the second temporary color image is the grayscale image of the G channel of the second color image;

[0082] If |Y - Y1| ≥ Y2, increase or decrease the second temporary angle, and re-obtain the second temporary color image under the ring light illumination at the second temporary angle, and obtain the grayscale image of the G channel of the second temporary color image. Repeat this step until |Y - Y1| < Y2, the second temporary angle is the second angle, the second temporary color image is the second color image, and the grayscale image of the G channel of the second temporary color image is the grayscale image of the G channel of the second color image;

[0083] Obtain the second angle, obtain the second color image, and obtain the grayscale image of the G channel of the second color image.

[0084] During debugging, the second temporary angle, the second target grayscale value, and the second difference can be set first. At the second temporary angle, use the camera module to capture a second temporary color image to obtain the grayscale image of the G channel of the second temporary color image; then, obtain the absolute value of the difference between the grayscale value of the grayscale image of the G channel of the second temporary color image and the second target grayscale value, and compare it with the second difference; if the absolute value of the difference between the grayscale value of the grayscale image of the G channel of the second temporary color image and the second target grayscale value is greater than or equal to the second difference, adjust the second temporary angle, and then at the adjusted second temporary angle, repeat using the camera module to capture another second temporary color image to obtain the grayscale image of the G channel of another second temporary color image, and repeat the above judgment until the absolute value of the difference between the grayscale value of the grayscale image of the G channel of the second temporary color image and the second target grayscale value is less than the second difference, then determine the second temporary angle as the second angle, the second temporary color image as the second color image, and the grayscale image of the G channel of the second temporary color image as the grayscale image of the G channel of the second color image. By continuously increasing or decreasing the second temporary angle, the difference between the grayscale value of the G channel of the second temporary color image and the second target grayscale value can be reduced, so as to reduce the amplitude of subsequent grayscale value modification, making the target color image have an effect approximately under the illumination of the AOI ring light.

[0085] Moreover, in the actual detection process, due to factors such as the voltage and current of the ring light source, the quality of the light source lamp beads, and the color reproduction of the camera, each judgment is made through the above method. When the deviation between the G-channel grayscale image of the second temporary color image and the second preset grayscale value is too large, it is convenient for the debugging personnel to judge whether it is necessary to adjust the second angle. Thus, factors such as the voltage and current of the ring light source, the quality of the light source lamp beads, and the color reproduction of the camera can be ignored, and the subsequent steps can still be combined to obtain a target color image with an effect approximately irradiated under the AOI ring light.

[0086] Therefore, by adjusting the second angle, the remaining cumbersome debugging steps can be replaced, and the second difference can be set according to the specific situation, so that the second difference has a certain redundancy to avoid frequent adjustment of the second angle in the future.

[0087] Specifically, if |Y - Y1| ≧ Y2, increase or decrease the second temporary angle, and re-obtain the second temporary color image under the ring light illumination of the second temporary angle, and obtain the G-channel grayscale image of the second temporary color image. Repeat this step until |Y - Y1| < Y2, where the second temporary angle is the second angle, the second temporary color image is the second color image, and the G-channel grayscale image of the second temporary color image is the G-channel grayscale image of the second color image. The following steps may also be included:

[0088] Set the preset number of steps B;

[0089] If |Y - Y1| ≧ Y2, increase or decrease the second temporary angle, and re-obtain the second temporary color image under the ring light illumination of the second temporary angle, and obtain the G-channel grayscale image of the second temporary color image. Repeat this step and record the number of repeated steps B1. When B1 = B, increase the second difference to Y2 until |Y - Y1| < Y2, where the second temporary angle is the second angle, the second temporary color image is the second color image, and the G-channel grayscale image of the second temporary color image is the G-channel grayscale image of the second color image.

[0090] By the above steps, it is possible to avoid repeatedly and frequently adjusting the size of the second angle.

[0091] Specifically, when Y is greater than Y1, the second temporary angle can be decreased, and when Y is less than Y1, the second temporary angle can be increased.

[0092] In some embodiments of the present invention, under the ring light illumination of the third angle, obtain a third color image, and obtain the B-channel grayscale image of the third color image, including the following steps:

[0093] Under the ring light illumination at the third temporary angle, obtain the third temporary color image, and obtain the grayscale image of the B channel of the third temporary color image;

[0094] Let the grayscale value of the grayscale image of the B channel of the third temporary color image be Z, the third target grayscale value be Z1, and the third difference be Z2;

[0095] If |Z - Z1| < Z2, the third temporary angle is the third angle, the third temporary color image is the third color image, and the grayscale image of the B channel of the third temporary color image is the grayscale image of the B channel of the third color image;

[0096] If |Z - Z1| ≥ Z2, increase or decrease the third temporary angle, and re-obtain the third temporary color image under the ring light illumination at the third temporary angle, and obtain the grayscale image of the B channel of the third temporary color image. Repeat this step until |Z - Z1| < Z2, the third temporary angle is the third angle, the third temporary color image is the third color image, and the grayscale image of the B channel of the third temporary color image is the grayscale image of the B channel of the third color image;

[0097] Obtain the third angle, obtain the third color image, and obtain the grayscale image of the B channel of the third color image.

[0098] During debugging, the third temporary angle, the third target grayscale value, and the third difference can be set first. At the third temporary angle, use the camera module to take a picture to obtain the third temporary color image, so as to obtain the grayscale image of the B channel of the third temporary color image; then, obtain the absolute value of the difference between the grayscale value of the grayscale image of the B channel of the third temporary color image and the third target grayscale value, and compare it with the third difference; if the absolute value of the difference between the grayscale value of the grayscale image of the B channel of the third temporary color image and the third target grayscale value is greater than or equal to the third difference, adjust the third temporary angle, and then at the adjusted third temporary angle, repeat using the camera module to take another third temporary color image, so as to obtain the grayscale image of the B channel of another third temporary color image, and repeat the above judgment until the absolute value of the difference between the grayscale value of the grayscale image of the B channel of the third temporary color image and the third target grayscale value is less than the third difference, then determine the third temporary angle as the third angle, the third temporary color image as the third color image, and the grayscale image of the B channel of the third temporary color image as the grayscale image of the B channel of the third color image. By continuously increasing or decreasing the third temporary angle, the difference between the grayscale value of the C channel of the third temporary color image and the third target grayscale value can be reduced, so that the amplitude of modifying the grayscale value in the subsequent process can be reduced, and the target color image can have an effect approximately under the illumination of the AOI ring light.

[0099] Moreover, in the actual detection process, due to factors such as the voltage and current of the ring light source, the quality of the light source lamp beads, and the color restoration of the camera, each judgment is made through the above method. When the deviation between the B-channel grayscale image of the third temporary color image and the third preset grayscale value is too large, it is convenient for the debugging personnel to judge whether it is necessary to adjust the third angle. Thus, factors such as the voltage and current of the ring light source, the quality of the light source lamp beads, and the color restoration of the camera can be ignored, and the subsequent steps can still be combined to obtain a target color image with an effect approximately irradiated under the AOI ring light.

[0100] Therefore, by adjusting the third angle, the remaining cumbersome debugging steps can be replaced, and the third difference can be set according to the specific situation, so that the third difference has a certain redundancy to avoid frequent adjustment of the third angle in the future.

[0101] Specifically, if |Z - Z1| ≧ Z2, increase or decrease the third temporary angle, and under the ring light illumination at the third temporary angle, obtain the third temporary color image, and obtain the B-channel grayscale image of the third temporary color image. Repeat this step until |Z - Z1| < Z2, where the third temporary angle is the third angle, the third temporary color image is the third color image, and the B-channel grayscale image of the third temporary color image is the B-channel grayscale image of the third color image. The following steps may also be included:

[0102] Set a preset number of steps C;

[0103] If |Z - Z1| ≧ Z2, increase or decrease the third temporary angle, and under the ring light illumination at the third temporary angle, obtain the third temporary color image, and obtain the B-channel grayscale image of the third temporary color image. Repeat this step and record the number of repeated steps C1. When C1 = C, increase the third difference to Z2 until |Z - Z1| < Z2, where the third temporary angle is the third angle, the third temporary color image is the third color image, and the B-channel grayscale image of the third temporary color image is the B-channel grayscale image of the third color image.

[0104] By the above steps, it is possible to avoid repeatedly and frequently adjusting the size of the third angle.

[0105] Specifically, when Z is greater than Z1, the third temporary angle can be decreased, and when Z is less than Z1, the third temporary angle can be increased.

[0106] In some embodiments of the present invention, the second angle is less than the first angle and greater than the third angle, or, the second angle is greater than the first angle and less than the third angle.

[0107] Specifically, color images exist in two forms: RGB and BGR. When the target image is in BGR format, the second angle is smaller than the first angle and larger than the third angle. When the target image is in RGB format, the second angle is larger than the first angle and smaller than the third angle.

[0108] Specifically, the first angle, the second angle, and the third angle are the angles between the direction of the light emitted from the ring light source and the horizontal plane.

[0109] In some embodiments of the present invention, the following step is further included: detecting the target color image.

[0110] Specifically, the target color image is inspected to detect surface defects in the workpiece to be inspected.

[0111] This invention also provides a surface defect detection device, which can implement any step of the above-described surface defect detection method.

[0112] Referring to Figures 1 to 8, the surface defect detection device includes a low-angle ring light source; a medium-angle ring light source; and a high-angle ring light source; the low-angle ring light source, the medium-angle ring light source, and the high-angle ring light source are stacked sequentially; a first camera is located above the high-angle ring light source and is used to obtain a first color image, a second color image, and a third color image; an AOI ring light source; a second camera is located above the AOI ring light source and is used to obtain a test color image; a target image determination module is connected to the first camera and the second camera and is used to obtain the first color image, the second color image, and the third color image, and is also used to obtain the first target grayscale value, the second target grayscale value, and the third target grayscale value of the test color image, and is capable of modifying and synthesizing the R channel grayscale image of the first color image, the G channel grayscale image of the second color image, and the B channel grayscale image of the third color image.

[0113] The workpiece to be inspected can be placed under an AOI ring light source, and a second camera can be used to capture images of the workpiece to obtain a test color image. The host computer can then determine the grayscale values ​​of the first, second, and third targets. The workpiece can be placed under low-angle, medium-angle, and high-angle ring light sources, and these sources can be activated alternately. The first camera can then capture the first, second, and third color images respectively. The first color image obtained under low-angle ring light illumination can be analyzed by the host computer to obtain the R-channel grayscale image. The second color image obtained under medium-angle ring light illumination can be analyzed by the host computer to obtain the R-channel grayscale image. The image yields a G-channel grayscale image, and a third color image obtained under high-angle ring light illumination. The host computer disassembles the third color image to obtain a B-channel grayscale image. The host computer modifies the grayscale values ​​of the R-channel grayscale image of the first color image, the G-channel grayscale image of the second color image, and the B-channel grayscale image of the third color image. This modifies the grayscale values ​​of the R-channel grayscale image to a first target grayscale value, the G-channel grayscale image to a second target grayscale value, and the B-channel grayscale image to a third target grayscale value. These are then synthesized to obtain the target color image, which approximates the effect of illumination under AOI ring light. This surface defect detection device has low debugging difficulty and a short debugging process, and can meet detection requirements.

[0114] Specifically, the first camera is a black and white camera, and the second camera is a color camera.

[0115] This invention also provides an electronic device, which includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the above-described surface defect detection method.

[0116] This invention also provides a non-transitory computer-readable storage medium storing computer instructions, which are used to cause a computer to execute the above-described surface defect detection method.

[0117] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A surface defect detection method, characterized in that, It includes the following steps: obtaining a first color image under ring light illumination at a first angle, and obtaining the grayscale image of the R channel of the first color image; obtaining a second color image under ring light illumination at a second angle, and obtaining the grayscale image of the G channel of the second color image; obtaining a third color image under ring light illumination at a third angle, and obtaining the grayscale image of the B channel of the third color image; modifying the grayscale value of the R channel grayscale image to a first target grayscale value, modifying the grayscale value of the G channel grayscale image to a second target grayscale value, and modifying the grayscale value of the B channel grayscale image to a third target grayscale value; synthesizing the R channel grayscale image, the G channel grayscale image, and the B channel grayscale image to obtain a target color image.

2. The surface defect detection method according to claim 1, characterized in that, Before the step of "obtaining a first color image under ring light illumination at a first angle, and obtaining the grayscale image of the R channel of the first color image", the following steps are further included: obtaining a test color image under AOI ring light illumination; disassembling the test color image to obtain the first target grayscale value, the second target grayscale value, and the third target grayscale value.

3. The surface defect detection method according to claim 2, characterized in that, Obtaining a first color image under ring light illumination at a first angle, and obtaining the grayscale image of the R channel of the first color image includes the following steps: obtaining a first temporary color image under ring light illumination at a first temporary angle, and obtaining the grayscale image of the R channel of the first temporary color image; setting the grayscale value of the R channel grayscale image of the first temporary color image as X, the first target grayscale value as X1, and the first difference as X2; if |X - X1| < X2, the first temporary angle is the first angle, the first temporary color image is the first color image, and the grayscale image of the R channel of the first temporary color image is the grayscale image of the R channel of the first color image; if |X - X1| ≥ X2, increasing or decreasing the first temporary angle, and re-obtaining the first temporary color image under ring light illumination at the first temporary angle, and obtaining the grayscale image of the R channel of the first temporary color image, repeating this step until |X - X1| < X2, the first temporary angle is the first angle, the first temporary color image is the first color image, and the grayscale image of the R channel of the first temporary color image is the grayscale image of the R channel of the first color image; obtaining the first angle, obtaining the first color image, and obtaining the grayscale image of the R channel of the first color image.

4. The surface defect detection method according to claim 2, characterized in that, Under the ring light illumination at the second angle, a second color image is obtained, and the grayscale image of the G channel of the second color image is obtained, including the following steps: Under the ring light illumination at the second temporary angle, a second temporary color image is obtained, and the grayscale image of the G channel of the second temporary color image is obtained; Let the grayscale value of the grayscale image of the G channel of the second temporary color image be Y, the second target grayscale value be Y1, and the second difference be Y2; If |Y - Y1| < Y2, the second temporary angle is the second angle, the second temporary color image is the second color image, and the grayscale image of the G channel of the second temporary color image is the grayscale image of the G channel of the second color image; If |Y - Y1| ≥ Y2, increase or decrease the second temporary angle, and re-obtain the second temporary color image under the ring light illumination at the second temporary angle, and obtain the grayscale image of the G channel of the second temporary color image, and repeat this step until |Y - Y1| < Y2, the second temporary angle is the second angle, the second temporary color image is the second color image, and the grayscale image of the G channel of the second temporary color image is the grayscale image of the G channel of the second color image; Obtain the second angle, obtain the second color image, and obtain the grayscale image of the G channel of the second color image.

5. The surface defect detection method according to claim 2, characterized in that, Under the ring light illumination at the third angle, a third color image is obtained, and the grayscale image of the B channel of the third color image is obtained, including the following steps: Under the ring light illumination at the third temporary angle, a third temporary color image is obtained, and the grayscale image of the B channel of the third temporary color image is obtained; Let the grayscale value of the grayscale image of the B channel of the third temporary color image be Z, the third target grayscale value be Z1, and the third difference be Z2; If |Z - Z1| < Z2, the third temporary angle is the third angle, the third temporary color image is the third color image, and the grayscale image of the B channel of the third temporary color image is the grayscale image of the B channel of the third color image; If |Z - Z1| ≥ Z2, increase or decrease the third temporary angle, and re-obtain the third temporary color image under the ring light illumination at the third temporary angle, and obtain the grayscale image of the B channel of the third temporary color image, and repeat this step until |Z - Z1| < Z2, the third temporary angle is the third angle, the third temporary color image is the third color image, and the grayscale image of the B channel of the third temporary color image is the grayscale image of the B channel of the third color image; Obtain the third angle, obtain the third color image, and obtain the grayscale image of the B channel of the third color image.

6. The surface defect detection method according to claim 1, characterized in that, The second angle is less than the first angle and greater than the third angle, or, the second angle is greater than the first angle and less than the third angle.

7. The surface defect detection method according to claim 1, characterized in that, It further includes the following steps: detecting the target color image.

8. A surface defect detection device, characterized in that, Including: Low-angle ring light source; Medium-angle ring light source; High-angle ring light source; The low-angle ring light source, the medium-angle ring light source, and the high-angle ring light source are stacked sequentially. A first camera is located above the high-angle ring light source and is used to obtain a first color image, a second color image, and a third color image. An AOI ring light source is also present. A second camera is located above the AOI ring light source and is used to obtain a test color image. A target image determination module is connected to the first camera and the second camera and is used to obtain the first color image, the second color image, and the third color image. It is also used to obtain the first target grayscale value, the second target grayscale value, and the third target grayscale value of the test color image, and is capable of modifying and synthesizing the R channel grayscale image of the first color image, the G channel grayscale image of the second color image, and the B channel grayscale image of the third color image.

9. An electronic device, characterized in that, include: At least one processor; A memory, communicatively connected to at least one of the processors; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 7.