A method and system for detecting the presence or absence of defects in a part under non-uniform lighting conditions

By combining global and local threshold binarization methods with Hu moment contour matching, the accuracy problem of part detection under uneven illumination conditions is solved, and efficient and robust part defect detection is achieved.

CN115587966BActive Publication Date: 2025-12-30SHANDONG ACAD OF SCI INST OF AUTOMATION
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211069617.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-31
Publication Date
2025-12-30
Estimated Expiration
2042-08-31

AI Technical Summary

Technical Problem

Under uneven lighting conditions, existing technologies struggle to accurately detect the presence or absence of defects in parts. Traditional methods involve complex and costly equipment, have low image recognition accuracy, and are highly susceptible to environmental influences, making them unsuitable for parts that rotate.

Method used

Image preprocessing is performed by combining global threshold binarization and local threshold binarization, and contour matching based on Hu moments is combined to eliminate the influence of illumination and improve the matching accuracy.

Benefits of technology

Under uneven lighting conditions, it achieves efficient detection of missing or defective parts, can adapt to changes in part angle, and improves the accuracy and robustness of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115587966B_ABST
    Figure CN115587966B_ABST
Patent Text Reader

Abstract

The present application belongs to the field of machine vision part detection, and provides a part presence / absence detection method and system under non-uniform illumination conditions, comprising: under uniform illumination conditions, pre-determining a template image; pre-processing the template image, and detecting the part contour in the image to obtain a template image contour; collecting a to-be-detected image and pre-processing it; detecting the contour in the to-be-detected image, and performing contour filtering to obtain a to-be-detected image contour; matching the to-be-detected image contour with the template image contour; if the matching is successful, it indicates that there is a part, and if the matching is unsuccessful, it indicates that there is no part. The present application pre-processes the image to eliminate the influence of illumination on the detection effect; in the pre-processing step, the binarization step adopts a method combining global threshold binarization and local threshold binarization, which is fast in processing speed and good in robustness; the Hu-moment-based contour matching mode is adopted to improve the matching accuracy, and meanwhile, to avoid detection errors caused by part angle changes and the like.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of machine vision part detection, and particularly relates to a part presence / absence detection method and system under non-uniform illumination conditions. BACKGROUND

[0002] The statements in this section merely provide background information related to the present application and do not necessarily constitute prior art.

[0003] In the industrial production process, it is often necessary to detect whether a certain part on a conveying belt is normally conveyed. The traditional manual inspection method has been difficult to meet the needs of industrial production. The current existing alternative manual methods usually require sensing devices and other mechanical devices, which are complex and high in cost, and cannot guarantee accuracy.

[0004] With the development of industrial camera device technology, the performance of camera resolution has been greatly improved, and has high application value in industrial production. However, due to the complex on-site industrial environment, the angle of view of the camera and other factors, the obtained target image is not ideal, the collected picture is non-uniformly illuminated, and the target is less different from the background, resulting in low overall gray pixel value of the image and low image contrast, thereby increasing the difficulty of identifying useful information from the image and reducing the identification accuracy. Therefore, the image needs to be further processed to obtain better features and visual effects.

[0005] Image binarization operation is an important step in image preprocessing, and the binarization effect has a direct impact on the subsequent steps. According to the different threshold value calculation methods, there are global threshold binarization method and local threshold binarization method. Among them, the global threshold binarization method generally determines the threshold value according to the image histogram or gray space distribution, and the commonly used algorithms include Otsu algorithm, optimal threshold method, simple statistical method, etc. This kind of method is simple in operation, but low in accuracy. Local threshold binarization includes block local threshold method, adaptive threshold method, etc. The block local threshold method divides the original image into blocks, and uses the method similar to calculating the global threshold to calculate the threshold value of each block sub-image, and then performs binarization processing on the sub-image; the adaptive threshold method calculates the threshold value according to the gray scale features of the neighborhood pixels centered on the current pixel, and then performs binarization on the center pixel. Commonly used local threshold binarization algorithms include Bernsen algorithm, Sauvola algorithm, White algorithm, etc. The local threshold binarization method is more suitable for complex situations, but the operation is complex and time-consuming.

[0006] In the matching of parts, the commonly used matching methods include contour matching, feature point matching, shape matching and template matching, etc. Among them, the threshold setting of the feature point matching method is complex and low in accuracy, and the shape matching and template matching are greatly affected by the environment and cannot be matched after the rotation of the part. SUMMARY

[0007] In order to solve the above problems, the present application provides a method and system for detecting whether a part is missing or not under the condition of uneven illumination. The present application firstly pre-processes the image to eliminate the influence of illumination on the detection effect. The binarization step in the pre-processing step adopts a method combining global threshold binarization and local threshold binarization, which is fast in processing speed and good in robustness. The contour matching method based on Hu moments is adopted to improve the matching accuracy and avoid detection errors caused by changes in the angle of the part.

[0008] According to some embodiments, the first aspect of the present application provides a method for detecting whether a part is missing or not under the condition of uneven illumination, which adopts the following technical solution:

[0009] A method for detecting whether a part is missing or not under the condition of uneven illumination, comprising:

[0010] Under the condition of uniform illumination, a template image is determined in advance;

[0011] The template image is pre-processed, and the contour of the part in the image is detected to obtain a template image contour;

[0012] The image to be detected is collected and pre-processed;

[0013] The contour in the image to be detected is detected, and contour filtering is performed to obtain a contour of the image to be detected;

[0014] The contour of the image to be detected is matched with the template image contour;

[0015] If the matching is successful, it indicates that there is a part, and if the matching is not successful, it indicates that there is no part.

[0016] Further, the pre-processing of the template image is specifically:

[0017] Filtering and denoising are adopted to weaken the noise in the template image;

[0018] Image sharpening is performed on the denoised template image;

[0019] Image segmentation is performed on the template image after image sharpening;

[0020] Image color space conversion is performed on the template image after image segmentation to obtain a gray image of the template image;

[0021] Global adaptive threshold binarization is adopted for binary analysis based on the gray image of the template image;

[0022] The template image after binarization processing is subjected to filtering and denoising again;

[0023] The template image after the second filtering denoising is dilated to obtain a preprocessed template image.

[0024] Further, the to-be-detected image is preprocessed, specifically:

[0025] Filtering denoising is adopted to weaken the noise in the to-be-detected image.

[0026] The to-be-detected image after the denoising is sharpened.

[0027] The to-be-detected image after the image sharpening is segmented.

[0028] The image after the image segmentation is converted in an image color space to obtain a gray image of the to-be-detected image.

[0029] Binary analysis is performed based on the gray image of the to-be-detected image.

[0030] The to-be-detected image after the binary processing is subjected to second filtering denoising.

[0031] The to-be-detected image after the second filtering denoising is dilated to obtain a preprocessed to-be-detected image.

[0032] Further, the binary analysis is performed based on the gray image of the to-be-detected image, specifically:

[0033] (1) The gray image is equally divided into N*N sub-image blocks, and the sub-image block is denoted as block[k] (0≤k

[0034] (2) Each sub-image block is traversed to obtain the mean value and variance of each sub-image block, record the proportion of LowPi in each sub-image block LowPi_Scale[k] and the proportion of HighPi HighPi_Scale[k], and the corresponding binary algorithm is adaptively selected;

[0035] (3) If LowPi_Scale[k]=0 and the mean value of the pixels in the region μ<10, it is considered that all the corresponding sub-block block[k] is background, and all the pixels in the block are set to 255 during binaryzation; otherwise, step (4) is performed.

[0036] (4) If 0LowPi_Scale[k]<Threshold1 (Threshold1 is 2% to 3%) and HighPi_Scale[k]>Threshold2 (Threshold1 is 10% to 20%), it is determined that the sub-image block is a region with large brightness difference, and Bernsen algorithm is used for binaryzation; otherwise, step (5) is performed.

[0037] (5) using Otsu algorithm to binarize the sub-image block, and going to step (6);

[0038] (6) outputting the binarized image.

[0039] Further, the LowPi_Scale[k] and HighPi_Scale[k] calculation formulas are as follows:

[0040]

[0041]

[0042] wherein f(x, y) is the gray value of the pixel point (x, y).

[0043] Further, the template image contour is the outermost contour of the template image, and the to-be-detected image contour is the outermost contour of the to-be-detected image.

[0044] Further, the to-be-detected image contour and the template image contour are matched using a contour matching method based on Hu moments.

[0045] According to some embodiments, the second aspect of the present application provides a part presence / absence detection system under non-uniform illumination conditions, which adopts the following technical solution:

[0046] A part presence / absence detection system under non-uniform illumination conditions, comprising:

[0047] A template image acquisition module configured to determine a template image under uniform illumination conditions;

[0048] A template image contour determination module configured to pre-process the template image and detect a part contour in the image to obtain a template image contour;

[0049] A to-be-detected image acquisition module configured to acquire a to-be-detected image and pre-process it;

[0050] A to-be-detected image contour determination module configured to detect a contour in the to-be-detected image and filter the contour to obtain a to-be-detected image contour;

[0051] A contour matching module configured to match the to-be-detected image contour with the template image contour;

[0052] A result output module configured to indicate the presence of a part if the matching is successful, and indicate the absence of a part if the matching is unsuccessful.

[0053] According to some embodiments, the third aspect of the present application provides a computer readable storage medium.

[0054] A computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of a method for detecting the presence or absence of a defect in a part under non-uniform illumination as claimed in the first aspect above.

[0055] According to some embodiments, a fourth aspect of the present application provides a computer device.

[0056] A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of a method for detecting the presence or absence of a defect in a part under non-uniform illumination as claimed in the first aspect above when executing the program.

[0057] Compared with the prior art, the present application has the following beneficial effects:

[0058] The present application realizes the detection of the presence or absence of a defect in a part under non-uniform illumination. By performing a series of pre-processing on the collected image to eliminate the influence of illumination, and then detecting the contour of the part in the image, the contour matching based on Hu moments is adopted, whether the placement angle of the part in the collected detection image is the same as that in the template image or not, the matching can be realized, and the matching result is output. In the binarization step in the image pre-processing process, the method of combining global threshold binarization and local threshold binarization is adopted, which overcomes the shortcomings of the global threshold binarization method in considering insufficient local information and the slow processing speed of the local threshold binarization method. For non-uniform illumination images, the binarization method proposed in the present application is fast and robust. BRIEF DESCRIPTION OF DRAWINGS

[0059] The drawings constituting a part of the specification of the present application are used to provide a further understanding of the present application, and the illustrative embodiments of the present application and the description thereof are used to explain the present application, and do not constitute an improper limitation on the present application.

[0060] Figure 1 is a flowchart of a method for detecting the presence or absence of a defect in a part under non-uniform illumination according to an embodiment of the present application;

[0061] Figure 2 is a flowchart of an image pre-processing process according to an embodiment of the present application;

[0062] Figure 3 is a flowchart of a binarization process according to an embodiment of the present application;

[0063] Figure 4 is a template image according to an embodiment of the present application;

[0064] Figure 5 is a to-be-detected image according to an embodiment of the present application. DETAILED DESCRIPTION

[0065] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0066] It should be noted that the following detailed description is illustrative and intended to provide further explanation of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.

[0067] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of exemplary embodiments according to the invention. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0068] Where there is no conflict, the embodiments and features in the embodiments of the present invention can be combined with each other.

[0069] Example 1

[0070] like Figure 1 As shown, this embodiment provides a method for detecting defects in parts under uneven lighting conditions. This embodiment uses the application of this method to a server as an example. It is understood that this method can also be applied to terminals, and can also be applied to systems including terminals, servers, and other components, and can be implemented through interaction between the terminal and the server. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network servers, cloud communication, middleware services, domain name services, CDN security services, and big data and artificial intelligence platforms. The terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. The terminal and server can be directly or indirectly connected via wired or wireless communication, which is not limited herein. In this embodiment, the method includes the following steps:

[0071] Under uniform lighting conditions, a template image is predetermined;

[0072] The template image is preprocessed, and the contours of the parts in the image are detected to obtain the template image contours;

[0073] Acquire the image to be detected and perform preprocessing;

[0074] The contours in the image to be detected are detected and the contours are filtered to obtain the contours of the image to be detected.

[0075] Match the contour of the image to be detected with the contour of the template image;

[0076] If a match is successful, it means there is a part; if a match is unsuccessful, it means there is no part.

[0077] Specifically, the preprocessing of the template image includes:

[0078] Filtering and denoising are used to reduce noise in the template image;

[0079] Sharpen the denoised template image;

[0080] Perform image segmentation on the sharpened template image;

[0081] The template image after image segmentation is converted to a grayscale image.

[0082] The grayscale image based on the template image is subjected to binary analysis using a global adaptive threshold binarization method;

[0083] The template image after binarization is filtered and denoised again.

[0084] The template image after further filtering and denoising is then dilated to obtain the preprocessed template image.

[0085] Specifically, the preprocessing of the image to be detected includes:

[0086] Filtering and noise reduction are employed to decrease noise in the image under test.

[0087] Image sharpening is performed on the denoised test image;

[0088] Image segmentation is performed on the sharpened image of the test image;

[0089] The image segmentation is performed on the image color space to obtain the grayscale image of the image under test;

[0090] Binary analysis based on the grayscale image of the image to be tested;

[0091] The image to be tested after binarization is filtered and denoised again.

[0092] The image to be tested after being filtered and denoised again is then dilated to obtain the preprocessed image to be tested.

[0093] Specifically, such as Figure 1 As shown, the specific process of the method described in this embodiment is as follows:

[0094] Step 1: Under uniform lighting conditions, place the part at the inspection location and take a picture with an industrial camera to serve as a template image;

[0095] Step 2: Take a picture of the target location where the part is placed using an industrial camera, as the image to be inspected;

[0096] Step 3: Preprocess the template image and detect the contours of the parts in the image;

[0097] Step 4: Preprocess the image to be detected by detecting contours and performing contour filtering.

[0098] The preprocessing procedures in steps 3 and 4 are as follows: Figure 2 As shown, the purpose is to remove redundant information from the image and retain useful information for subsequent contour detection. Here, we use a test image with uneven illumination as an example to illustrate the preprocessing steps.

[0099] 1. Filtering and noise reduction

[0100] Denoising through filtering can reduce noise and other interference factors in images captured by the camera. Common filtering methods include Gaussian filtering, bilateral filtering, and median filtering. Among them, median filtering does not rely on values ​​within the filter that differ significantly from typical values, thus it is effective in handling speckle noise and salt-and-pepper noise. Furthermore, median filtering better preserves edge information, preventing blurring of image details. In this case, a clear outline of the part is required; after practical comparison, median filtering was chosen.

[0101] 2. Image sharpening

[0102] Due to the special nature of the material of the parts, the difference between the parts and the background in the photos is small. Therefore, image sharpening and segmentation operations can be used to extract important information from the image and make the image boundaries clearer.

[0103] Specifically, image sharpening operations utilize kernels to perform convolution operations on the image. The convolution kernel is a matrix of type CV_32FC1.

[0104]

[0105] 3. Image segmentation

[0106] Image segmentation employs the Mean-Shift method. In the Mean-Shift method, each pixel is represented by a five-dimensional vector (x, y, b, g, r). The first two values ​​are the pixel's coordinates in the image, and the last three are the color components (blue, green, red). Starting from the peak of the color distribution, a sliding window is used to continuously find pixels belonging to the same class and unify their pixel values. The sliding window consists of a radius and a color amplitude. The radius determines the range of the sliding window, i.e., the range of pixel (x, y), and the color amplitude determines the classification standard of pixels within the radius. By continuously sliding the window, image segmentation based on pixel color is achieved. After image segmentation, pixels of the same class have the same pixel value. Here, the sliding window radius is 20, the color amplitude of the sliding window is 20, and the number of scaling layers in the segmentation pyramid is 2, i.e., a 3-layer Gaussian pyramid is constructed. The algorithm iteration stopping condition is set as follows: the maximum number of iterations is 20, and the required precision or parameter change when the iteration algorithm stops is set to 0.01.

[0107] 4. Image color space conversion

[0108] Image color space transformation is the process of converting a color image into a grayscale image, using formula (1) for image grayscale conversion. The purpose of image grayscale conversion is to simplify the matrix and improve the calculation speed.

[0109] L=0.299×R+0.587×G+0.114×B (1)

[0110] 5. Binary Analysis

[0111] For images where the target and background are relatively clear, global thresholding methods such as the Otsu method can achieve good results and are fast and efficient. However, if the background of the image is uneven or the contrast of the target image is low due to differences in lighting, it is difficult to identify useful information in the image. In such cases, local thresholding methods, such as the Bernsen method, are generally used for image binarization.

[0112] To reduce the impact of uneven illumination, a binarization method combining Otsu's global thresholding and Bernsen's local thresholding is used.

[0113] The Bernsen algorithm implementation steps are as follows:

[0114] (1) Take a window of size (2w+1)×(2w+1) centered on pixel M(x,y) in the grayscale image;

[0115] (2) Traverse the pixels in the window and calculate the threshold T(x,y) according to formula (2), where -w≤m≤w, -w≤n≤w, and f(x,y) is the gray value at point (x,y).

[0116] T(x, y) = 0.5 × [max f(x + m, y + n) + min f(x + m, y + n)] (2)

[0117] (3) Use the threshold T(x, y) to binarize the pixel points of the image respectively according to formula (3):

[0118]

[0119] For a grayscale image, its pixel value range is [0, 255], and it is divided into four grayscale intervals: the low grayscale pixel value interval [0, 63), denoted as LowPi; the medium - low grayscale pixel value interval [64, 127); the medium - high grayscale pixel value interval [128, 191); the high grayscale pixel value interval [192, 255], denoted as HighPi. Then binarize the image according to the following steps:

[0120] (1) Divide the grayscale image into N * N sub - image blocks evenly. If N is too small, it will affect the processing time; if N is too large, it will affect the processing accuracy. For an image of 1685 * 1771 pixels, when N takes 3 or 4, the best results can be obtained simultaneously in terms of binarization effect and processing speed.

[0121] (2) Traverse the sub - image block block[k], calculate the mean and variance of each sub - image block, record the proportion LowPi_Scale[k] of LowPi and the proportion HighPi_Scale[k] of HighPi in each sub - image block, and adaptively select the corresponding binarization algorithm. The calculation formulas for LowPi_Scale[k] and HighPi_Scale[k] are shown in formulas (4) and (5), where f(x, y) is the grayscale value of the pixel point (x, y).

[0122]

[0123]

[0124] (3) If LowPi_Scale[k] = 0 and the mean pixel value μ in the region < 10, it is considered that the corresponding sub - block block[k] is all background, and all pixel points in this block are set to 255 during binarization. Otherwise, go to step (4).

[0125] (4) If 0 < LowPi_Scale[k] < Threshold1 (Threshold1 takes 2% - 3%) and HighPi_Scale[k] > Threshold2 (Threshold2 takes 10% - 20%), it is determined that this sub - image block is a region with large brightness difference, and the Bernsen algorithm is used for binarization. Otherwise, go to step (5).

[0126] (5) Binarize the sub-image block using the Otsu algorithm. Proceed to step (6).

[0127] (6) Output the binarized image.

[0128] 6. Filtering and noise reduction

[0129] The image still has relatively little noise after binarization, so median filtering is applied again to eliminate noise interference.

[0130] 7. Image dilation

[0131] After the filtering operation in the previous step, some useful information in the image will be filtered out. In addition, regions that should have been connected in the image will be broken after the filtering operation. The dilation operation can eliminate the above effects. A structuring element is used to control the effect of image dilation. The structuring element is a custom structuring element. The size of the structuring element is selected according to the actual effect. Here, a (10×10) rectangular structuring element is used, and the dilation is 1.

[0132] In steps 3 and 4, the image contour is detected. Here, the outermost contour of the image is detected, and it is not necessary to output the structural relationship of the contour.

[0133] The contour filtering in step 4 is used to filter out contours generated by noise that has not been eliminated, as well as other interfering contours. Specifically, in the contour acquisition step, conditions are set. Here, contours with an area less than 1000 are set as interfering contours and are removed, without proceeding to the subsequent contour matching step.

[0134] The contour matching in step 5 is a contour matching based on Hu moments.

[0135] Moments are operators that describe image features. Since Hu moments are invariant to rotation, translation, and scaling, they are used here to implement contour matching. Hu moments are seven invariant moments calculated from the second and third central moments, and their calculation formula is as follows:

[0136]

[0137] Where, η 02 η 11 and η 20 Let η be the second-order normalized central moment. 03 η 12 η 21 and η 30 It is the third-order normalized central moment.

[0138] A contour matching function based on Hu moments is used to find regions in the image to be detected or contours that match the pixels of the template image or contours. During the extraction of image contours, the Hu moments of the contours are calculated, and for each contour in the image to be detected, the matching coefficient of the template contour is calculated using formula (7).

[0139]

[0140] in, and Let Hu be the moments of contours A and B, respectively. The greater the degree of contour matching, the smaller the matching coefficient I(A,B) becomes and it approaches 0.

[0141] The specific steps for setting the verification conditions in step 6 are as follows:

[0142] In the contour matching process of step 5, the matching coefficient threshold is set to 0.01. When I(A,B)<0.01, it indicates that the contour being compared is successfully matched, and the output is "Part present". If the threshold condition cannot be met for each contour matching, the output is "No part". After the part is successfully matched, the contour of the target part is drawn on the image to be tested.

[0143] Example 2

[0144] This embodiment provides a detection system for whether parts have defects under uneven illumination conditions, including:

[0145] The template image acquisition module is configured to pre-determine the template image under uniform lighting conditions;

[0146] The template image contour determination module is configured to preprocess the template image and detect the contours of parts in the image to obtain the template image contour.

[0147] The image acquisition module is configured to acquire the image to be detected and perform preprocessing.

[0148] The image contour determination module is configured to detect contours in the image to be detected and perform contour filtering to obtain the image contours.

[0149] The contour matching module is configured to match the contour of the image to be detected with the contour of the template image;

[0150] The output module is configured to indicate that a part exists if a match is found, and that no part exists if a match is not found.

[0151] The examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the content disclosed in Embodiment 1 above. It should be noted that the above modules, as part of the system, can be executed in a computer system such as a set of computer-executable instructions.

[0152] The descriptions of each embodiment in the above embodiments have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0153] The proposed system can be implemented in other ways. For example, the system embodiments described above are merely illustrative, and the division of modules described above is only a logical functional division. In actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed.

[0154] Example 3

[0155] This embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method for detecting whether a part has defects under uneven illumination conditions as described in Embodiment 1 above.

[0156] Example 4

[0157] This embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps in the method for detecting whether a part has defects under uneven lighting conditions as described in Embodiment 1 above.

[0158] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.

[0159] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0160] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0161] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0162] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0163] While the specific embodiments of the present invention have been described above in conjunction with the accompanying drawings, this is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art without creative effort based on the technical solutions of the present invention are still within the scope of protection of the present invention.

Claims

1. A method for detecting the presence or absence of a defect in a part under non-uniform lighting conditions, characterized by, Comprising: predetermine the template image under uniform illumination conditions; preprocess the template image, and detect the part contour in the image to obtain a template image contour; collect and preprocess the image to be detected, specifically: adopt filtering denoising to weaken the noise in the image to be detected; perform image sharpening on the denoised image to be detected; perform image segmentation on the image sharpened image to be detected; perform image color space conversion on the image segmented image to be detected to obtain a gray image of the image to be detected; perform binarization processing based on the gray image of the image to be detected, specifically: (1) the gray image of the image to be detected is equally divided into N*N sub-image blocks, and the sub-image blocks are denoted as block [ k ], 0≤ k < N * N ; (2) traverse sub-image blocks block [ k ] to find the mean and variance of each sub-image block, record the proportion of each sub-image block LowPi [ LowPi_Scale ] in the image k [ HighPi ], HighPi_ Scale [ k ], and adaptively select the corresponding binary algorithm LowPi_Scale [ k ], HighPi_ Scale [ k ] The calculation formula is as follows: in, f ( x , y ) represents the pixels of the grayscale image of the image to be detected. x , y The grayscale value of ). (3) If LowPi_Scale [ k ] = 0, and the mean value of the pixels in the region μ < 10, it is considered that all the pixels in the corresponding sub-block block [ k ] are background, and all the pixels in the block are set to 255 in the binaryzation; otherwise, go to step (4); (4) if 0 < I < 2%, LowPi_Scale [ k ] < Threshold1 , Threshold1 take 2%~3%, and HighPi_Scale [ k ] > Threshold2 , Threshold1 take 10%~20%, determine this sub-image block as a large area of brightness difference, and use Bernsen algorithm for binarization; otherwise, go to step (5); (5) perform binarization on the sub-image block using the Otsu algorithm, and go to step (6); (6) output the binarized image; perform re-filtering denoising on the image to be detected after binarization processing; perform image dilation on the image to be detected after re-filtering denoising to obtain the preprocessed image to be detected; detect the contour in the image to be detected and perform contour filtering to obtain an image to be detected contour; match the image to be detected contour with the template image contour; if the matching is successful, it indicates that there is a part, and if the matching is unsuccessful, it indicates that there is no part.

2. The method of claim 1, wherein the method is characterized by: The preprocessing of the template image is specifically: adopt filtering denoising to weaken the noise in the template image; perform image sharpening on the denoised template image; perform image segmentation on the image sharpened template image; perform image color space conversion on the image segmented template image to obtain a gray image of the template image; perform binarization processing based on the gray image of the template image using the global adaptive threshold binarization method; perform re-filtering denoising on the template image after binarization processing; perform image dilation on the template image after re-filtering denoising to obtain the preprocessed template image.

3. The method of claim 1, wherein the method is characterized by: The template image contour is the outermost contour of the template image, and the image to be detected contour is the outermost contour of the image to be detected.

4. The method of claim 1, wherein the method is characterized by: The image to be detected contour and the template image contour are matched using the Hu moment-based contour matching method.

5. A system for detecting the presence or absence of a defect in a part under non-uniform lighting conditions, comprising: a light source; a camera; a light source controller; a camera controller; and a processor. Comprising: a template image collection module configured to predetermine the template image under uniform illumination conditions; a template image contour determination module configured to preprocess the template image, and detect the part contour in the image to obtain a template image contour; a to-be-detected image collection module configured to collect and preprocess the image to be detected, specifically: adopt filtering denoising to weaken the noise in the image to be detected; perform image sharpening on the denoised image to be detected; perform image segmentation on the image sharpened image to be detected; perform image color space conversion on the image segmented image to be detected to obtain a gray image of the image to be detected; perform binarization processing based on the gray image of the image to be detected, specifically: Based on the gray image of the image to be detected, binaryzation is performed, specifically: (1) the gray image of the image to be detected is equally divided into N*N sub-image blocks, and the sub-image blocks are denoted as block [ k ], 0≤ k < N * N ; (2) traverse sub-image blocks block [ k ] to find the mean and variance of each sub-image block, record the proportion of each sub-image block LowPi [ LowPi_Scale ] in the image, k [ HighPi ] the proportion of HighPi_ Scale [ k ], adaptive selection of the corresponding binary algorithm, LowPi_Scale [ k ], HighPi_ Scale [ k ] the calculation formula is as follows: wherein, f ( x , y ) is a gray value of a pixel point ( x , y ) of the gray image of the image to be detected; (3) If LowPi_Scale [ k ] = 0, and the mean value of the pixels in the region μ < 10, it is considered that all the pixels in the corresponding sub-block block [ k ] are background, and all the pixels in the block are set to 255 in the binaryzation; otherwise, go to step (4); (4) if 0 < I < 2%, LowPi_Scale [ k ] < Threshold1 , Threshold1 take 2%~3%, and HighPi_Scale [ k ] > Threshold2 , Threshold1 take 10%~20%, determine that this sub-image block is a large area of brightness difference, and use Bernsen algorithm for binarization; otherwise, go to step (5); (5) The Otsu algorithm is used to perform binaryzation on the sub-image block, and step (6) is performed; (6) The binaryzation image is output; The image to be detected after binaryzation is filtered and denoised again; The image to be detected after filtering and denoising again is dilated to obtain the preprocessed image to be detected; The image to be detected profile determination module is configured to detect the profile in the image to be detected and perform profile filtering to obtain the image to be detected profile; The profile matching module is configured to match the image to be detected profile with the template image profile; The result output module is configured to indicate that there is a part if the matching is successful, and indicate that there is no part if the matching is unsuccessful.

6. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to realize the steps in the part presence / absence detection method under uneven illumination conditions according to any one of claims 1-4.

7. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the program to realize the steps in the part presence / absence detection method under uneven illumination conditions according to any one of claims 1-4.

Citation Information

Patent Citations

  • Vehicle video speed measuring method based on binocular camera

    CN104063882A

  • Component defect detection method and system

    CN106504231A