Method, apparatus and medium for detecting lens defects
By capturing lens images at different focal lengths and combining image attributes with rectangular analysis, the problem of detecting defects at different depths in lenses was solved, achieving efficient and accurate defect identification.
Patent Information
- Application Number
- CN202310403665.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-11
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2043-04-11
AI Technical Summary
Existing technologies struggle to detect defects at different depths in lenses, especially since deep defects are small, adhere to the background, and are not in the camera's focus position, making it difficult to fully capture them in a single image.
By taking lens images at multiple different focal lengths, suspected defects are identified based on image attributes, including location information. It is determined whether preset slope and image size offset conditions are met, and defects are identified by combining gradient rectangles and contour rectangles. Suspected defects in lens images are then identified.
It enables accurate detection of defects at different depths in lenses, improving detection efficiency and accuracy.
Smart Images

Figure CN116539617B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of lens defect detection technology, and in particular to a method for detecting lens defects, a device for detecting lens defects, and a computer-readable storage medium. Background Technology
[0002] Currently, the number of hardware products and content resources related to head-mounted display devices is constantly increasing, and with the growing number of users, the production volume is also increasing. To ensure the widespread application of head-mounted display devices and a good user experience, the display screen must achieve good resolution and be free of dead pixels and dirt. At present, in the production process of head-mounted display devices, defects on the lens surface can be effectively distinguished using software algorithms.
[0003] However, for defects at different depths of the lens, it is difficult to detect defects at different depths of the lens because these defects have small areas, are adhered to the background, are not in the camera's focus position, and cannot all be shown in one image. Summary of the Invention
[0004] The main objective of this application is to provide a method for detecting lens defects, a device for detecting lens defects, and a computer-readable storage medium, aiming to solve the technical problem that it is difficult to detect defects at different depths in lenses in the prior art.
[0005] To achieve the above objectives, this application provides a method for detecting lens defects, the method comprising:
[0006] The lens images of the lens to be tested are acquired at multiple different focal lengths, and the image attributes of the lens images are used to determine whether there are suspected defects in all the lens images. The image attributes include the position information of the lens images.
[0007] If the suspected defect is present in all of the lens images, then the suspected defect is determined to be the target defect of the lens to be tested.
[0008] For example, the step of determining whether a suspected defect exists in all the lens images based on the image attributes of the lens images includes:
[0009] Determine the center point of the region of interest of any two target lens images in the preset defect region of interest, and determine the reference center point of the two target lens images based on the center point of the region;
[0010] Determine the center point of the first defect of the first undetermined defect in one of the target lens images, and the center point of the second defect of the second undetermined defect in another target lens image;
[0011] Based on the reference center point, the first defect center point, and the second defect center point, it is determined whether the undetermined defects in all the lens images meet the preset slope condition, and whether the undetermined defects in all the lens images meet the preset image size offset condition.
[0012] If the suspected defects in all the lens images satisfy the preset slope condition and the preset image size offset condition, then it is determined that there are suspected defects in all the lens images.
[0013] For example, the step of determining whether the undetermined defects in all the lens images satisfy a preset slope condition includes:
[0014] Determine the first slope between the reference center point and the first defect center point, the second slope between the reference center point and the second defect center point, and the third slope between the first defect center point and the second defect center point;
[0015] When the variance between the first slope, the second slope, and the third slope in two target lens images is less than a preset first threshold, it is determined that the undetermined defects in all the lens images satisfy the preset slope condition.
[0016] For example, the step of determining whether the undetermined defects in all the lens images satisfy the preset image size offset condition includes:
[0017] Determine a first distance between the first defect center point and the reference center point, and a second distance between the second defect center point and the reference center point;
[0018] Determine the maximum distance of a first contour of the defect to be determined in one of the target lens images, and the maximum distance of a second contour of the defect to be determined in another target lens image;
[0019] The image size offset is determined based on the first distance, the second distance, the maximum distance of the first contour, and the maximum distance of the second contour.
[0020] A first distance difference between the first distance and the second distance is determined. When the first distance difference between any two target lens images is less than the image size offset, it is determined that the undetermined defects in all the lens images meet the preset image size offset condition.
[0021] For example, the step of determining the image size offset based on the first distance, the second distance, the first maximum contour distance, and the second maximum contour distance includes:
[0022] Determine the first distance sum of the first distance and the second distance;
[0023] Determine a second distance sum of the maximum distance of the first contour and the maximum distance of the second contour;
[0024] Determine a second distance difference between the maximum distance of the first contour and the maximum distance of the second contour;
[0025] The image size offset is determined based on the ratio between the first distance sum, the second distance sum, and the second distance difference.
[0026] For example, before the step of determining the suspected defect as a target defect of the lens to be tested, the method further includes:
[0027] Determine the gradient rectangle and contour rectangle of the suspected defect in any two target lens images;
[0028] Based on the gradient rectangle and the contour rectangle, it is determined whether the suspected defect is the target defect.
[0029] For example, the step of determining the gradient rectangle and contour rectangle of the suspected defect in any two target lens images includes:
[0030] Traverse the pixels of the target lens image and determine the pixel region where the gradient change value is greater than a preset second threshold as the gradient rectangle of the suspected defect;
[0031] The target lens image is binarized, and the bounding rectangle of the connected region with the largest black pixel is determined as the outline rectangle of the suspected defect.
[0032] For example, the step of determining whether the suspected defect is a target defect based on the gradient rectangle and the contour rectangle includes:
[0033] Determine the intersection area of the gradient rectangle and the outline rectangle;
[0034] Determine the target area between the gradient rectangle and the outline rectangle, wherein the target area is the larger of the area of the gradient rectangle and the area of the outline rectangle;
[0035] If the intersection ratio is greater than a preset third threshold and the number of black pixels in the target area is greater than a preset fourth threshold, then the suspected defect is determined to be a target defect, wherein the intersection ratio is the ratio of the intersection area to the target area.
[0036] This application also provides a lens defect detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps of the lens defect detection method described above.
[0037] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the lens defect detection method described above.
[0038] This application proposes a lens defect detection method, lens defect detection device, and computer-readable storage medium. The method acquires lens images of a lens under test taken at multiple different focal lengths, and determines whether a suspected defect exists in all the lens images based on the image attributes of the lens images. The image attributes include the positional information of the lens images. If the suspected defect exists in all the lens images, the suspected defect is determined to be the target defect of the lens under test.
[0039] Due to the unique depth characteristics of lens defects, defects at different depths are difficult to detect. Therefore, this application proposes a method to capture images of the lens under test at different focal lengths by focusing the camera at different depths, thereby obtaining lens images that may contain defects at different depths. Suspected defects are then identified within these images. Once it is confirmed that a suspected defect exists in all lens images, the suspected defect can be identified as the target defect. This method of lens defect determination can detect lens defects at different depths with high accuracy and improved production line inspection efficiency. Attached Figure Description
[0040] Figure 1 This is a schematic diagram of the structure of the operating device of the hardware operating environment involved in the embodiments of this application;
[0041] Figure 2 This is a schematic flowchart of an embodiment of the lens defect detection method involved in the present application.
[0042] Figure 3 This is a schematic diagram of a depth defect in one embodiment of the lens defect detection method involved in the present application.
[0043] Figure 4 This is a schematic diagram of the first gradient rectangle of an embodiment of the lens defect detection method involved in the present application;
[0044] Figure 5 This is a schematic diagram of the second gradient rectangle of an embodiment of the lens defect detection method involved in the present application;
[0045] Figure 6 This is a schematic diagram of the first contour rectangle of an embodiment of the lens defect detection method involved in the present application.
[0046] Figure 7 This is a schematic diagram of the second contour rectangle of an embodiment of the lens defect detection method involved in the present application.
[0047] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0048] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.
[0049] Reference Figure 1 , Figure 1 This is a schematic diagram of the operating device structure of the hardware operating environment involved in the embodiments of this application.
[0050] like Figure 1 As shown, the operating device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed random access memory (RAM) or a stable non-volatile memory (NVM), such as a disk drive. The memory 1005 may also optionally be a storage device independent of the aforementioned processor 1001.
[0051] Those skilled in the art will understand that Figure 1 The structure shown does not constitute a limitation on the operating equipment and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0052] like Figure 1 As shown, the memory 1005, which serves as a storage medium, may include an operating system, a data storage module, a network communication module, a user interface module, and computer programs.
[0053] exist Figure 1 In the illustrated operating device, the network interface 1004 is mainly used for data communication with other devices; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and memory 1005 in the operating device of this application can be disposed in the operating device, and the operating device calls the computer program stored in the memory 1005 through the processor 1001 and performs the following operations:
[0054] The lens images of the lens to be tested are acquired at multiple different focal lengths, and the image attributes of the lens images are used to determine whether there are suspected defects in all the lens images. The image attributes include the position information of the lens images.
[0055] If the suspected defect is present in all of the lens images, then the suspected defect is determined to be the target defect of the lens to be tested.
[0056] In one embodiment, the processor 1001 may invoke a computer program stored in the memory 1005 and further perform the following operations:
[0057] The step of determining whether a suspected defect exists in all lens images based on the image attributes of the lens images includes:
[0058] Determine the center point of the region of interest of any two target lens images in the preset defect region of interest, and determine the reference center point of the two target lens images based on the center point of the region;
[0059] Determine the center point of the first defect of the first undetermined defect in one of the target lens images, and the center point of the second defect of the second undetermined defect in another target lens image;
[0060] Based on the reference center point, the first defect center point, and the second defect center point, it is determined whether the undetermined defects in all the lens images meet the preset slope condition, and whether the undetermined defects in all the lens images meet the preset image size offset condition.
[0061] If the suspected defects in all the lens images satisfy the preset slope condition and the preset image size offset condition, then it is determined that there are suspected defects in all the lens images.
[0062] In one embodiment, the processor 1001 may invoke a computer program stored in the memory 1005 and further perform the following operations:
[0063] The step of determining whether the undetermined defects in all the lens images satisfy the preset slope condition includes:
[0064] Determine the first slope between the reference center point and the first defect center point, the second slope between the reference center point and the second defect center point, and the third slope between the first defect center point and the second defect center point;
[0065] When the variance between the first slope, the second slope, and the third slope in two target lens images is less than a preset first threshold, it is determined that the undetermined defects in all the lens images satisfy the preset slope condition.
[0066] In one embodiment, the processor 1001 may invoke a computer program stored in the memory 1005 and further perform the following operations:
[0067] The step of determining whether the undetermined defects in all the lens images meet the preset image size offset condition includes:
[0068] Determine a first distance between the first defect center point and the reference center point, and a second distance between the second defect center point and the reference center point;
[0069] Determine the maximum distance of a first contour of the defect to be determined in one of the target lens images, and the maximum distance of a second contour of the defect to be determined in another target lens image;
[0070] The image size offset is determined based on the first distance, the second distance, the maximum distance of the first contour, and the maximum distance of the second contour.
[0071] A first distance difference between the first distance and the second distance is determined. When the first distance difference between any two target lens images is less than the image size offset, it is determined that the undetermined defects in all the lens images meet the preset image size offset condition.
[0072] In one embodiment, the processor 1001 may invoke a computer program stored in the memory 1005 and further perform the following operations:
[0073] The step of determining the image size offset based on the first distance, the second distance, the maximum distance of the first contour, and the maximum distance of the second contour includes:
[0074] Determine the first distance sum of the first distance and the second distance;
[0075] Determine a second distance sum of the maximum distance of the first contour and the maximum distance of the second contour;
[0076] Determine a second distance difference between the maximum distance of the first contour and the maximum distance of the second contour;
[0077] The image size offset is determined based on the ratio between the first distance sum, the second distance sum, and the second distance difference.
[0078] In one embodiment, the processor 1001 may invoke a computer program stored in the memory 1005 and further perform the following operations:
[0079] Before the step of determining the suspected defect as the target defect of the lens to be tested, the method further includes:
[0080] Determine the gradient rectangle and contour rectangle of the suspected defect in any two target lens images;
[0081] Based on the gradient rectangle and the contour rectangle, it is determined whether the suspected defect is the target defect.
[0082] In one embodiment, the processor 1001 may invoke a computer program stored in the memory 1005 and further perform the following operations:
[0083] The step of determining the gradient rectangle and contour rectangle of the suspected defect in any two target lens images includes:
[0084] Traverse the pixels of the target lens image and determine the pixel region where the gradient change value is greater than a preset second threshold as the gradient rectangle of the suspected defect;
[0085] The target lens image is binarized, and the bounding rectangle of the connected region with the largest black pixel is determined as the outline rectangle of the suspected defect.
[0086] In one embodiment, the processor 1001 may invoke a computer program stored in the memory 1005 and further perform the following operations:
[0087] The step of determining whether the suspected defect is a target defect based on the gradient rectangle and the contour rectangle includes:
[0088] Determine the intersection area of the gradient rectangle and the outline rectangle;
[0089] Determine the target area between the gradient rectangle and the outline rectangle, wherein the target area is the larger of the area of the gradient rectangle and the area of the outline rectangle;
[0090] If the intersection ratio is greater than a preset third threshold and the number of black pixels in the target area is greater than a preset fourth threshold, then the suspected defect is determined to be a target defect, wherein the intersection ratio is the ratio of the intersection area to the target area.
[0091] This application provides a method for detecting lens defects, referring to... Figure 2 In a first embodiment of the lens defect detection method, the method includes:
[0092] Step S10: Obtain lens images of the lens to be tested taken at multiple different focal lengths, and determine whether there are suspected defects in all the lens images based on the image attributes of the lens images, wherein the image attributes include the position information of the lens images.
[0093] Step S20: If the suspected defect exists in all the lens images, then the suspected defect is determined to be the target defect of the lens to be tested.
[0094] Reference Figure 3 Depth defects can be located anywhere on the lens. To obtain a clear image of the defect, the camera can be focused at different depths of the lens, i.e., the camera's focal length can be continuously changed to focus on the defect at different depths. The characteristic of defects at different depths on the lens displayed in the image is that the closer the focus position is to the defect position, the clearer the captured lens image. Therefore, in this embodiment, the focal length is adjusted from the lens surface to the bottom surface, and multiple images are captured during the adjustment process. The captured images are then analyzed. In this embodiment, the number of captured lens images is not limited. In one implementation, 10 images at 10 different focal lengths can be captured, and defects in each image can be detected. The following explanation uses two images at two different focal lengths as an example. In one embodiment, 10 lens images at 10 different focal lengths are traversed. Subsequent detection steps are performed between each pair of the first lens image and the remaining nine lens images, and between each pair of the second lens image and the remaining eight lens images, and so on. Only when the results of all pairwise judgments prove the existence of a suspected defect is the suspected defect identified as the target defect.
[0095] After acquiring original images of the lens under test at different focal lengths, the effective region to be detected is extracted from the original image to eliminate interference. In one embodiment, the original image is first binarized using an adaptive binarization method to obtain a binary image; then, the contour of the binary image is determined, and the largest contour in the binary image is found. To adaptively select the region of interest, the original image can be scaled at different ratios to obtain contour images of different sizes. Finally, the effective region corresponding to the largest contour is obtained through Fourier transform, convolution, inverse Fourier transform, and binarization, and suspected defects in the effective region of the lens image are identified. Subsequent detection steps are performed for each suspected defect. In another embodiment, two Gaussian filters with different parameters are first subtracted to obtain a bandpass filter. Then, a convolution operation is performed on the image based on this bandpass filter. After the convolution operation, an inverse Fourier transform is performed, followed by a mask operation to obtain the maximum and minimum grayscale values of the image. Finally, binarization is performed to obtain the effective region.
[0096] After confirming the presence of suspected defects in all lens images, the suspected defects are identified as target defects, specifically depth defects in the lens under test. In one embodiment, the target image containing the depth defect with the highest contrast value is determined, and the depth information of the defect is determined in the clearest target image; that is, the depth of different defects in the lens under test is calculated using the clearest target image.
[0097] In this embodiment, the method for identifying defects and the method for determining the depth information of defects are not limited.
[0098] In this embodiment, lens images of the lens to be tested are acquired at multiple different focal lengths, and it is determined whether a suspected defect exists in all of the lens images based on the image attributes of the lens images, wherein the image attributes include the position information of the lens images; if the suspected defect exists in all of the lens images, the suspected defect is determined to be the target defect of the lens to be tested.
[0099] Due to the unique depth characteristics of lens defects, defects at different depths are difficult to detect. Therefore, this embodiment proposes to capture images of the lens under test at different focal lengths by focusing the camera at different depths, thus obtaining lens images that may contain defects at different depths. Suspected defects are then identified within these images. Once it is confirmed that a suspected defect exists in all lens images, the suspected defect can be identified as the target defect. This method of lens defect determination can detect lens defects at different depths with high accuracy and improved production line inspection efficiency.
[0100] This application provides a method for detecting lens defects. In one embodiment of the method, the step of determining whether a suspected defect exists in all lens images based on the image attributes of the lens images includes:
[0101] Determine the center point of the region of interest of any two target lens images in the preset defect region of interest, and determine the reference center point of the two target lens images based on the center point of the region;
[0102] Determine the center point of the first defect of the first undetermined defect in one of the target lens images, and the center point of the second defect of the second undetermined defect in another target lens image;
[0103] Based on the reference center point, the first defect center point, and the second defect center point, it is determined whether the undetermined defects in all the lens images meet the preset slope condition, and whether the undetermined defects in all the lens images meet the preset image size offset condition.
[0104] If the suspected defects in all the lens images satisfy the preset slope condition and the preset image size offset condition, then it is determined that there are suspected defects in all the lens images.
[0105] In this embodiment, a method is proposed to determine whether suspected defects exist in all lens images. This method determines whether suspected defects exist in all lens images by determining whether the suspected defects in all lens images satisfy preset slope conditions and preset image size offset conditions.
[0106] The image attributes of the lens image include point information such as the center point of the preset defect region of interest, the reference center point of the target lens image, and the defect center point of the defect to be determined.
[0107] First, any two lens images are selected as target lens images. The contours identified on the target lens images are all composed of contour points. The size of the region of interest in different images is calculated by using the coordinates of the largest and smallest contour points. The preset region of interest in different image regions of interest is then delineated.
[0108] Then, the center point of the preset defect region of interest in any two target lens images is determined. The center point of the region can be obtained by directly reading the region attributes of the defect region of interest. In one embodiment, the preset defect region of interest is a circular region, and its center point is the center of the preset defect region of interest. The center point of the region is obtained by directly reading the coordinates of the center of the preset defect region of interest.
[0109] Secondly, due to image size distortion and changes in focal length, the coordinate position of the same depth defect varies significantly across images with different focal lengths. For example, there might be only one defect when the image is out of focus, but three or more defects when it is in focus, or vice versa. Therefore, it is necessary to determine the reference center point of the two target lens images based on the region center point. In one embodiment, the average coordinate of the region center points corresponding to the two selected target lens images is used as the reference center point, thereby obtaining a precise reference center point that minimizes distortion.
[0110] Next, the first defect center point of the first undetermined defect in one of the target lens images and the second defect center point of the second undetermined defect in another target lens image are determined by image recognition. In this embodiment, the defect center point is determined by image recognition of the undetermined defect, and the method for determining the defect center point is not limited.
[0111] For example, the step of determining whether the undetermined defects in all the lens images satisfy a preset slope condition includes:
[0112] Determine the first slope between the reference center point and the first defect center point, the second slope between the reference center point and the second defect center point, and the third slope between the first defect center point and the second defect center point;
[0113] When the variance between the first slope, the second slope, and the third slope in two target lens images is less than a preset first threshold, it is determined that the undetermined defects in all the lens images satisfy the preset slope condition.
[0114] In this embodiment, a preset slope condition and a method for determining whether the undetermined defects in all lens images satisfy the preset slope condition are proposed.
[0115] The first slope between the reference center point and the first defect center point, the second slope between the reference center point and the second defect center point, and the third slope between the first defect center point and the second defect center point are determined using the slope calculation formula between the two points. In one embodiment, the reference center point is (x c y c The center point of the first defect is (x). i y i The center point of the second defect is (x). j y j The first slope is k. i =(y i -y c ) / (x i -x c The second slope is k.j =(y j -y c ) / (x j -x c The third slope is K = (y i -y j ) / (x i -x j ), when the first slope k of any two target lens images i Second slope k j When the variance of the three values of the first, second, and third slopes (K) is less than a preset first threshold, it is determined that the defects to be determined in all lens images satisfy the preset slope condition. In other words, images taken at different focal lengths are similar to being enlarged or reduced proportionally along the ray direction of the image center point. If the preset slope condition is met, it means that the reference center point, the first defect center point, and the second defect center point are on a straight line.
[0116] For example, the step of determining whether the undetermined defects in all the lens images satisfy the preset image size offset condition includes:
[0117] Determine a first distance between the first defect center point and the reference center point, and a second distance between the second defect center point and the reference center point;
[0118] Determine the maximum distance of a first contour of the defect to be determined in one of the target lens images, and the maximum distance of a second contour of the defect to be determined in another target lens image;
[0119] The image size offset is determined based on the first distance, the second distance, the maximum distance of the first contour, and the maximum distance of the second contour.
[0120] A first distance difference between the first distance and the second distance is determined. When the first distance difference between any two target lens images is less than the image size offset, it is determined that the undetermined defects in all the lens images meet the preset image size offset condition.
[0121] In this embodiment, a preset image size offset condition and a method for determining whether the undetermined defects in all lens images satisfy the preset image size offset condition are proposed.
[0122] The image size offset Δdistance is defined as follows: if the pixel distance of a line segment after imaging at the current focal length is 100 pixels and the pixel distance after imaging at another focal length is 300 pixels, then the image size offset Δdistance is 300-100=200 pixels.
[0123] Although the reference center point, the first defect center point, and the second defect center point can be determined under the premise of meeting the preset slope condition, and these three points are on a straight line, it cannot be directly concluded that the defect center point of the undetermined defect in any two target lens images is necessarily the same defect point. It is also necessary to determine whether the image size offset Δdistance corresponds to the positional change caused by the focal length change. That is, whether the image size offset Δdistance between any two target lens images matches the positional change caused by the focal length change. For example, if the image size offset Δdistance is 200 pixels, but the positional change caused by the focal length change is 190 pixels, then the camera shooting is inaccurate and cannot correspond to the actual focal length change.
[0124] The determination of the regional center point and the reference center point, as well as the determination of the first defect center point and the second defect center point, will not be elaborated here.
[0125] Then, by calculating the Euclidean distance, the first distance between the first defect center point and the reference center point, and the second distance between the second defect center point and the reference center point are determined; in one embodiment, the distance between the first defect center point A and the reference center point (x c y c The first distance is D. i The distance from the first defect center point B to the reference center point (x) c y c The second distance is D. j .
[0126] Next, the maximum distance of the first contour of the undetermined defect in one of the target lens images and the maximum distance of the second contour of the undetermined defect in another target lens image are determined; in one embodiment, contour information vector is obtained by traversing the contours of each undetermined defect in a preset region of interest. <point>`lnnerProfile_src` obtains the maximum distance of the profile of the undetermined defect based on the profile information. In one embodiment, the maximum distance of the defect profile can be determined by traversing each profile point on the profile of the undetermined defect and calculating the distance between any two profile points; that is, the distance between the two farthest profile points on the defect profile is determined as the maximum distance of the defect profile. Alternatively, the top-left point of each profile can be obtained based on the profile information.
[0127] Point i .x = lnnerProfile_src[i].x;
[0128] Point i .y = lnnerProfile_src[i].y;
[0129] And the coordinates of the bottom right point:
[0130] Point i+n .x=lnnerProfile_src[i+n].x;
[0131] Point i+n . y =lnnerProfile_src[i+n].y;
[0132] The top-left and bottom-right points are preset selection criteria. By continuously adjusting the subscripts of the contour points, the selected contour points are changed, and the maximum distance between the two contour points, distance1, is calculated. Similarly, the corresponding distances for other lens images are distance2, ..., distanceN, where N is the number of lens images captured.
[0133] Secondly, the image size offset Δdistance is calculated based on the first distance, the second distance, the maximum distance of the first contour, and the maximum distance of the second contour through the distance ratio relationship.
[0134] Finally, the focal length change corresponds to the image size offset Δdistance, which is the maximum actual offset in the physical size of the image. If the difference between the first distance and the second distance is greater than the image size offset Δdistance, it means that the defect center point of the undetermined defect in any two target lens images is not the same defect point. Conversely, if the difference between the first distances of any two target lens images is less than the image size offset, it can be determined that the undetermined defect in all lens images meets the preset image size offset condition, and the defect center point of the undetermined defect in all lens images is the same defect point.
[0135] For example, the step of determining the image size offset based on the first distance, the second distance, the first maximum contour distance, and the second maximum contour distance includes:
[0136] Determine the first distance sum of the first distance and the second distance;
[0137] Determine a second distance sum of the maximum distance of the first contour and the maximum distance of the second contour;
[0138] Determine a second distance difference between the maximum distance of the first contour and the maximum distance of the second contour;
[0139] The image size offset is determined based on the ratio between the first distance sum, the second distance sum, and the second distance difference.
[0140] In one embodiment, the sum of the first distances of the first distance and the second distance is determined to be D. i +D j The second distance, which is the sum of the maximum distance of the first contour and the maximum distance of the second contour, is determined as distance. j +distancei, the second distance difference between the maximum distance of the first contour and the maximum distance of the second contour is determined as distancej-distancei. Because of image size distortion and focal length changes, the image size offset Δdistance can be determined based on the ratio between the sum of the first distance, the sum of the second distance, and the second distance difference through the distance ratio relationship.
[0141]
[0142] In one embodiment, to obtain a more accurate calculation result, the image size offset Δdistance is calculated by taking the average of the first distance sum, the second distance sum, and the second distance difference.
[0143]
[0144] This application provides a method for detecting lens defects. In one embodiment of the method, before the step of determining the suspected defect as a target defect of the lens to be detected, the method further includes:
[0145] Determine the gradient rectangle and contour rectangle of the suspected defect in any two target lens images;
[0146] Based on the gradient rectangle and the contour rectangle, it is determined whether the suspected defect is the target defect.
[0147] Since image texture affects the image contrast of the defect area, even after determining that the suspected defects in all lens images meet the preset image size offset condition and that the defect center point of the suspected defects in all lens images is the same defect point, the final target defect cannot be directly determined by image contrast.
[0148] Therefore, in this embodiment, firstly, the gradient rectangle and contour rectangle of the suspected defect in any two target lens images are determined, and finally, the suspected defect is determined to be the target defect based on the gradient rectangle and contour rectangle.
[0149] For example, the step of determining the gradient rectangle and contour rectangle of the suspected defect in any two target lens images includes:
[0150] Traverse the pixels of the target lens image and determine the pixel region where the gradient change value is greater than a preset second threshold as the gradient rectangle of the suspected defect;
[0151] The target lens image is binarized, and the bounding rectangle of the connected region with the largest black pixel is determined as the outline rectangle of the suspected defect.
[0152] An n*n filter is applied to any two target lens images to remove interference points. Then, the pixels in each row and column are traversed, and gradient change information is statistically analyzed. The pixel region where the gradient change value is greater than a preset second threshold is identified as the region containing the gradient rectangle of the suspected defect. In one embodiment, the pixels of the target lens image are traversed from left to right, from top to bottom, from right to left, and from bottom to top. The leftmost value left1 (the minimum horizontal coordinate of the pixel when the gradient change value is greater than the preset second threshold), the topmost value top1 (the maximum vertical coordinate of the pixel when the gradient change value is greater than the preset second threshold), the rightmost value right1 (the maximum horizontal coordinate of the pixel when the gradient change value is greater than the preset second threshold), and the bottommost value bottom1 (the minimum vertical coordinate of the pixel when the gradient change value is greater than the preset second threshold) are determined. Then, the rectangular region Rect(left1, top1, right1-left1, bottom1-top1) is determined from the above four points. (Refer to...) Figure 4 The gradient rectangle, defined by the gradient change value, is rect1. (Refer to...) Figure 5 The gradient rectangle, determined by the gradient change value, is rect2.
[0153] The target lens image is binarized. In one embodiment, the image is binarized... Figure 4 The results of adaptive binarization are as follows: Figure 6 As shown, for Figure 5 The results of adaptive binarization are as follows: Figure 7 As shown. Then, the bounding rectangle of the largest black pixel connected region is determined as the outline rectangle of the suspected defect. In one embodiment, the black pixels in the binarized image are counted, the largest connected region of the black pixels is obtained, and the outline of the largest black pixel connected region is used to determine the defect. Figure 6 The outer rectangle is Rect_contours1, which is determined. Figure 7 The outer rectangle is Rect_contours2.
[0154] For example, the step of determining whether the suspected defect is a target defect based on the gradient rectangle and the contour rectangle includes:
[0155] Determine the intersection area of the gradient rectangle and the outline rectangle;
[0156] Determine the target area between the gradient rectangle and the outline rectangle, wherein the target area is the larger of the area of the gradient rectangle and the area of the outline rectangle;
[0157] If the intersection ratio is greater than a preset third threshold and the number of black pixels in the target area is greater than a preset fourth threshold, then the suspected defect is determined to be a target defect, wherein the intersection ratio is the ratio of the intersection area to the target area.
[0158] In one embodiment, the gradient rectangle rect1 and the contour rectangle Rect_contours1 are intersected, and the gradient rectangle rect2 and the contour rectangle Rect_contours2 are intersected to obtain the intersection area between the gradient rectangle and the contour rectangle.
[0159] The larger area between the gradient rectangle and the contour rectangle is determined as the target area, and the ratio of the intersection area to the target area is determined, i.e., the intersection ratio. The intersection ratio characterizes the degree of overlap between the gradient rectangle and the contour rectangle; the greater the overlap, the larger the intersection ratio. In one embodiment, Figure 4 The area A of the gradient rectangle rect1, Figure 6 Let B be the area of the outline rectangle Rect_contours1, and C be the area of the intersection of the gradient rectangle rect1 and the outline rectangle Rect_contours1. If A is greater than B, the intersection ratio is A / C; if B is greater than A, the intersection ratio is B / C.
[0160] If the number of black pixels in the target area is greater than the preset fourth threshold, that is, the number of black pixels in the largest connected region is greater than the preset fourth threshold (the reason for being less than the preset fourth threshold may be a misjudgment caused by image texture), and the intersection ratio is greater than the preset third threshold, then the suspected defect can be identified as the target defect. At this time, the depth of the target defect can be determined by the image of the target defect with the highest contrast.
[0161] Furthermore, this application embodiment also provides a lens defect detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps of the lens defect detection method described above.
[0162] Furthermore, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the lens defect detection method described above.
[0163] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0164] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to conventional technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0165] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.< / point>
Claims
1. A method for detecting lens defects, characterized in that, The method includes: The lens images of the lens to be tested are acquired at multiple different focal lengths, and the center point of the region of interest of any two target lens images in the preset defect region of interest is determined. The reference center point of the two target lens images is determined based on the center point of the region. Determine the center point of the first defect of the first undetermined defect in one of the target lens images, and the center point of the second defect of the second undetermined defect in another target lens image; Based on the reference center point, the first defect center point, and the second defect center point, a first slope between the reference center point and the first defect center point, a second slope between the reference center point and the second defect center point, and a third slope between the first defect center point and the second defect center point are determined. When the variance between the first slope, the second slope, and the third slope in the two target lens images is less than a preset first threshold, it is determined that the undetermined defects in all the lens images satisfy the preset slope condition, and the first distance between the center point of the first defect and the reference center point, and the second distance between the center point of the second defect and the reference center point are determined. Determine the maximum distance of a first contour of the defect to be determined in one of the target lens images, and the maximum distance of a second contour of the defect to be determined in another target lens image; The first distance is determined to be the sum of the first distance and the second distance. ; The second distance sum of the maximum distance of the first contour and the maximum distance of the second contour is determined as follows: ; The second distance difference between the maximum distance of the first contour and the maximum distance of the second contour is determined as follows: ; The image size offset is determined based on the ratio between the first distance sum, the second distance sum, and the second distance difference. : ; Determine the first distance difference between the first distance and the second distance. When the first distance difference between any two target lens images is less than the image size offset, determine that the undetermined defects in all the lens images meet the preset image size offset condition. If the suspected defects in all the lens images meet the preset slope condition and the preset image size offset condition, then it is determined that there are suspected defects in all the lens images. If the suspected defect is present in all of the lens images, then the suspected defect is determined to be the target defect of the lens to be tested.
2. The method for detecting lens defects as described in claim 1, characterized in that, Before the step of determining the suspected defect as the target defect of the lens to be tested, the method further includes: Determine the gradient rectangle and contour rectangle of the suspected defect in any two target lens images; Based on the gradient rectangle and the contour rectangle, it is determined whether the suspected defect is the target defect.
3. The method for detecting lens defects as described in claim 2, characterized in that, The step of determining the gradient rectangle and contour rectangle of the suspected defect in any two target lens images includes: Traverse the pixels of the target lens image and determine the pixel region where the gradient change value is greater than a preset second threshold as the gradient rectangle of the suspected defect; The target lens image is binarized, and the bounding rectangle of the connected region with the largest black pixel is determined as the outline rectangle of the suspected defect.
4. The method for detecting lens defects as described in claim 2, characterized in that, The step of determining whether the suspected defect is a target defect based on the gradient rectangle and the contour rectangle includes: Determine the intersection area of the gradient rectangle and the outline rectangle; Determine the target area between the gradient rectangle and the outline rectangle, wherein the target area is the larger of the area of the gradient rectangle and the area of the outline rectangle; If the intersection ratio is greater than a preset third threshold and the number of black pixels in the target area is greater than a preset fourth threshold, then the suspected defect is determined to be a target defect, wherein the intersection ratio is the ratio of the intersection area to the target area.
5. A lens defect detection device, characterized in that, The lens defect detection device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the lens defect detection method as described in any one of claims 1 to 4.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the lens defect detection method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Screen defect detection method and device
CN115187593A
System and method for inspecting defects
KR1020160049571A