Product surface image defect detection method, device, equipment and storage medium
By using preset template images to determine the initial and target detection areas from the image to be detected, and performing differences detection in combination with the intersection of boundary lines, the problem of low accuracy in product defect detection is solved, and efficient pixel-level detection is achieved.
Patent Information
- Application Number
- CN202211289019.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-20
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2042-10-20
AI Technical Summary
The existing machine vision systems have poor adaptability in product defect detection, resulting in lower detection accuracy.
Using the first preset area of the preset template image, the initial detection area is determined from the image to be detected, and the target edge grabbing area is determined in combination with the positional relationship between the preset template image and the preset edge grabbing area, and the border line intersection point is determined as a reference point in the area, and the difference detection is performed based on the relationship between the reference point and the detection area of the preset template image.
Improve the accuracy of defect detection, achieve pixel-level detection effect, and enhance detection efficiency.
Smart Images

Figure CN115829929B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of target detection technology, and in particular to a method, device, equipment and storage medium for defect detection of product surface images. Background Art
[0002] Currently, industrial automation levels are increasing, and consumers are demanding more stringent product quality requirements. Product quality is crucial to manufacturers' survival and future development. Industrial product testing not only ensures product quality but also reveals problems in the production process, making it an essential step in industrial production. For example, with the continuous improvement of integration levels, electronic devices are becoming smaller and more complex. A tiny defect in a product can have a significant impact on product quality. Therefore, accurate detection of product defects, especially small ones, is crucial.
[0003] Currently, the industry's most widely adopted method for product defect detection is machine vision-based. This method can better detect defects that occur during industrial production processes and are difficult to detect manually, thereby improving industrial production efficiency and the degree of automation. However, existing machine vision systems have poor adaptability, including poor adaptability to the different characteristics of different product models, poor adaptability to the external operating environment of the equipment, and poor equipment debugging and operability. This results in low accuracy in product defect detection. Therefore, how to improve the accuracy of product defect detection during machine vision inspection has become an urgent problem to be solved. Summary of the Invention
[0004] Based on this, it is necessary to provide a product surface image defect detection method, device, equipment and storage medium to address the above technical problems, so as to solve the problem of low product defect detection accuracy during machine vision inspection.
[0005] A first aspect of an embodiment of the present application provides a method for detecting defects in a product surface image, characterized in that the method comprises:
[0006] Using a first preset area of a preset template image, determining an initial detection area corresponding to the first preset area from the image to be detected;
[0007] Determining a target edge-grabbing area from the image to be detected based on a positional relationship between the first preset area and the preset edge-grabbing area in the preset template image and in combination with the initial detection area, wherein the preset edge-grabbing area includes at least two non-parallel sub-areas;
[0008] Determine at least two boundary lines in the target edge-grabbing area, and use the intersection of the at least two boundary lines as a target reference point;
[0009] According to the positional relationship between the preset reference point and the preset detection area in the preset template image, combined with the target reference point, the target detection area is determined from the image to be detected, and difference detection is performed on the target detection area to obtain a detection result.
[0010] A second aspect of an embodiment of the present application provides a device for detecting defects in a product surface image, wherein the device comprises:
[0011] An initial detection area determination module, configured to use a first preset area of a preset template image to determine an initial detection area corresponding to the first preset area from the image to be detected;
[0012] a target edge-grabbing area determining module, configured to determine a target edge-grabbing area from the image to be detected based on a positional relationship between the first preset area and the preset edge-grabbing area in the preset template image and in combination with the initial detection area, wherein the preset edge-grabbing area includes at least two non-parallel sub-areas;
[0013] A target reference point acquisition module, configured to determine at least two boundary lines in the target edge grasping area, and use an intersection of the at least two boundary lines as a target reference point;
[0014] The detection module is used to determine the target detection area from the image to be detected based on the positional relationship between the preset reference point and the preset detection area in the preset template image, combined with the target reference point, and perform difference detection on the target detection area to obtain a detection result.
[0015] In a third aspect, an embodiment of the present invention provides a computer device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for detecting defects in product surface images as described in the first aspect is implemented.
[0016] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for defect detection of product surface images as described in the first aspect is implemented.
[0017] Compared with the prior art, the present invention has the following beneficial effects:
[0018] Using a first preset area of a preset template image, an initial detection area corresponding to the first preset area is determined from the image to be detected. Based on the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image, combined with the initial detection area, a target edge-grabbing area is determined from the image to be detected. The preset edge-grabbing area includes at least two non-parallel sub-areas. At least two boundary lines are determined in the target edge-grabbing area. The intersection of the at least two boundary lines is used as a target reference point. Based on the positional relationship between the preset reference point and the preset detection area in the preset template image, combined with the target reference point, a target detection area is determined from the image to be detected. Difference detection is performed on the target detection area to obtain a detection result. In the present invention, using the first preset area of the preset template image, an initial detection area corresponding to the first preset area is determined from the image to be detected, and the target edge-grabbing area is determined based on the initial detection area. The detection area boundary line can be quickly detected from the target edge-grabbing area, and the target reference point is determined. The target detection area of the image to be detected is calculated. The target detection area is determined based on the target reference point, thereby improving the detection efficiency of the target detection area. Pixel-by-pixel detection is performed in the target detection area, so that the accuracy of defect detection can reach the pixel level, thereby improving the defect detection result. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0020] Figure 1 This is a schematic diagram of an application environment of a product surface image defect detection method provided by an embodiment of the present invention;
[0021] Figure 2 This is a flow chart of a method for detecting defects in a product surface image provided by one embodiment of the present invention;
[0022] Figure 3 1 is a schematic structural diagram of a device for detecting defects in a product surface image provided by an embodiment of the present invention;
[0023] Figure 4 It is a structural diagram of a computer device provided by one embodiment of the present invention. DETAILED DESCRIPTION
[0024] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0025] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0026] It will also be understood that the term "and / or" used in the present description and appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0027] As used in the present specification and the appended claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" may be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0028] In addition, in the description of the present specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0029] References to "one embodiment" or "some embodiments" in the present specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present invention. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in yet other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0030] It should be understood that the order of execution of the steps in the following embodiments does not necessarily mean the order in which they are executed. The order in which each process is executed should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0031] In order to illustrate the technical solution of the present invention, specific embodiments are provided below.
[0032] An embodiment of the present invention provides a method for detecting defects in a product surface image, which can be applied in the following situations: Figure 1 In an application environment, a client communicates with a server. The client includes, but is not limited to, a palmtop computer, a desktop computer, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook computer, a personal digital assistant (PDA), and other computer devices. The server can be implemented as a standalone server or a server cluster consisting of multiple servers.
[0033] See also Figure 2 , is a flow chart of a method for detecting defects in a product surface image provided by an embodiment of the present invention. The above-mentioned method for detecting defects in a product surface image can be applied to Figure 1 The server in the above mentioned server connects to the corresponding client, such as Figure 2 As shown, the defect detection method may include the following steps.
[0034] This embodiment is applied to perform defect detection on images corresponding to industrial products.
[0035] S201: Using a first preset area of a preset template image, determining an initial detection area corresponding to the first preset area from an image to be detected.
[0036] In step S201, the first preset area of the preset template image is a pre-set area containing obvious corner points and edge information, and an initial detection area corresponding to the first preset area is determined from the image to be detected, wherein the initial detection area is an area with the same content as the first preset area.
[0037] In this embodiment, an image of the object to be detected is collected by an industrial camera. When the industrial camera is used for collection, if the object to be detected is large, the image obtained by the industrial camera cannot completely contain the object to be detected. In this embodiment, images of the object to be detected are taken at different angles, and each vertex in the object to be detected is used as a distinguishing feature. Four images of the object to be detected are taken, namely, the upper left, upper right, lower right, and lower left of the object to be detected. There may be a certain amount of edge overlap in the four images to ensure that the entire product can be captured. In order to include the information of the entire object to be detected in the four positive images, a part of the overlapping area is reserved between any two images. The images can be divided into different types according to the position information of the vertices in each image, wherein the vertex position information corresponds to the position of the image to be detected in the object to be detected. For example, when the vertex position of the upper left corner of the object to be detected is captured, the image to be detected obtained is an image with the features of the upper left corner of the object to be detected.
[0038] When an image of the object to be detected is captured, the corresponding preset template image is first obtained. If four images of the object to be detected are taken, four corresponding preset template images need to be obtained. After obtaining the preset template images, a template area is selected from the preset template images as the first preset area. When selecting the template area, an area containing corner point and edge information is selected so that the edge capture area can be selected later and the boundary line of the edge capture can be detected.
[0039] Optionally, using a first preset area of a preset template image, determining an initial detection area corresponding to the first preset area from the image to be detected includes:
[0040] Determining a first preset area of the preset template image according to an area selected from the preset template image;
[0041] The first preset area is matched with the image to be detected, and an initial detection area corresponding to the first preset area is determined from the image to be detected.
[0042] In this embodiment, a template area is selected from a preset template image as the first preset area. The number of preset template images is equal to the number of images of the entire object to be detected. The first preset area is matched with the image to be detected, and an initial detection area corresponding to the first preset area is determined from the image to be detected. When matching the first preset area with the image to be detected, a pixel-by-pixel matching process is performed, and the area with an average error value less than a preset threshold is determined as the initial detection area.
[0043] For example, the image to be detected is first grayscaled to obtain the pixel value of each pixel in the image to be detected, and then the size of the first preset area is obtained. Starting from the upper left corner of the image to be detected, a second area equal to the size of the first preset area is extracted, and the difference in pixel values between the first preset area and each corresponding pixel position in the second area is calculated. According to the difference, the average value of the pixel difference between the first preset area and the second area is calculated. When the average value of the pixel difference between the first preset area and the second area is less than a preset threshold, the second area is used as a candidate area, and the variance of the pixel value of the pixels in the candidate area and the pixels in the first preset area is calculated. The candidate area with the smallest variance value is selected as the initial detection area of the image to be detected.
[0044] S202: Determine a target edge-grabbing area from the image to be detected based on a positional relationship between a first preset area and a preset edge-grabbing area in the preset template image and in combination with the initial detection area.
[0045] In step S202, the preset edge-grabbing area is an area containing a boundary line selected in the preset template image. The preset edge-grabbing area includes at least two non-parallel sub-areas. The preset edge-grabbing area is used to obtain the boundary line of the detection area and reduce the detection area. According to the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image, combined with the initial detection area, the target edge-grabbing area is determined from the image to be detected. The target edge-grabbing area is the corresponding edge-grabbing area in the image to be detected. The number of target edge-grabbing areas is equal to the number of preset edge-grabbing areas, and there are at least two non-parallel sub-areas.
[0046] In this embodiment, a preset edge-grabbing area is set in a preset template image, and two non-parallel sub-areas are set. When setting the preset edge-grabbing area, two non-parallel sub-areas are selected so that the boundary lines detected in the two sub-areas intersect to obtain corresponding intersection points. When setting the preset edge-grabbing area, it is also necessary to set it in a place containing a straight line. According to the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image, combined with the initial detection area, the target edge-grabbing area is determined from the image to be detected, wherein the positional relationship between the first preset area and the preset edge-grabbing area corresponds to the positional relationship between the initial detection area and the target edge-grabbing area, so the target edge-grabbing area can be determined from the image to be detected in combination with the initial detection area.
[0047] It should be noted that when a preset edge-grabbing area is set in a preset template image, the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image will be automatically obtained. For example, when a preset edge-grabbing area is set in a preset template image, the position difference between the center point coordinates in the first preset area and the diagonal points in the preset edge-grabbing area can be obtained, so that the position of the diagonal points in the target edge-grabbing area with the same position difference as the initial detection area can be calculated based on the position difference between the center point coordinates in the first preset area and the diagonal points in the preset edge-grabbing area, combined with the initial detection area.
[0048] Optionally, determining the target edge-grabbing area from the image to be detected based on the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image and in combination with the initial detection area includes:
[0049] Obtaining a positional relationship between a first preset region and each subregion in a preset template image;
[0050] According to the positional relationship between the first preset area and each sub-area, combined with the initial detection area, the target sub-area corresponding to each sub-area is determined from the image to be detected, and all the target sub-areas constitute the target edge grasping area.
[0051] In this embodiment, the number of sub-areas corresponding to the preset edge-grabbing area in the preset template image is obtained, and the positional relationship between each sub-area and the first preset area is obtained. After obtaining the positional relationship between each sub-area and the first preset area, combined with the initial detection area, the target sub-area corresponding to each sub-area is determined from the image to be detected, and all target sub-areas constitute the target edge-grabbing area.
[0052] S203: Determine at least two boundary lines in the target edge-grabbing area, and use the intersection of the at least two boundary lines as a target reference point.
[0053] In step S203, at least two boundary lines are determined in the target edge-grabbing area. The target edge-grabbing area is composed of multiple sub-areas. At least two boundary lines are determined from the multiple sub-areas. The intersection of the at least two boundary lines is used as a target reference point. The target reference point is used to represent the position information when the boundary lines intersect.
[0054] In this embodiment, a preset algorithm is used to obtain the boundary line of each target edge-grabbing area. Due to the complexity of the surface of the object to be detected, multiple straight lines may exist. Corresponding boundary lines are determined within the target edge-grabbing area. It should be noted that when multiple straight lines are detected within each target sub-area, one of the multiple straight lines is selected as the boundary line. This selection can be made based on the length of each straight line, with the longest straight line within the target sub-area being selected as the boundary line. It should be noted that the boundary lines selected within different target sub-areas are non-parallel, so that the different boundary lines intersect at a point, with the intersection of at least two boundary lines serving as the target reference point.
[0055] Optionally, determining at least two boundary lines in the target edge-grabbing area and using the intersection of the at least two boundary lines as the target reference point includes:
[0056] By using a preset detection algorithm, a corresponding boundary line is detected in each target sub-region in the target edge grasping region to obtain a sub-boundary line of each target sub-region;
[0057] Get the intersection point of each sub-boundary line and use the intersection point as the target reference point.
[0058] In this embodiment, the LSD line detection method is used for detection. First, the gradient size and direction of each pixel in the image are calculated. Then, the adjacent points with a gradient direction change less than a set threshold are regarded as a connected domain. Then, according to the rectangularity of each domain, it is determined whether it needs to be disconnected according to the set rules to form multiple domains with larger rectangularity. Finally, all the generated domains are screened, and the domains that meet the first set condition are retained to obtain the final line detection result. The line detection result is the detection result of the boundary line.
[0059] After detecting the sub-boundary line of each corresponding target sub-area through the LSD straight line detection method, it is necessary to determine whether the detected sub-boundary line is equal to the sub-boundary line pre-detected in the preset edge-grabbing area, so as to prevent the obtained target reference point from intersecting with the preset reference point in the preset template image, which is not the same boundary line.
[0060] S204: According to the positional relationship between the preset reference point and the preset detection area in the preset template image and in combination with the target reference point, a target detection area is determined from the image to be detected, and a difference detection is performed on the target detection area to obtain a detection result.
[0061] In step S204, the preset reference point is the intersection of the boundary lines in the preset edge-grabbing area in the preset template image, the preset detection area is the necessary area for difference detection, and the target detection area is the area to be detected in the image to be detected. Difference detection is performed on the target detection area to obtain the detection result.
[0062] In this embodiment, first, a preset reference point and a preset detection area are determined in a preset template image. The LSD line detection method is used to detect the points. The gradient magnitude and direction of each pixel in the image are calculated. Adjacent points with gradient direction changes less than a set threshold are then considered a connected domain. Based on the rectangularity of each domain, it is determined whether it is necessary to disconnect it according to the set rules to form multiple domains with larger rectangularities. Finally, all generated domains are screened, and those that meet the second set condition are retained to obtain the final line detection result, which is the detection result of the boundary line. The domains for the first set condition and the second set condition are equal. All preset detection areas are necessary detection areas, and multiple non-essential detection areas can also be set simultaneously.
[0063] According to the positional relationship between the preset reference point and the preset detection area, the positional relationship between the preset reference point and the preset detection area is brought into the process of determining the target detection area to obtain the corresponding target detection area. Difference detection is performed in the wood slope monitoring area to obtain the detection result.
[0064] Optionally, determining the target detection area from the image to be detected based on the positional relationship between a preset reference point and a preset detection area in a preset template image in combination with the target reference point includes:
[0065] Obtaining the positional relationship between each corner point in the preset detection area and the preset reference point;
[0066] According to the positional relationship between each corner point in the preset detection area and the preset reference point, in combination with the target reference point, the target corner point corresponding to each corner point in the preset detection area is determined from the image to be detected;
[0067] Based on the target corner points, the target detection area is determined.
[0068] In this embodiment, the preset detection area is a quadrilateral detection area, and the positional relationship between each corner point in the preset detection area and the preset reference point is obtained, that is, the positional relationship between the four corner points in the preset detection area and the preset reference point is obtained. According to the positional relationship between each corner point in the preset detection area and the preset reference point, combined with the target reference point, the target corner point corresponding to each corner point in the preset detection area is determined from the image to be detected, and the target detection area is determined based on the target corner point.
[0069] Optionally, performing difference detection on the target detection area to obtain a detection result includes:
[0070] Divide the target detection area into N sub-areas, where N is an integer greater than 1;
[0071] Difference detection is performed in each of the N sub-regions to obtain detection results.
[0072] In this embodiment, when performing difference detection, in order to improve detection accuracy and detection efficiency, the target detection area is divided into multiple sub-areas, and difference detection is performed in each sub-area. Positions without sub-areas do not need to be detected. The multiple divided sub-areas reduce the total detection area and can improve detection efficiency. Pixel-by-pixel detection is performed in each sub-area, and the difference in pixel value between each pixel and the adjacent pixels is detected. When the difference in pixel value is greater than a preset difference threshold, the pixel is considered to be a difference pixel different from the remaining pixels. Pixel-by-pixel detection is performed in each sub-area, and pixel-level detection improves detection accuracy.
[0073] Optionally, performing difference detection in each of the N sub-regions to obtain detection results includes:
[0074] In each sub-region, each pixel is detected in turn, and the difference area is determined according to the pixel value of each pixel;
[0075] The size of the difference area and the coordinates of the center point of the difference area are obtained to obtain the detection result.
[0076] In this embodiment, each pixel in each sub-region is sequentially tested. Based on the pixel value of each pixel, a different region is determined. The size and center coordinates of the different region are then determined to obtain a detection result. When a different region is detected, it can be large or small. To determine the location of the difference in the image to be tested, the pixel position and center coordinates of each different region are determined to obtain a detection result.
[0077] Using a first preset area of a preset template image, an initial detection area corresponding to the first preset area is determined from the image to be detected. Based on the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image, combined with the initial detection area, a target edge-grabbing area is determined from the image to be detected. The preset edge-grabbing area includes at least two non-parallel sub-areas. At least two boundary lines are determined in the target edge-grabbing area. The intersection of the at least two boundary lines is used as a target reference point. Based on the positional relationship between the preset reference point and the preset detection area in the preset template image, combined with the target reference point, a target detection area is determined from the image to be detected. Difference detection is performed on the target detection area to obtain a detection result. In the present invention, using the first preset area of the preset template image, an initial detection area corresponding to the first preset area is determined from the image to be detected, and the target edge-grabbing area is determined based on the initial detection area. The detection area boundary line can be quickly detected from the target edge-grabbing area, and the target reference point is determined. The target detection area of the image to be detected is calculated. The target detection area is determined based on the target reference point, thereby improving the detection efficiency of the target detection area. Pixel-by-pixel detection is performed in the target detection area, so that the accuracy of defect detection can reach the pixel level, thereby improving the defect detection result.
[0078] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of a product surface image defect detection device provided by an embodiment of the present invention. In this embodiment, the terminal includes various units for executing Figure 2 Each step in the corresponding embodiment. Please refer to Figure 2 as well as Figure 2 For the convenience of explanation, only the parts related to this embodiment are shown. Figure 3 The product surface image defect detection device 30 includes: an initial detection area determination module 31, a target edge grasping area determination module 32, a target reference point acquisition module 33, and a detection module 34.
[0079] The initial detection area determination module 31 is configured to use a first preset area of a preset template image to determine an initial detection area corresponding to the first preset area from the image to be detected.
[0080] The target edge-grabbing area determining module 32 is configured to determine the target edge-grabbing area from the image to be detected based on the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image and the initial detection area. The preset edge-grabbing area includes at least two non-parallel sub-areas.
[0081] The target reference point acquisition module 33 is configured to determine at least two boundary lines in the target edge grasping area and use the intersection of the at least two boundary lines as the target reference point.
[0082] The detection module 34 is used to determine the target detection area from the image to be detected based on the positional relationship between the preset reference point and the preset detection area in the preset template image and the target reference point, perform difference detection on the target detection area, and obtain a detection result.
[0083] Optionally, the initial detection area determination module 31 includes:
[0084] The first preset area acquisition unit is configured to determine a first preset area of the preset template image according to an area selected from the preset template image.
[0085] The matching unit is used to match the first preset area with the image to be detected, and determine an initial detection area corresponding to the first preset area from the image to be detected.
[0086] Optionally, the target edge-grabbing area determination module 32 includes:
[0087] The acquiring unit is configured to acquire a positional relationship between the first preset region and each sub-region in the preset template image.
[0088] The target sub-region determining unit is used to determine the target sub-region corresponding to each sub-region from the image to be detected based on the positional relationship between the first preset region and each sub-region and the initial detection region. All target sub-regions constitute the target edge grasping region.
[0089] Optionally, the target reference point acquisition module 33 includes:
[0090] The boundary line determination unit is used to detect a corresponding boundary line in each target sub-region in the target edge grasping region by using a preset detection algorithm to obtain a sub-boundary line of each target sub-region.
[0091] The sub-boundary line intersection determination unit is used to obtain the intersection point of each sub-boundary line and use the intersection point as a target reference point.
[0092] Optionally, the detection module 34 includes:
[0093] The positional relationship determination unit between each corner point and the preset reference point is used to obtain the positional relationship between each corner point and the preset reference point in the preset detection area.
[0094] The target corner point determination unit is used to determine the target corner point corresponding to each corner point in the preset detection area from the image to be detected based on the positional relationship between each corner point in the preset detection area and the preset reference point, combined with the target reference point.
[0095] The target detection area determination unit is used to determine the target detection area based on the target corner points.
[0096] Optionally, the target detection area determination unit includes:
[0097] A sub-division unit, used to divide the target detection area into N sub-areas, where N is an integer greater than 1;
[0098] The sub-region detection sub-unit is used to perform difference detection in each of the N sub-regions to obtain detection results.
[0099] Optionally, the sub-region detection subunit includes:
[0100] The difference region determination subunit is used to detect each pixel in each subregion in turn and determine the difference region according to the pixel value of each pixel.
[0101] The detection result determination subunit is used to obtain the size of the difference area and the coordinates of the center point of the difference area to obtain the detection result.
[0102] It should be noted that the information interaction, execution process and other contents between the above-mentioned units are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0103] Figure 4 This is a schematic diagram of the structure of a computer device provided by an embodiment of the present invention. Figure 4 As shown, the computer device of this embodiment includes: at least one processor ( Figure 4 Only one is shown), a memory, and a computer program stored in the memory and executable on at least one processor, wherein when the processor executes the computer program, the steps in any of the above-mentioned embodiments of defect detection of product surface images are implemented.
[0104] The computer device may include, but is not limited to, a processor and a memory. It will be understood by those skilled in the art that Figure 4 The above is merely an example of a computer device and does not constitute a limitation on the computer device. The computer device may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include a network interface, a display screen, and an input device.
[0105] The processor may be a CPU, or other general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. A general-purpose processor may be a microprocessor, or any conventional processor.
[0106] The memory includes a readable storage medium, an internal memory, etc., wherein the internal memory can be the memory of a computer device, and the internal memory provides an environment for the operation of the operating system and computer-readable instructions in the readable storage medium. The readable storage medium can be the hard disk of the computer device, and in other embodiments, it can also be an external storage device of the computer device, for example, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device. Furthermore, the memory can also include both the internal storage unit of the computer device and the external storage device. The memory is used to store the operating system, application programs, boot loaders (BootLoader), data, and other programs, such as the program code of the computer program. The memory can also be used to temporarily store data that has been output or is about to be output.
[0107] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other and are not used to limit the scope of protection of the present invention. The specific working process of the units and modules in the above-mentioned device can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, it can implement the steps of the above-mentioned method embodiment. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include at least: any entity or device capable of carrying computer program code, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0108] The present invention may implement all or part of the processes in the above-mentioned method embodiments, and may also be completed through a computer program product. When the computer program product runs on a computer device, the computer device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0109] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0110] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0111] In the embodiments provided by the present invention, it should be understood that the disclosed apparatus / computer equipment and methods can be implemented in other ways. For example, the apparatus / computer equipment embodiments described above are merely illustrative. For example, the division of modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0112] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0113] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. A method for detecting defects in product surface images, characterized in that: The defect detection method comprises: Using a first preset area of a preset template image, determining an initial detection area corresponding to the first preset area from the image to be detected; Determining a target edge-grabbing area from the image to be detected based on a positional relationship between the first preset area and the preset edge-grabbing area in the preset template image and in combination with the initial detection area, wherein the preset edge-grabbing area includes at least two non-parallel sub-areas; Determine at least two boundary lines in the target edge-grabbing area, and use the intersection of the at least two boundary lines as a target reference point; According to the positional relationship between the preset reference point and the preset detection area in the preset template image, combined with the target reference point, the target detection area is determined from the image to be detected, and difference detection is performed on the target detection area to obtain a detection result.
2. The defect detection method according to claim 1, wherein: The step of using the first preset area of the preset template image to determine an initial detection area corresponding to the first preset area from the image to be detected includes: Determining a first preset area of the preset template image according to an area selected from the preset template image; The first preset area is matched with the image to be detected, and an initial detection area corresponding to the first preset area is determined from the image to be detected.
3. The defect detection method according to claim 1, wherein: The determining of the target edge-grabbing area from the image to be detected based on the positional relationship between the first preset area and the preset edge-grabbing area in the preset template image and in combination with the initial detection area includes: Acquire a positional relationship between the first preset area and each sub-area in the preset template image; According to the positional relationship between the first preset area and each sub-area, combined with the initial detection area, a target sub-area corresponding to each sub-area is determined from the image to be detected, and all target sub-areas constitute a target edge-grabbing area.
4. The defect detection method according to claim 1, wherein: Determining at least two boundary lines in the target edge-grabbing area and using the intersection of the at least two boundary lines as the target reference point includes: By using a preset detection algorithm, a corresponding boundary line is detected in each target sub-region in the target edge grasping region to obtain a sub-boundary line of each target sub-region; Obtain the intersection point of each sub-boundary line and use the intersection point as the target reference point.
5. The defect detection method according to claim 1, wherein: The determining the target detection area from the image to be detected based on the positional relationship between the preset reference point and the preset detection area in the preset template image and in combination with the target reference point includes: Obtaining a positional relationship between each corner point in the preset detection area and the preset reference point; Determining, from the image to be detected, a target corner point corresponding to each corner point in the preset detection area based on a positional relationship between each corner point in the preset detection area and the preset reference point and in combination with the target reference point; The target detection area is determined based on the target corner points.
6. The defect detection method according to claim 1, wherein: The performing difference detection on the target detection area to obtain a detection result includes: Divide the target detection area into N sub-areas, where N is an integer greater than 1; Difference detection is performed in each of the N sub-regions to obtain detection results.
7. The defect detection method according to claim 6, wherein: The performing difference detection in each of the N sub-regions to obtain a detection result includes: In each sub-region, each pixel is detected in turn, and the difference area is determined according to the pixel value of each pixel; The size of the difference area and the coordinates of the center point of the difference area are obtained to obtain a detection result.
8. A device for detecting defects in product surface images, characterized in that: The defect detection device comprises: An initial detection area determination module, configured to use a first preset area of a preset template image to determine an initial detection area corresponding to the first preset area from the image to be detected; a target edge-grabbing area determining module, configured to determine a target edge-grabbing area from the image to be detected based on a positional relationship between the first preset area and the preset edge-grabbing area in the preset template image and in combination with the initial detection area, wherein the preset edge-grabbing area includes at least two non-parallel sub-areas; A target reference point acquisition module, configured to determine at least two boundary lines in the target edge grasping area, and use an intersection of the at least two boundary lines as a target reference point; The detection module is used to determine the target detection area from the image to be detected based on the positional relationship between the preset reference point and the preset detection area in the preset template image, combined with the target reference point, and perform difference detection on the target detection area to obtain a detection result.
9. A computer device, characterized in that: The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the defect detection method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the defect detection method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Boundary defect detection method and device and detection device
CN109325930A
Flange surface defect detection method, system and equipment
CN112508939A