Image detection method and device

By performing affine transformation and fault type feature screening on the image to be detected, a reference image is generated for pixel-by-pixel comparison, which solves the problem of misjudgment in complex scenes by traditional image detection methods and achieves high-accuracy and robust fault identification.

CN121810587APending Publication Date: 2026-04-07HYC (CHENGDU) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-10
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Traditional image detection methods rely heavily on idealized reference standards or static parameters, making it difficult to adapt to complex and ever-changing real-world scenarios, resulting in high rates of misjudgment and false alarms.

Method used

An intermediate image is generated by performing an affine transformation on the image to be detected. A screening strategy is designed to select pixel values ​​that meet the conditions based on the pixel features of the fault type, a reference image is generated, and the target fault area is determined by pixel-by-pixel comparison.

Benefits of technology

The algorithm's robustness has been enhanced, the false detection rate has been reduced, the accuracy and precision of fault identification have been improved, and the subjectivity and possibility of omissions in manual interpretation have been reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121810587A_ABST
    Figure CN121810587A_ABST
Patent Text Reader

Abstract

The invention relates to an image detection method and device. The method comprises the following steps: acquiring a to-be-detected image; performing affine transformation on the to-be-detected image to obtain an intermediate image; respectively comparing pixel values of corresponding pixels between the to-be-detected image and the intermediate image by using a preset screening strategy, and screening a pixel value meeting a preset requirement from the corresponding pixels to obtain a reference image; wherein the screening strategy is determined based on pixel features corresponding to a to-be-detected fault type; and comparing the pixel value of each pixel of the to-be-detected image with the reference image, and determining a target fault area in the to-be-detected image. By adopting the method, the precision and efficiency of image detection can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of automation, in particular to an image detection method and device. BACKGROUND

[0002] With the development of computer vision and industrial automation detection technology, the demand for automatic detection of small defects such as camera lens internal dust is increasingly prominent. In the traditional technology, for the detection of fault areas in the image, the standard template comparison method or the pixel analysis method based on fixed threshold is mainly used. The former needs to obtain an ideal image without defects as a template, and matches the image to be detected with it pixel by pixel; the latter sets a global or local pixel value threshold according to experience, and determines the area exceeding the range as abnormal. However, the detection effect of the current two methods is highly dependent on the ideal reference standard or static parameters, and it is difficult to adapt to complex and variable real scenes. It is easy to be misjudged as a fault, thereby producing a large number of false positives. SUMMARY

[0003] Therefore, it is necessary to provide an image detection method and device in view of the above technical problems.

[0004] In a first aspect, the present application provides an image detection method. The method comprises:

[0005] obtaining a to-be-detected image;

[0006] performing affine transformation on the to-be-detected image to obtain an intermediate image;

[0007] comparing pixel values of corresponding pixels between the to-be-detected image and the intermediate image respectively by using a preset screening strategy, screening pixel values meeting a preset requirement from the corresponding pixels to obtain a reference image; wherein the screening strategy is determined based on pixel features corresponding to a to-be-detected fault type;

[0008] comparing pixel values of each pixel between the to-be-detected image and the reference image to determine a target fault area in the to-be-detected image.

[0009] In one embodiment, the comparing pixel values of each pixel between the to-be-detected image and the reference image to determine the target fault area in the to-be-detected image comprises:

[0010] comparing pixel values of each pixel between the to-be-detected image and the reference image to determine a first candidate fault area in the to-be-detected image;

[0011] obtaining a reference pixel of a to-be-detected fault;

[0012] matching pixels of the to-be-detected image according to the reference pixel to determine a second candidate fault area;

[0013] determine a target fault region in the image to be detected based on the first candidate fault region and the second candidate fault region.

[0014] In one of the embodiments, the matching of the pixels of the image to be detected based on the reference pixels to determine the second candidate fault region comprises:

[0015] determining a similarity coefficient between the reference pixels and each local region of the image to be detected;

[0016] in a case where the region similarity coefficient meets a preset condition, determining the region as the second candidate fault region.

[0017] In one of the embodiments, the obtaining of the image to be detected comprises:

[0018] obtaining an initial image;

[0019] performing a grayscale processing on the initial image to obtain a grayscale image;

[0020] performing a contrast enhancement on the grayscale image to obtain the image to be detected.

[0021] In one of the embodiments, the image to be detected is obtained by a camera; the fault to be detected comprises a camera lens dust; and the method further comprises:

[0022] obtaining target fault regions corresponding to a plurality of images to be detected;

[0023] determining a camera lens dust region based on the target fault regions corresponding to the plurality of images to be detected.

[0024] In one of the embodiments, the determining of the camera lens dust region based on the target fault regions corresponding to the plurality of images to be detected comprises:

[0025] determining a candidate dust region of the camera lens based on the target fault regions corresponding to the plurality of images to be detected;

[0026] performing a first detection on the candidate dust region to determine a first detection result; wherein the first detection is used to determine whether the dust region meets a preset area requirement;

[0027] performing a second detection on the candidate dust region to determine a second detection result; wherein the second detection is used to determine whether the dust meets a preset shape requirement;

[0028] in a case where both the first detection result and the second detection result pass, determining the candidate dust region as the camera lens dust region.

[0029] In one embodiment, the image to be detected is obtained by a camera; the fault to be detected includes camera lens dust; the method further comprises:

[0030] performing different affine transformations on the image to be detected to obtain a plurality of intermediate images;

[0031] determining reference images based on the plurality of intermediate images and the image to be detected respectively; and determining a plurality of target fault regions based on the reference images and the image to be detected;

[0032] determining the camera lens dust region according to the plurality of target fault regions.

[0033] In one embodiment, the comparing of the pixel values of the corresponding pixels between the image to be detected and the intermediate image, the screening of the pixel values meeting the preset requirements from the corresponding pixels, and the obtaining of the reference image, comprise:

[0034] comparing the pixel values of the pixel positions in the image to be detected with the pixel values of the corresponding pixel positions in the intermediate image, and screening the larger pixel values of each pixel position as the target pixel values of the corresponding pixel positions;

[0035] determining the reference image based on the target pixel values.

[0036] In one embodiment, the comparing of the pixel values of each pixel between the image to be detected and the reference image, and the determining of the target fault region in the image to be detected, comprise:

[0037] performing quotient processing on the pixel values of the pixel positions in the image to be detected and the pixel values of the corresponding pixel positions in the intermediate image to obtain a fault parameter;

[0038] in a case where the fault parameter meets a preset requirement, determining a pixel region corresponding to the fault parameter as a target fault region.

[0039] In a second aspect, the present application further provides an image detection device. The device comprises:

[0040] an image acquisition module configured to acquire an image to be detected;

[0041] an image transformation module configured to perform affine transformation on the image to be detected to obtain an intermediate image;

[0042] The image generation module is used to compare the pixel values ​​of corresponding pixels between the image to be detected and the intermediate image using a preset filtering strategy, and filter the pixel values ​​that meet the preset requirements from the corresponding pixels to obtain a reference image; wherein, the filtering strategy is determined based on the pixel features corresponding to the fault type to be detected.

[0043] The fault detection module is used to compare the pixel values ​​of each pixel in the image to be detected with the reference image to determine the target fault area in the image to be detected.

[0044] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the image detection method as described in any one of the embodiments of this disclosure.

[0045] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the image detection method as described in any one of the embodiments of this disclosure.

[0046] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the image detection method as described in any one of the embodiments of this disclosure.

[0047] The aforementioned image detection method and apparatus perform an affine transformation on the image to be detected to generate an intermediate image. A filtering strategy is designed based on the pixel features corresponding to the fault type. Pixel values ​​meeting certain conditions are selected from corresponding positions in two images to form a reference image. The fault region is located by comparing the pixels of the original image and the reference image. Introducing an affine transformation can, to some extent, unify differences in image angle, scale, or position, enhancing the algorithm's robustness to images captured under different shooting conditions. Designing a pixel filtering strategy for specific fault types effectively extracts pixel features of normal or typical faults. By generating a reference image through comparison, non-critical factors such as lighting changes and background interference are filtered out, reducing the false detection rate. A pixel-by-pixel comparison between the original image and the generated reference image directly highlights abnormal areas, making fault location more accurate and intuitive, reducing the subjectivity and potential for omissions in manual interpretation. This method improves fault identification accuracy by combining structured image processing with targeted filtering. Attached Figure Description

[0048] Figure 1 This is an application environment diagram of the image detection method in one embodiment;

[0049] Figure 2 This is a flowchart illustrating an image detection method in one embodiment;

[0050] Figure 3 Fig. 1 is a schematic diagram of spot detection in an embodiment;

[0051] Figure 4 Fig. 2 is a schematic diagram of fixed black spots in imaging of dust in an embodiment;

[0052] Figure 5 Fig. 3 is a schematic diagram of reference pixels in an embodiment;

[0053] Figure 6 Fig. 4 is a schematic diagram of matching of pixels to be detected in an embodiment;

[0054] Figure 7 Fig. 5 is a schematic diagram of a flow of implementation of an image detection method in an embodiment;

[0055] Figure 8 Fig. 6 is a structural block diagram of an image detection device in an embodiment;

[0056] Figure 9 Fig. 7 is an internal structural diagram of a computer device in an embodiment. DETAILED DESCRIPTION

[0057] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not used to limit the present application.

[0058] The image detection method provided by the embodiments of the present application can be applied to, for example, Figure 1The application environment is shown. In the application environment, the terminal 102 communicates with the server 104 through a network. The data storage system can store data required to be processed by the server 104. The data storage system can be integrated on the server 104, or placed on a cloud or other network server. In the application environment, the terminal 102 can be used to shoot or upload a to-be-detected image (such as an image of a surface of an industrial part, a test picture shot by an optical lens, etc.) to the server 104; the server 104 is configured to perform the method in the embodiments of the present application: performing affine transformation on the to-be-detected image to generate an intermediate image; according to a preset screening strategy for a specific fault type (such as lens dust, scratch, stain), comparing pixel values of corresponding pixels in the to-be-detected image and the intermediate image, and screening pixel values meeting preset requirements to generate a reference image; finally, by comparing the to-be-detected image and the reference image pixel by pixel, a target fault area in the image is determined and located. After processing is completed, the server 104 can return the detection result (such as an image or a report identifying the fault area) to the terminal 102, or store it in the data storage system for subsequent analysis. The terminal 102 can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, Internet of Things devices, and portable wearable devices. The Internet of Things device can be a smart speaker, a smart television, a smart air conditioner, a smart vehicle device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The server 104 can be implemented by an independent server or a server cluster composed of multiple servers.

[0059] In one embodiment, as shown in Figure 2 , an image detection method is provided. The method is applied to a server in Figure 1 for example, and includes the following steps:

[0060] Step S200, a to-be-detected image is acquired.

[0061] The to-be-detected image can be an image obtained by a camera, such as an image of a surface of an industrial part or a test picture shot by an optical lens. The image can contain a fault area to be detected, such as dust, scratch, or stain, etc. The image can be an original image directly acquired from a device, or an image after preliminary processing, etc.

[0062] Step S202, affine transformation is performed on the to-be-detected image to obtain an intermediate image.

[0063] The affine transformation can include translation, rotation, etc. Specifically, each pixel point of the to-be-detected image can be translated or linearly displaced, etc.

[0064] In an exemplary embodiment, the to-be-detected image can be subjected to affine transformation by the following formula:

[0065]

[0066] In the formula, x and y can represent the original coordinates of the pixel points in the image to be detected, a11, a12, a21, a22 can represent the parameters of the affine transformation matrix, which are used to control rotation, scaling or shearing, etc., and a13 and a23 represent the translation amount. Through the above transformation, an intermediate image can be generated. In actual use, homogeneous coordinates and matrix multiplication can be used for the affine transformation. Specifically, on the basis of the original coordinates, a coordinate with a third value of 1 can be mapped, and the affine transformation can be performed by using the following formula:

[0067]

[0068]

[0069] Wherein A can represent an affine transformation matrix.

[0070] In an exemplary embodiment, the affine transformation of the image to be detected can include transforming all regions of the image to be detected, which can specifically include the fault region of the image to be detected. Therefore, through the affine transformation, the fault region of the image to be detected is not the same as the fault region of the intermediate image, thereby achieving preliminary separation of the fault region in the image to be detected, etc.

[0071] Step S204: comparing the pixel values of the corresponding pixels between the image to be detected and the intermediate image by using a preset screening strategy, screening the pixel values meeting the preset requirements from the corresponding pixels, and obtaining a reference image; wherein the screening strategy is determined based on the pixel characteristics corresponding to the fault type to be detected.

[0072] The screening strategy can be set according to the specific fault type, etc. For example, for the detection of lens dust, the screening can be based on the pixel characteristics of the dust particles presented in the image. These characteristics can include the brightness, contrast or pixel distribution characteristics in the local region of the pixel value, etc. By analyzing the differences between the corresponding pixels of the image to be detected and the intermediate image, and combining the preset threshold or rules, the required part can be screened from these pixels, thereby generating the reference image.

[0073] In an example embodiment, the determination of the screening strategy can include determination of pixel features corresponding to the fault type, such as detection of lens dust. The pixel value of the dust in the image is close to 0, so the two images can be compared in terms of pixel value, and the pixel value of the image with a larger pixel value is retained to generate a reference image. It can be understood that in the process of affine transformation, the fault area is also subjected to affine transformation, so the fault area corresponding to the intermediate image and the image to be detected is not the same, and therefore the reference image generated after the fusion of the two images is an image in which part of the fault is eliminated.

[0074] In step S206, the pixel value of each pixel of the image to be detected and the reference image is compared to determine the target fault area in the image to be detected.

[0075] In the comparison process, the difference or ratio of each pixel in the image to be detected and the reference image can be calculated, and it can be determined according to a preset threshold whether the pixel belongs to the fault area. If the difference or ratio does not meet the set threshold, the pixel is marked as part of the target fault area. In addition, a multi-scale analysis method can be combined to perform layered processing on the image to be detected, and the above comparison step is repeated at different resolutions to further confirm the range and characteristics of the target fault area.

[0076] In an example embodiment, the image to be detected and the reference image can be divided to obtain ratio data, and the ratio data can be thresholded to determine the target fault area. For example, dust is a dark spot in the image, and the value of the ratio data is less than 1, so different thresholds can be set to determine the area where the dust is located.

[0077] In the above image detection method, the image to be detected is subjected to affine transformation to generate an intermediate image, a screening strategy is designed according to pixel features corresponding to the fault type, pixels that meet the conditions are selected from the corresponding positions of the two images to form a reference image, and the fault area is located by comparing the pixels of the original image and the reference image. The introduction of affine transformation can to some extent unify the angle, scale or position difference of the image, and enhance the robustness of the algorithm to images under different shooting conditions. Designing a pixel screening strategy for a specific fault type can effectively extract the pixel features of normal or typical faults, and generate a reference image by comparison, thereby filtering out non-critical factors such as changes in illumination and background interference, and reducing the false detection rate. Comparing the original image with the generated reference image pixel by pixel directly highlights the abnormal area, making the fault location more accurate and intuitive, and reducing the subjectivity and omission of manual interpretation. This method combines structured image processing and targeted screening to improve the accuracy of fault identification.

[0078] In one embodiment, the comparison of the pixel values of each pixel between the to-be-detected image and the reference image to determine the target fault region in the to-be-detected image comprises:

[0079] The comparison of the pixel values of each pixel between the to-be-detected image and the reference image to determine the first candidate fault region in the to-be-detected image.

[0080] The determination of the first candidate fault region can be based on the saliency analysis of the pixel value difference. Specifically, by calculating the difference or ratio of each pixel in the to-be-detected image and the reference image, and combining the preset threshold condition, the pixel set that may belong to the fault region is screened out.

[0081] In an exemplary embodiment, the obtained first candidate fault region can be disturbed by factors such as imaging products and ambient light, and therefore the first candidate fault region can be screened. Specifically, the first candidate fault region can be screened by using spot detection. Specifically, for a two-dimensional high-speed function G(x, y, σ):

[0082]

[0083] The corresponding Laplace transform can be:

[0084]

[0085] Specifically, after the normalized Laplace transform, the following can be obtained:

[0086] △ norm 2 = σ 2 △ 2 g= σ 2 ( ∂ 2 g ∂ x 2 + ∂ 2 g ∂ y 2 )=- 1 2 π σ 2 [1- x 2 + y 2 σ 2 ] × exp ( - x 2 + y 2 2 σ 2 ) # ( 6 )

[0087] Thus, a circularly symmetric function is presented on a two-dimensional image, which can be used to detect spots in the image and detect two-dimensional spots of different sizes through different scale values. Specifically, the spot detection schematic diagram can be as shown in Figure 3 The fixed black spot schematic diagram of dust in imaging can be as shown in Figure 4 and so on.

[0088] The reference pixel of the to-be-detected fault is obtained.

[0089] The reference pixel can be set based on the feature pixel value corresponding to the fault type. For example, for lens dust detection, the area of the image affected by dust can be selected as the source of the reference pixel. The acquisition of the reference pixel can also be combined with the pixel features in the historical data or standard sample image to set. For example, by analyzing the pixel distribution law in a large number of known fault images, the representative pixel value range or statistical characteristics are extracted as the basis for the reference pixel.

[0090] According to the reference pixel, a pixel of the image to be detected is matched to determine a second candidate failure region.

[0091] In an exemplary embodiment, the determination of the second candidate region can be based on the similarity analysis between the reference pixel and the pixels in the image to be detected. Specifically, by calculating the similarity between each pixel in the image to be detected and the reference pixel, a set of pixels meeting a preset similarity threshold is screened to form a second candidate failure region, etc.

[0092] In an exemplary embodiment, the reference pixel can include a pixel of an image corresponding to dust, which can be as shown in Figure 5 When matching the pixels to be detected according to the reference pixel (template image), the correlation calculation can be performed from left to right and from top to bottom to obtain a similarity matrix, etc., as shown in Figure 6

[0093] Based on the first candidate failure region and the second candidate failure region, a target failure region in the image to be detected is determined.

[0094] In an exemplary embodiment, the determination of the target failure region can be based on the comprehensive analysis of the results of the first candidate failure region and the second candidate failure region. Specifically, the final target failure region can be further screened and confirmed by the intersection, union or weighted fusion of the two, etc. For example, the part of the first candidate failure region overlapping with the second candidate failure region is regarded as a high-confidence failure region, and the remaining part is subjected to a secondary judgment in combination with an additional verification step. In addition, a multi-scale analysis method can be introduced to refine the candidate failure region at different resolutions to improve the positioning accuracy of the target failure region.

[0095] In another embodiment, a machine learning model can be introduced in the process of determining the target failure region. For example, a trained classifier is used to classify the candidate failure region in the image to be detected to determine whether it belongs to a real failure. The training data of the classifier can come from historical accumulated failure images and their annotation information, and the feature extraction process can combine multi-dimensional information such as pixel value, texture feature and statistical characteristics of local region, etc.

[0096] In this embodiment, by combining the results of the first candidate failure region and the second candidate failure region, the target failure region can be more comprehensively located. This method not only utilizes the saliency analysis of pixel value difference, but also further verifies the accuracy of the failure region by matching the reference pixel. Through the comprehensive analysis of the two, the false judgment caused by a single method can be effectively reduced, and the reliability of the failure detection is improved.

[0097] ​In one embodiment, the matching of the pixel of the image to be detected with the reference pixel to determine the second candidate fault region comprises:

[0098] determining a similarity coefficient between the reference pixel and each local region of the image to be detected.

[0099] In the case where the region similarity coefficient meets a preset condition, the region is determined as the second candidate fault region.

[0100] In one exemplary embodiment, the determination of the similarity coefficient can be implemented based on various algorithms, for example, using cosine similarity, Euclidean distance or structural similarity index (SSIM) and the like to measure the matching degree between the reference pixel and the local region of the image to be detected. Specifically, a quantitative value can be obtained as the similarity coefficient by calculating the difference between the feature vector of the reference pixel and each pixel in the local region. If the coefficient reaches a preset threshold, it is considered that the local region has high similarity with the reference pixel, and it is marked as the second candidate fault region. In addition, a multi-scale analysis method can also be combined to perform multiple similarity calculations on the local region at different resolutions, so as to reduce the error that may exist at a single scale.

[0101] In another embodiment, the robustness of the similarity calculation can be enhanced by introducing local feature descriptors. For example, the key point features of the reference pixel and the local region of the image to be detected are extracted using SIFT (Scale-Invariant Feature Transform) or ORB (Oriented FAST and Rotated BRIEF) algorithm, and the similarity of the two is calculated through a feature matching algorithm.

[0102] In this embodiment, the second candidate fault region is determined by calculating the similarity coefficient, which realizes accurate positioning of the fault region and effectively improves the accuracy and efficiency of the detection. At the same time, this method can adapt to various complex image scenes and has strong robustness.

[0103] In one embodiment, the obtaining of the image to be detected comprises:

[0104] obtaining an initial image.

[0105] performing gray scale processing on the initial image to obtain a gray scale image.

[0106] performing contrast enhancement on the gray scale image to obtain the image to be detected.

[0107] The initial image can be original data directly collected by various imaging devices, such as a component surface image captured by an industrial camera, a scene picture recorded by a monitoring camera, or a test image captured by an optical lens, etc. These images can contain complex background information or be affected by lighting conditions, and therefore need to be preprocessed to improve the accuracy of subsequent detection. Gray processing can be used to convert color images into single-channel gray images, thereby reducing the data dimension and highlighting the key features of the target area. Contrast enhancement can further enhance the visual effect and detail performance of the image by adjusting the distribution of pixel values in the gray image, making the potential fault area more obvious.

[0108] In an example embodiment, contrast enhancement of the gray image can adopt methods such as histogram equalization or adaptive contrast adjustment. Histogram equalization can remap the gray distribution of the image so that the pixel values are more evenly distributed throughout the gray range, thereby improving the overall contrast. Adaptive contrast adjustment can dynamically adjust the contrast according to the pixel distribution characteristics of the local area, which can preserve details while avoiding noise amplification problems caused by excessive enhancement. In addition, gamma correction techniques can be combined to perform nonlinear adjustments on pixel values in different brightness ranges, further optimizing the visual effect and detection performance of the image, etc.

[0109] In an example embodiment, the gray image can be subjected to Gaussian filtering and the like; specifically, a Gaussian sum can be used for convolution to smooth the image, for removing high-frequency noise while preserving edge information of the dust area, etc.

[0110] In this embodiment, by performing gray processing on the initial image, the data dimension can be effectively reduced, the processing efficiency can be improved, and the key information in the image can be preserved. Efficient preprocessing of the image is achieved, providing a reliable foundation for subsequent fault detection.

[0111] In one embodiment, the image to be detected is obtained by a camera; the fault to be detected includes camera lens dust; the method further comprises:

[0112] Obtaining target fault areas corresponding to a plurality of images to be detected.

[0113] Determining the camera lens dust area according to the target fault areas corresponding to the plurality of images to be detected.

[0114] In determining the camera lens dust area, the target fault areas of the plurality of images to be detected can be comprehensively analyzed. Specifically, by superimposing and comparing the position information and features of the target fault area in each image to be detected, a region with high consistency can be extracted as the final dust area.

[0115] In an exemplary embodiment, the dust area can be determined by calculating the intersection or union of multiple target failure areas. For example, for target failure areas in multiple images, their pixel coordinates can be mapped to a unified space, and the frequency of each pixel point being marked as a failure area can be counted. If a pixel point is identified as a target failure area in most images, the point can be considered as part of the dust area. In addition, morphological operations such as dilation and erosion can also be used to optimize the extracted dust area to eliminate isolated noise points or fill small gaps.

[0116] In another embodiment, a clustering algorithm can be used to analyze multiple target failure areas. For example, based on the geometric position, area size or gray distribution characteristics of the target failure area, K-means clustering or DBSCAN method can be used for grouping. In this way, regions with similar characteristics can be further screened out, and abnormal points caused by accidental factors can be excluded. The final clustering center or main cluster can be considered as the dust area on the camera lens, etc.

[0117] In this embodiment, by combining multiple image information, accurate positioning and efficient detection of the camera lens dust area are achieved. This method not only improves the accuracy and reliability of the detection result, but also provides a solid foundation for subsequent automated processing and maintenance work.

[0118] In one embodiment, the camera lens dust area is determined based on the target failure areas corresponding to multiple images to be detected, including:

[0119] The candidate dust area of the camera lens is determined based on the target failure areas corresponding to multiple images to be detected.

[0120] The candidate dust area is subjected to a first detection to determine a first detection result, wherein the first detection is used to determine whether the dust area meets a predetermined area requirement.

[0121] The candidate dust area is subjected to a second detection to determine a second detection result, wherein the second detection is used to determine whether the dust meets a predetermined shape requirement.

[0122] In the case where the first detection result and the second detection result both pass, the candidate dust area is determined as the camera lens dust area.

[0123] The first detection can include calculating the area of the candidate dust region and comparing the area with a preset area threshold. If the area of the candidate dust region is less than or equal to a set minimum threshold, the region is considered not to constitute an effective dust region; if the area is greater than a maximum threshold, it is likely to be other types of interference objects rather than dust, and is also not identified as an effective dust region. Only when the area is within a reasonable range, the first detection is passed. The second detection can include further analyzing the shape characteristics of the candidate dust region. Specifically, the contour information of the region can be extracted, and shape description parameters such as aspect ratio, circularity or eccentricity, etc. can be calculated. These parameters can reflect the geometric characteristics of the dust region. The calculated shape parameters are compared with the preset standard range, and if they are outside the allowed range, the region is determined not to meet the typical shape characteristics of dust and fails the second detection. On the contrary, if the shape parameters meet the requirements, it is considered to pass the second detection. In some embodiments, the candidate dust region can also be supplemented and verified in combination with texture characteristics. For example, using a gray level co-occurrence matrix (GLCM) or other texture analysis methods, the texture information in the region is extracted, and whether it meets the uniformity or randomness characteristics of dust is evaluated. This method can further improve the accuracy of detection and avoid misjudgment due to the sole reliance on area and shape.

[0124] In this embodiment, by introducing a multi-level detection mechanism, the candidate dust region is comprehensively evaluated from multiple dimensions such as area, shape and texture, to ensure that the finally determined camera lens dust region has high accuracy and reliability. This multi-dimensional verification method not only reduces the error risk that may be caused by single condition judgment, but also enhances the adaptability of the algorithm in complex scenes.

[0125] In one embodiment, the image to be detected is obtained by a camera; the fault to be detected includes camera lens dust; and the method further includes:

[0126] Different affine transformations are performed on the image to be detected to obtain a plurality of intermediate images.

[0127] Based on the plurality of intermediate images and the image to be detected, a reference image is determined; and based on the reference image and the image to be detected, a plurality of target fault regions are determined.

[0128] The camera lens dust region is determined according to the plurality of target fault regions.

[0129] The affine transformation can include translation, rotation, scaling, shearing and other transformation operations. By applying different combinations of affine transformation to the original image to be detected, intermediate images with changes in perspective, scale or shape can be generated. For example, a slight translation (e.g., 1-2 pixels) in the horizontal / vertical direction, etc. These transformations can simulate the pose changes or imaging angle differences that can occur when a camera is shooting, thereby enhancing the robustness of subsequent dust area detection. The determination of the reference image can be achieved by comparing and analyzing each intermediate image with the original image to be detected.

[0130] In one embodiment, the comparison of the pixel values of the corresponding pixels between the image to be detected and the intermediate image, the filtering of the pixel values meeting the preset requirements from the corresponding pixels, and the obtaining of the reference image include:

[0131] The pixel value of a pixel position in the image to be detected is compared with the pixel value of the corresponding pixel position in the intermediate image, and the larger pixel value of each pixel position is selected as the target pixel value of the corresponding pixel position.

[0132] Based on the target pixel values, a reference image is determined.

[0133] The pixel value of each pixel position in the image to be detected is compared with the pixel value of the corresponding pixel position in the intermediate image obtained by affine transformation, and the larger pixel value of the two is selected as the target pixel value of the pixel position in the reference image. For example, if the pixel value of a pixel in the image to be detected is 150, and the pixel value of the corresponding position in the intermediate image is 180, then 180 is selected as the target pixel value of the pixel position in the reference image; if the pixel value in the image to be detected is 200 and the pixel value of the corresponding position in the intermediate image is 160, then 200 is selected as the target pixel value. After the comparison and selection of all pixel positions are completed, the target pixel values of the pixel positions are combined to form a new reference image. It can be understood that the gray value of the dust pixel is usually close to 0. After the translation transformation of the image to be detected, the original dust area will be moved to a new position, which originally has a non-dust pixel value in the image to be detected. Therefore, whether it is the original dust position or the new position after translation, in the comparison process of taking the larger value, since the pixel value of the dust is 0, the reference image will finally select the corresponding non-dust pixel value, thereby avoiding the retention of the dust pixel in the reference image, etc.

[0134] In one embodiment, the comparison of the pixel values of the corresponding pixels between the image to be detected and the intermediate image, the filtering of the pixel values meeting the preset requirements from the corresponding pixels, and the obtaining of the reference image include:

[0135] The pixel value of a pixel position in the image to be detected is compared with the pixel value of the corresponding pixel position in the intermediate image, and the larger pixel value of each pixel position is selected as the target pixel value of the corresponding pixel position.

[0132] Based on the target pixel values, a reference image is determined.

[0133] The pixel value of each pixel position in the image to be detected is compared with the pixel value of the corresponding pixel position in the intermediate image obtained by affine transformation, and the larger pixel value of the two is selected as the target pixel value of the pixel position in the reference image. For example, if the pixel value of a pixel in the image to be detected is 150, and the pixel value of the corresponding position in the intermediate image is 180, then 180 is selected as the target pixel value of the pixel position in the reference image; if the pixel value in the image to be detected is 200 and the pixel value of the corresponding position in the intermediate image is 160, then 200 is selected as the target pixel value. After the comparison and selection of all pixel positions are completed, the target pixel values of the pixel positions are combined to form a new reference image. It can be understood that the gray value of the dust pixel is usually close to 0. After the translation transformation of the image to be detected, the original dust area will be moved to a new position, which originally has a non-dust pixel value in the image to be detected. Therefore, whether it is the original dust position or the new position after translation, in the comparison process of taking the larger value, since the pixel value of the dust is 0, the reference image will finally select the corresponding non-dust pixel value, thereby avoiding the retention of the dust pixel in the reference image, etc.

[0134] In one embodiment, the comparison of the pixel values of the corresponding pixels between the image to be detected and the intermediate image, the filtering of the pixel values meeting the preset requirements from the corresponding pixels, and the obtaining of the reference image include:

[0135] The pixel value of a pixel position in the image to be detected is compared with the pixel value of the corresponding pixel position in the intermediate image, and the larger pixel value of each pixel position is selected as the target pixel value of the corresponding pixel position.

[0132] Based on the target pixel values, a reference image is determined.

[0133] The pixel value of each pixel position in the image to be detected is compared with the pixel value of the corresponding pixel position in the intermediate image obtained by affine transformation, and the larger pixel value of the two is selected as the target pixel value of the pixel position in the reference image. For example, if the pixel value of a pixel in the image to be detected is 150, and the pixel value of the corresponding position in the intermediate image is 180, then 180 is selected as the target pixel value of the pixel position in the reference image; if the pixel value in the image to be detected is 200 and the pixel value of the corresponding position in the intermediate image is 160, then 200 is selected as the target pixel value. After the comparison and selection of all pixel positions are completed, the target pixel values of the pixel positions are combined to form a new reference image. It can be understood that the gray value of the dust pixel is usually close to 0. After the translation transformation of the image to be detected, the original dust area will be moved to a new position, which originally has a non-dust pixel value in the image to be detected. Therefore, whether it is the original dust position or the new position after translation, in the comparison process of taking the larger value, since the pixel value of the dust is 0, the reference image will finally select the corresponding non-dust pixel value, thereby avoiding the retention of the dust pixel in the reference image, etc.

[0136] In a case where the fault parameter meets a preset requirement, the pixel region corresponding to the fault parameter is determined as a target fault region.

[0137] The calculation method of the fault parameter can include dividing the pixel value of the to-be-detected image by the pixel value of the reference image, and the difference between the two is measured by the ratio. When the fault parameter is less than a preset threshold, it indicates that the pixel value of the pixel in the to-be-detected image is significantly lower than the pixel value of the corresponding pixel in the reference image, and there is a high possibility that it is a dust fault region. The preset threshold can be adjusted according to the actual application scene and the characteristics of the dust. For example, in the case where the pixel value of the dust is close to 0, if the pixel value of the corresponding pixel in the reference image is the high pixel value of the normal region, the fault parameter will tend to 0, and at this time the threshold can be set to a small value (such as 0.3). When the fault parameter is less than the threshold, it is determined that the pixel belongs to the target fault region. In actual operation, each pixel of the to-be-detected image can be traversed, the fault parameter of each pixel and the corresponding pixel in the reference image is calculated one by one, and all pixels meeting the preset requirement are marked to finally form a complete target fault region. This fault parameter calculation method based on the pixel value ratio can effectively highlight the gray difference between the to-be-detected image and the reference image, thereby accurately positioning the potential dust region.

[0138] In an exemplary embodiment, the image detection method can be as shown in Figure 7 The specific implementation can include the following steps.

[0139] Step S700, set N product output results for shooting.

[0140] Step S702, camera imaging.

[0141] Step S704, image preprocessing; specifically, it can include grayscale processing, Gaussian filter denoising, and contrast enhancement, etc.

[0142] Step S706, the dust detection module 1 performs first dust detection on the preprocessed image and outputs a first candidate dust image; and screens the first candidate dust image.

[0143] Step S708, the dust detection module 2 performs second dust detection on the preprocessed image and outputs a second candidate dust image.

[0144] Step S710, based on the first candidate dust image and the second candidate dust image, the target dust region is determined.

[0145] Step S712, judge whether all products have been detected; if yes, proceed to step S714, if not, return to step S702;

[0146] Step S714. Determine the target dust area; the determination can include area, shape, texture detection, etc.

[0147] Step S716, output the final result.

[0148] It should be understood that although each step in the flowchart involved in each embodiment as described above is displayed in sequence according to the arrow, these steps are not necessarily executed in the order indicated by the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least part of the steps in the flowchart involved in each embodiment as described above can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be alternately executed with at least part of other steps or steps or stages in other steps.

[0149] Based on the same inventive concept, the embodiments of the present application also provide an image detection device for implementing the above-mentioned image detection method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more image detection device embodiments provided below can refer to the limitations of the image detection method in the above text, which will not be repeated here.

[0150] In one embodiment, as shown in Figure 8 An image detection device 800 is provided, comprising: an image acquisition module 801, an image transformation module 803, an image generation module 805 and a fault detection module 807, wherein:

[0151] The image acquisition module is configured to acquire a to-be-detected image.

[0152] The image transformation module is configured to perform affine transformation on the to-be-detected image to obtain an intermediate image.

[0153] The image generation module is configured to compare pixel values of corresponding pixels between the to-be-detected image and the intermediate image respectively using a preset screening strategy, screen pixel values meeting preset requirements from the corresponding pixels, and obtain a reference image; wherein the screening strategy is determined based on pixel features corresponding to a to-be-detected fault type.

[0154] The fault detection module is configured to compare pixel values of each pixel between the to-be-detected image and the reference image, and determine a target fault area in the to-be-detected image.

[0155] In one embodiment, the fault module is further configured to:

[0156] comparing pixel values of each pixel of the to-be-detected image with the reference image, to determine a first candidate fault region in the to-be-detected image;

[0157] obtaining a reference pixel of a to-be-detected fault;

[0158] matching pixels of the to-be-detected image according to the reference pixel, to determine a second candidate fault region;

[0159] determining a target fault region in the to-be-detected image based on the first candidate fault region and the second candidate fault region.

[0160] In an embodiment, the fault module is further configured to:

[0161] determining a similarity coefficient between the reference pixel and each local region of the to-be-detected image;

[0162] in a case where a region similarity coefficient meets a preset condition, determining the region as a second candidate fault region.

[0163] In an embodiment, the image acquisition module comprises:

[0164] an image acquisition sub-module configured to acquire an initial image;

[0165] an image processing sub-module configured to perform grayscale processing on the initial image to obtain a grayscale image;

[0166] the image processing sub-module is further configured to perform contrast enhancement on the grayscale image to obtain a to-be-detected image.

[0167] In an embodiment, the to-be-detected image is obtained by a camera; the to-be-detected fault comprises camera lens dust; and the fault detection module is further configured to:

[0168] obtaining target fault regions corresponding to a plurality of to-be-detected images;

[0169] determining a camera lens dust region according to the target fault regions corresponding to the plurality of to-be-detected images.

[0170] In an embodiment, the fault detection module is further configured to:

[0171] determining a candidate dust region of the camera lens according to the target fault regions corresponding to the plurality of to-be-detected images;

[0172] performing first detection on the candidate dust region to determine a first detection result; wherein the first detection is configured to determine whether a dust region meets a preset area requirement;

[0173] performing a second detection on the candidate dust region to obtain a second detection result, wherein the second detection is used to determine whether the dust meets a preset shape requirement;

[0174] In a case where both the first detection result and the second detection result pass, the candidate dust region is determined as the camera lens dust region.

[0175] In an embodiment, the image to be detected is obtained by a camera; the fault to be detected includes camera lens dust; and the fault detection module is further configured to:

[0176] perform different affine transformations on the image to be detected to obtain a plurality of intermediate images;

[0177] determine reference images based on the plurality of intermediate images and the image to be detected respectively, and determine a plurality of target fault regions based on the reference images and the image to be detected;

[0178] determine the camera lens dust region according to the plurality of target fault regions.

[0179] In an embodiment, the image generation module is further configured to:

[0180] compare pixel values of pixel positions in the image to be detected with pixel values of corresponding pixel positions in the intermediate image, and filter out larger pixel values of each pixel position as target pixel values of the corresponding pixel positions;

[0181] determine reference images based on the target pixel values.

[0182] In an embodiment, the fault detection module is further configured to:

[0183] perform a quotient operation on pixel values of pixel positions in the image to be detected and pixel values of corresponding pixel positions in the intermediate image to obtain a fault parameter;

[0184] In a case where the fault parameter meets a preset requirement, a pixel region corresponding to the fault parameter is determined as a target fault region.

[0185] Each of the above image detection apparatuses can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above modules can be embedded in or independent of a processor in a computer device in a hardware form, or can be stored in a memory in a computer device in a software form, so as to be called and executed by a processor to perform operations corresponding to each of the above modules.

[0186] In an embodiment, a computer device is provided, which can be a terminal, and an internal structure diagram of the computer device can be as shown in Figure 9As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. Among them, the processor, the memory and the input / output interface are connected through the system bus, the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control ability. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with external terminals in wired or wireless mode. Wireless mode can be achieved through WIFI, mobile cellular network, NFC (near field communication) or other technologies. The computer program is executed by the processor to implement an image detection method. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or a key, trackball or touchpad arranged on the shell of the computer device, or an external keyboard, touchpad or mouse, etc.

[0187] Those skilled in the art can understand that, Figure 9 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different component arrangement.

[0188] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties. The collection, use and processing of related data need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0189] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.

[0190] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist, it should be considered as the scope of the present application.

[0191] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent of the present application. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. An image detection method, characterized in that, The method includes: Acquire the image to be detected; An intermediate image is obtained by performing an affine transformation on the image to be detected. Using a preset filtering strategy, the pixel values ​​of corresponding pixels between the image to be detected and the intermediate image are compared, and pixel values ​​that meet preset requirements are filtered from the corresponding pixels to obtain a reference image; wherein, the filtering strategy is determined based on the pixel features corresponding to the fault type to be detected. The pixel values ​​of each pixel in the image to be detected are compared with those in the reference image to determine the target fault area in the image to be detected.

2. The method according to claim 1, characterized in that, The step of comparing the pixel values ​​of each pixel in the image to be detected with the reference image to determine the target fault region in the image to be detected includes: The pixel values ​​of each pixel in the image to be detected are compared with those in the reference image to determine the first candidate fault region in the image to be detected. Obtain the reference pixel for the fault to be detected; Based on the reference pixels, the pixels of the image to be detected are matched to determine the second candidate fault region; Based on the first candidate fault region and the second candidate fault region, the target fault region in the image to be detected is determined.

3. The method according to claim 2, characterized in that, The step of matching pixels of the image to be detected based on the reference pixels to determine the second candidate fault region includes: Determine the similarity coefficient between the reference pixel and each local region of the image to be detected; If the region has a similarity coefficient that meets the preset conditions, the region is identified as the second candidate fault region.

4. The method according to claim 1, characterized in that, The acquisition of the image to be detected includes: Get the initial image; The initial image is processed to obtain a grayscale image; The grayscale image is contrast-enhanced to obtain the image to be detected.

5. The method according to claim 1, characterized in that, The image to be detected includes images captured by a camera; the fault to be detected includes dust on the camera lens; the method further includes: Obtain the target fault regions corresponding to multiple images to be detected; The dust area of ​​the camera lens is determined based on the target fault areas corresponding to multiple images to be detected.

6. The method according to claim 5, characterized in that, The step of determining the dust area of ​​the camera lens based on the target fault areas corresponding to multiple images to be detected includes: Based on the target fault areas corresponding to multiple images to be detected, candidate dust areas of the camera lens are determined; The candidate dust area is subjected to a first detection to determine a first detection result; wherein, the first detection is used to determine whether the dust area meets a preset area requirement; A second detection is performed on the candidate dust area to determine the second detection result; wherein, the second detection is used to determine whether the dust meets the preset shape requirements; If both the first and second detection results are passed, the candidate dust area is determined as the camera lens dust area.

7. The method according to claim 1, characterized in that, The image to be detected includes images captured by a camera; the fault to be detected includes dust on the camera lens; the method further includes: Perform different affine transformations on the image to be detected to obtain multiple intermediate images; A reference image is determined based on multiple intermediate images and the image to be detected; and multiple target fault regions are determined based on the reference image and the image to be detected. Based on the multiple target fault areas, the dust area of ​​the camera lens is determined.

8. The method according to claim 1, characterized in that, The step of comparing the pixel values ​​of corresponding pixels between the image to be detected and the intermediate image, and selecting pixel values ​​that meet preset requirements from the corresponding pixels to obtain a reference image, includes: The pixel value at the pixel position in the image to be detected is compared with the pixel value at the corresponding pixel position in the intermediate image, and the larger pixel value at each pixel position is selected as the target pixel value at the corresponding pixel position. A reference image is determined based on the target pixel values.

9. The method according to claim 1, characterized in that, The step of comparing the pixel values ​​of each pixel in the image to be detected with the reference image to determine the target fault region in the image to be detected includes: The fault parameters are obtained by quotienting the pixel value at the pixel position in the image to be detected with the pixel value at the corresponding pixel position in the intermediate image. If the fault parameters meet the preset requirements, the pixel region corresponding to the fault parameters is determined as the target fault region.

10. An image detection device, characterized in that, The device includes: The image acquisition module is used to acquire the image to be detected; An image transformation module is used to perform an affine transformation on the image to be detected to obtain an intermediate image; The image generation module is used to compare the pixel values ​​of corresponding pixels between the image to be detected and the intermediate image using a preset filtering strategy, and filter the pixel values ​​that meet the preset requirements from the corresponding pixels to obtain a reference image; wherein, the filtering strategy is determined based on the pixel features corresponding to the fault type to be detected. The fault detection module is used to compare the pixel values ​​of each pixel in the image to be detected with the reference image to determine the target fault area in the image to be detected.