Method for detecting defects on a product surface and related apparatus
By acquiring product inspection images and using region detection algorithms and image processing techniques, including dilation, binarization, and boundary fitting, the accuracy problem of visual inspection systems in detecting surface defects in products has been solved, achieving high-precision defect recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER
- Filing Date
- 2023-07-07
- Publication Date
- 2026-06-23
Smart Images

Figure CN116894815B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of visual inspection technology, and in particular to a method, apparatus, computer equipment, readable storage medium, and program for detecting defects on the curved surface of a product. Background Technology
[0002] Many manufacturing companies are now using vision inspection systems to inspect product quality. The widespread construction of unmanned workshops relies heavily on vision inspection systems to replace manual quality control. Vision inspection offers the following advantages: Accuracy: Due to the physical limitations of the human eye, machines have a significant advantage in accuracy, ensuring consistent quality. Repeatability: Vision inspection systems can work repeatedly and continuously, while humans require rest. Speed: Vision inspection systems can inspect products much faster, especially when inspecting high-speed moving objects, such as on high-speed production lines, where the system can keep up with the flow. Cost: Because vision inspection systems are faster than humans, one automated machine vision system can perform the tasks of multiple people, leading to lower costs in mass production. Summary of the Invention
[0003] This disclosure provides an apparatus, computer device, readable storage medium, and program for detecting surface defects in products, relating to the field of visual inspection technology. This method can detect surface defects in products.
[0004] This disclosure provides a method for detecting surface defects in a product, comprising: acquiring a first detection image; acquiring a first detection region of the first detection image using a region detection algorithm; performing an image dilation operation on the first detection region to obtain a first dilated detection region; binarizing the first dilated detection region to obtain a first dilated binary detection region; and performing an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region.
[0005] In one embodiment, obtaining a first detection region of the first detection image using a region detection algorithm includes: setting a threshold to obtain a first pixel region of the first detection image; obtaining a first grayscale average value of the first pixel region; obtaining a first binary image based on the first grayscale average value; dividing the first binary image into a first upper binary image and a first lower binary image; and determining the upper and lower boundaries of the product in the first detection image based on the first upper binary image and the first lower binary image to obtain the first detection region.
[0006] In one embodiment, obtaining the first detection region of the first detection image through a region detection algorithm further includes: applying Gaussian filtering to the first binary image, then eroding it, and then applying N dilation operations to the entire image, where N is an integer greater than or equal to 1.
[0007] In one embodiment, determining the upper and lower boundaries of the product in the first detection image based on the first upper binary image and the first lower binary image to obtain the first detection region includes: finding the estimated positions of the product edges in the first upper binary image and the first lower binary image by searching for straight lines; finding non-zero points among the estimated positions of the product edges in the first upper binary image and the first lower binary image to form edge regions of the product in the first upper binary image and the first lower binary image; finding the lower edge of the edge region of the first upper binary image to determine the upper boundary of the product; finding the upper edge of the edge region of the first lower binary image to determine the lower boundary of the product; and obtaining the first detection region based on the upper boundary and the lower boundary of the product.
[0008] In one embodiment, obtaining the first detection region based on the upper boundary and the lower boundary of the product includes: setting M rectangular boxes centered on the edge points of the upper boundary and the lower boundary of the product, where M is an integer greater than or equal to 1; performing adaptive gradient calculation on the M rectangular boxes and superimposing boundary threshold range conditions, and using a quadratic curve to fit and form the true upper boundary and the true lower boundary of the product.
[0009] In one embodiment, the method further includes: performing connected component calculation on the first dilated binary detection region to obtain a background region; and obtaining the average grayscale value of the background region.
[0010] In one embodiment, performing an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region includes: filtering noise in the defect region using the average grayscale value of the background region, and determining the final defect region using area and brightness conditions.
[0011] This disclosure provides a device for detecting surface defects in a product, comprising: an acquisition unit for acquiring a first detection image; a region unit for acquiring a first detection region of the first detection image using a region detection algorithm; a dilation unit for performing an image dilation operation on the first detection region to obtain a first dilated detection region; a binarization unit for binarizing the first dilated detection region to obtain a first dilated binary detection region; and an AND operation unit for performing an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region.
[0012] This disclosure provides a computer device including a processor, a memory, and an input / output interface; the processor is connected to the memory and the input / output interface respectively, wherein the input / output interface is used to receive data and output data, the memory is used to store a computer program, and the processor is used to call the computer program so that the computer device performs the method as described in any of the above embodiments.
[0013] This disclosure provides a computer-readable storage medium storing a computer program adapted to be loaded and executed by a processor, such that a computer device having the processor performs the method as described in any of the above embodiments.
[0014] This disclosure provides a computer program product, including a computer program that, when executed by a processor, implements the method described in any of the above embodiments.
[0015] The product surface defect detection method of this application involves acquiring a first detection image; acquiring a first detection region of the first detection image using a region detection algorithm; performing an image dilation operation on the first detection region to obtain a first dilated detection region; binarizing the first dilated detection region to obtain a first dilated binary detection region; and performing an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region, thereby enabling the detection of product surfaces. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A product inspection image acquisition system according to an embodiment of the present disclosure is shown;
[0018] Figure 2 A schematic diagram of an exemplary system architecture for a product surface defect detection method to which embodiments of the present disclosure can be applied is shown;
[0019] Figure 3 This is a flowchart of a method for detecting surface defects in a product according to an embodiment of this disclosure;
[0020] Figure 4 This is a flowchart of a method for obtaining a first detection region of the first detection image using a region detection algorithm, provided in an embodiment of this disclosure;
[0021] Figure 5 This is a flowchart of a method for determining the upper and lower boundaries of a product in a first detection image based on a first upper binary image and a first lower binary image to obtain the first detection region, provided by an embodiment of this disclosure.
[0022] Figure 6 This is a schematic diagram of the structure of a product surface defect detection device provided in an embodiment of this disclosure;
[0023] Figure 7 This is a schematic diagram of the structure of a computer device for implementing the product surface defect detection method provided in the embodiments of this disclosure. Detailed Implementation
[0024] The technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0025] In this embodiment of the disclosure, a method for detecting surface defects in a product is provided. The method includes: acquiring a first detection image; acquiring a first detection region of the first detection image using a region detection algorithm; performing an image dilation operation on the first detection region to obtain a first dilated detection region; binarizing the first dilated detection region to obtain a first dilated binary detection region; and performing an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region, thereby enabling the detection of surface defects in the product.
[0026] The following is a brief explanation of some of the terms used in this disclosure:
[0027] Grayscale uses black to represent objects; that is, it uses black as a base color and displays images with different saturations of black. Each grayscale object has a brightness value from 0% (white) to 100% (black). Images generated using black-and-white or grayscale scanners are typically displayed in grayscale.
[0028] A binary image is an image in which each pixel has only two possible values or grayscale levels. Binary images are often represented as black and white, B&W, or monochrome images. In a binary image, there are only two grayscale levels; that is, any pixel in the image has a grayscale value of either 0 or 255, representing black and white respectively.
[0029] Line search is mainly used to find lines in an image that have certain features. It uses known feature points to form a set of feature points and then fits them into a line.
[0030] Quadratic curve fitting is a classic nonlinear fitting method, mainly used to fit experimental or theoretical data. There are various methods for quadratic curve fitting, such as least squares method, curve fitting, and line integral.
[0031] Inflation, similar to "domain expansion," expands the white areas in an image, resulting in a larger white area than the original image.
[0032] Erosion, similar to "domain erosion," reduces and refines the white areas in an image, resulting in a smaller white area than the original image.
[0033] The solutions provided in this disclosure involve techniques such as dilation and binary images.
[0034] Figure 1 A product inspection image acquisition system according to an embodiment of the present disclosure is shown.
[0035] refer to Figure 1 The product inspection image acquisition system includes at least a product 100, a first camera 201, a second camera 202, a third camera 203, and a fourth camera 204. The first camera 201, second camera 202, third camera 203, and fourth camera 204 are evenly arranged at 90-degree angles along the side of the product 100 to capture the curved surface of the product 100's side. The product 100 is rotated twice, 30 degrees each time, and three photos are taken to achieve a 360-degree panoramic view of the product 100's side, meeting the design requirements for full surface inspection of the product 100.
[0036] Figure 2 A schematic diagram of an exemplary system architecture 200 for detecting surface defects in products to which embodiments of the present disclosure can be applied is shown.
[0037] like Figure 2 As shown, system architecture 200 may include one or more of terminals 201, 202, and 203, a network 204, and a server 205. Network 204 is the medium used to provide a communication link between terminals 201, 202, and 203 and server 205. Network 204 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.
[0038] It should be understood that Figure 2 The number of terminals, networks, and servers shown is merely illustrative. Depending on implementation needs, there can be any number of terminals, networks, and servers. For example, server 205 could be a server cluster consisting of multiple servers.
[0039] Terminals 201, 202, and 203 interact with server 205 via network 204, and can receive or send messages, etc. Terminals 201, 202, and 203 can be various electronic devices with displays, including but not limited to smartphones, tablets, laptops, and desktop computers, etc.
[0040] Server 205 can be a server that provides various services. For example, after terminal 203 (or terminal 201 or 202) sends a product surface defect detection request to server 205, server 205 can acquire a first detection image; acquire a first detection region of the first detection image through a region detection algorithm; perform an image dilation operation on the first detection region to obtain a first dilated detection region; binarize the first dilated detection region to obtain a first dilated binary detection region; and perform an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region, thereby realizing the detection of the product surface.
[0041] The terminal can be a mobile phone (such as terminal 201), a tablet computer (such as terminal 202), or a desktop computer (such as terminal 201), etc., without limitation. The terminal can display an application, which can be an application for designing dot matrix and floodlight projectors, etc. Figure 2 The terminals mentioned are only a portion of the devices cited in this disclosure; the terminals are not limited to these. Figure 2 The equipment listed in the text.
[0042] Currently, there are two common types of product surface inspection systems: contact inspection and vision inspection. Contact inspection is more expensive; vision inspection algorithms are cheaper, but their accuracy is lower. Most existing vision inspection systems are designed for measuring part dimensions, with fewer solutions for detecting surface defects.
[0043] Figure 3 This is a flowchart illustrating a method for detecting surface defects in a product according to an embodiment of this disclosure. The method provided in this embodiment can be... Figure 2 The methods described in this embodiment are executed by a terminal or server, or by interaction between a terminal and a server. However, this disclosure is not limited thereto; the methods of this disclosure can be executed by any processor with computing power.
[0044] like Figure 3 As shown, the method provided in this disclosure embodiment may include the following steps.
[0045] In step S310, the first detection image is acquired.
[0046] In this step, the terminal or server acquires the first detection image. The first detection image may be... Figure 1 Images taken by any one of the cameras.
[0047] In step S320, the first detection region of the first detection image is obtained by a region detection algorithm.
[0048] In this step, the terminal or server obtains the first detection region of the first detection image through a region detection algorithm.
[0049] In step S330, an image dilation operation is performed on the first detection region to obtain a first dilated detection region.
[0050] In this step, the terminal or server performs an image dilation operation on the first detection area to obtain a first dilated detection area.
[0051] Before this step, multiple images can be used to statistically analyze the local grayscale change rate at the top and bottom edges, fit the pixel values of each column for pixel compensation (the compensation value is set according to historical images), and create a mask (to cover non-edge areas and compensate for edge areas) to make the grayscale at the top and bottom edges more uniform, eliminating the excessive local grayscale change rate caused by uneven lighting; set a threshold, perform edge detection on the image, and use the Canny algorithm to obtain the edge information image.
[0052] In step S340, the first dilated detection region is binarized to obtain the first dilated binary detection region.
[0053] In this step, the terminal or server binarizes the first dilated detection region to obtain the first dilated binary detection region.
[0054] In step S350, the first expanded detection area and the first expanded binary detection area are ANDed to obtain the defect area.
[0055] In this step, the terminal or server performs a bitwise AND operation between the first expanded detection area and the first expanded binary detection area to obtain the defect area.
[0056] Figure 3 The method for detecting defects on the curved surface of a product involves: acquiring a first detection image; obtaining a first detection region of the first detection image using a region detection algorithm; performing an image dilation operation on the first detection region to obtain a first dilated detection region; binarizing the first dilated detection region to obtain a first dilated binary detection region; and performing an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region, thereby enabling the detection of the curved surface of the product.
[0057] In one embodiment, Figure 3The method for detecting surface defects in products further includes: performing connected component calculation on the first dilated binary detection region to obtain a background region; and obtaining the average grayscale value of the background region. Connected component calculation is performed on the dilated binary image (identical parts, such as the sky, ground, and river in the image, are each a connected component), resulting in multiple regions. The largest region is the background region (the largest connected component), with its label set to 0. The remaining connected components are sequentially labeled (e.g., 1, 2, 3, etc.). Grayscale statistics are performed on the background region in the grayscale image, and the average value is calculated.
[0058] In one embodiment, Figure 3 In the method for detecting surface defects in products, performing an AND operation between the first expanded detection area and the first expanded binary detection area to obtain a defect area includes: filtering noise in the defect area using the average grayscale value of the background area, and determining the final defect area using area and brightness conditions.
[0059] Figure 4 This is a flowchart illustrating a method for obtaining a first detection region of a first detection image using a region detection algorithm, as provided in this embodiment of the disclosure. The method provided in this embodiment can be... Figure 2 The methods described in this embodiment are executed by a terminal or server, or by interaction between a terminal and a server. However, this disclosure is not limited thereto; the methods of this disclosure can be executed by any processor with computing power.
[0060] like Figure 4 As shown, the method provided in this disclosure embodiment may include the following steps.
[0061] In step S410, a threshold is set to obtain the first pixel region of the first detected image.
[0062] In this step, the terminal or server sets a threshold to obtain a first pixel region of the first detected image. For example, there are two thresholds, 100 and 200 (between 0 and 255); thus, a pixel region between 100 and 200 is obtained.
[0063] In step S420, the first grayscale average value of the first pixel region is obtained.
[0064] In this step, the terminal or server obtains the first grayscale average value of the first pixel region. For example, it calculates the average value between pixels 100 and 200.
[0065] In step S430, a first binary image is obtained based on the first grayscale average value.
[0066] In this step, the terminal or server obtains a first binary image based on the first grayscale average value.
[0067] For example, the first grayscale average value is 160; values greater than 160 are set to 1; values less than 160 are set to 0.
[0068] In step S440, the first binary image is divided into a first upper binary image and a first lower binary image.
[0069] In this step, the terminal or server divides the first binary image into a first upper binary image and a first lower binary image.
[0070] Before this step, for example, Gaussian filtering can be applied to the first binary image, followed by erosion, and then N dilation operations can be performed on the entire image, where N is an integer greater than or equal to 1; thereby reducing edge noise interference.
[0071] In step S450, the upper and lower boundaries of the product in the first detection image are determined based on the first upper binary image and the first lower binary image to obtain the first detection area.
[0072] In this step, the terminal or server determines the upper and lower boundaries of the product in the first detection image based on the first upper binary image and the first lower binary image, so as to obtain the first detection area.
[0073] Figure 5 This is a flowchart illustrating a method for determining the upper and lower boundaries of a product in a first detection image based on a first upper binary image and a first lower binary image, thereby obtaining the first detection region, according to an embodiment of this disclosure. The method provided in this embodiment can be... Figure 2 The methods described in this embodiment are executed by a terminal or server, or by interaction between a terminal and a server. However, this disclosure is not limited thereto; the methods of this disclosure can be executed by any processor with computing power.
[0074] like Figure 5 As shown, the method provided in this disclosure embodiment may include the following steps.
[0075] In step S510, the estimated positions of the product edges in the first upper binary image and the first lower binary image are found by linear search.
[0076] In this step, the terminal or server finds the estimated location of the product edge in the first upper binary image and the first lower binary image by linear search.
[0077] In step S520, non-zero points are found in the estimated positions of the product edges in the first upper binary image and the first lower binary image to form the edge regions of the product in the first upper binary image and the first lower binary image.
[0078] In this step, the terminal or server finds non-zero points (points with a value of 1) in the estimated positions of the product edges in the first upper binary image and the first lower binary image, forming the edge regions of the product in the first upper binary image and the first lower binary image.
[0079] In step S530, the lower edge of the edge region of the first upper binary image is located to determine the upper boundary of the product.
[0080] In this step, the terminal or server locates the lower edge of the edge region of the first upper binary image to determine the upper boundary of the product.
[0081] In step S540, the upper edge of the edge region of the first lower binary image is located to determine the lower boundary of the product.
[0082] In this step, the terminal or server locates the upper edge of the edge region of the first binary image to determine the lower boundary of the product.
[0083] In step S550, the first detection area is obtained based on the upper boundary and the lower boundary of the product.
[0084] In this step, the terminal or server obtains the first detection area based on the upper and lower boundaries of the product. Specifically, the upper and lower boundaries of the product are formed by quadratic curve fitting using the edge points of the upper and lower boundaries.
[0085] In one embodiment, obtaining the first detection area based on the upper boundary and the lower boundary of the product includes: setting M rectangular boxes centered on the edge points of the upper boundary and the lower boundary of the product; performing adaptive gradient calculation on the M rectangular boxes and superimposing boundary threshold range conditions, and using a quadratic curve to fit and form the true upper boundary and the true lower boundary of the product.
[0086] Figure 6 This is a schematic diagram of the structure of a product surface defect detection device provided in an embodiment of this disclosure.
[0087] like Figure 6 As shown, the product surface defect detection device 600 provided in this embodiment may include:
[0088] Acquisition unit 610 is used to acquire the first detection image;
[0089] Region unit 620 is used to obtain a first detection region of the first detection image through a region detection algorithm;
[0090] The dilation unit 630 is used to perform an image dilation operation on the first detection region to obtain a first dilated detection region.
[0091] Binarization unit 640 is used to binarize the first dilated detection region to obtain the first dilated binary detection region.
[0092] The operation unit 650 is used to perform an AND operation between the first expanded detection area and the first expanded binary detection area to obtain a defect area.
[0093] Figure 6 The device for detecting defects on the curved surface of a product comprises: an acquisition unit for acquiring a first detection image; a region unit for acquiring a first detection region of the first detection image using a region detection algorithm; a dilation unit for performing an image dilation operation on the first detection region to obtain a first dilated detection region; a binarization unit for binarizing the first dilated detection region to obtain a first dilated binary detection region; and an AND operation unit for performing an AND operation between the first dilated detection region and the first dilated binary detection region to obtain a defect region, thereby enabling the detection of the curved surface of the product.
[0094] In one embodiment, the region unit 620 is further configured to set a threshold to obtain a first pixel region of the first detection image; obtain a first grayscale average value of the first pixel region; obtain a first binary image based on the first grayscale average value; divide the first binary image into a first upper binary image and a first lower binary image; and determine the upper and lower boundaries of the product in the first detection image based on the first upper binary image and the first lower binary image to obtain the first detection region.
[0095] In one embodiment, region unit 620 is further configured to apply Gaussian filtering to the first binary image, then erosion, and then N dilation operations to the entire image, where N is an integer greater than or equal to 1.
[0096] In one embodiment, region unit 620 is further configured to: find the estimated positions of product edges in the first upper binary image and the first lower binary image by straight line search; find non-zero points among the estimated positions of product edges in the first upper binary image and the first lower binary image to form edge regions of the product in the first upper binary image and the first lower binary image; find the lower edge of the edge region of the first upper binary image to determine the upper boundary of the product; find the upper edge of the edge region of the first lower binary image to determine the lower boundary of the product; and obtain the first detection region based on the upper boundary and the lower boundary of the product.
[0097] In one embodiment, region unit 620 is further configured to set M rectangular frames centered on the edge points of the upper boundary and the lower boundary of the product; perform adaptive gradient calculation on the M rectangular frames and superimpose boundary threshold range conditions, and use quadratic curves to fit and form the true upper boundary and the true lower boundary of the product.
[0098] In one embodiment, the acquisition unit 610 is further configured to perform connected component calculation on the first dilated binary detection region to obtain the background region; and to obtain the average grayscale value of the background region.
[0099] In one embodiment, the operation unit 650 is further configured to filter noise in the defect area using the average grayscale value of the background area, and determine the final defect area using area and brightness conditions.
[0100] See Figure 7 , Figure 7 This is a schematic diagram of the structure of a computer device 700 that implements the product surface defect detection method provided in the embodiments of this disclosure.
[0101] like Figure 7 As shown, the computer device in this embodiment may include one or more processors 701, a memory 702, and an input / output interface 703. The processor 701, memory 702, and input / output interface 703 are connected via a bus 704. The memory 702 stores a computer program, which includes program instructions. The input / output interface 703 receives and outputs data, such as for data interaction between the host machine and the computer device, or for data interaction between various virtual machines within the host machine. The processor 701 executes the program instructions stored in the memory 702.
[0102] The processor 701 can perform the following operations:
[0103] A first detection image is acquired; a first detection region of the first detection image is acquired using a region detection algorithm; an image dilation operation is performed on the first detection region to obtain a first dilated detection region; the first dilated detection region is binarized to obtain a first dilated binary detection region; and the first dilated detection region and the first dilated binary detection region are ANDed to obtain a defect region.
[0104] In some feasible implementations, the processor 701 may be a central processing unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0105] The memory 702 may include read-only memory and random access memory, and provides instructions and data to the processor 701 and the input / output interface 703. A portion of the memory 702 may also include non-volatile random access memory. For example, the memory 702 may also store device type information.
[0106] In practice, the computer device can execute the implementation methods provided by the steps in the above embodiments through its built-in functional modules. For details, please refer to the implementation methods provided by the steps in the above embodiments, which will not be repeated here.
[0107] This disclosure provides a computer device including a processor, an input / output interface, and a memory. The processor retrieves a computer program from the memory and executes the steps of the method shown in the above embodiments to perform a transmission operation.
[0108] This disclosure also provides a computer-readable storage medium storing a computer program adapted to be loaded by a processor and execute the methods provided in the steps of the above embodiments. Specific implementations of the steps in the above embodiments can be found therein and will not be repeated here. Furthermore, the beneficial effects of using the same method will not be repeated here either. For technical details not disclosed in the embodiments of the computer-readable storage medium involved in this disclosure, please refer to the description of the method embodiments of this disclosure. As an example, the computer program can be deployed to execute on a single computer device, or on multiple computer devices located in one location, or on multiple computer devices distributed across multiple locations and interconnected via a communication network.
[0109] The computer-readable storage medium can be the apparatus provided in any of the foregoing embodiments or the internal storage unit of the computer device, such as the hard disk or memory of the computer device. The computer-readable storage medium can also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., provided on the computer device. Furthermore, the computer-readable storage medium can include both internal storage units and external storage devices of the computer device. The computer-readable storage medium is used to store the computer program and other programs and data required by the computer device. The computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
[0110] This disclosure also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various alternative embodiments described above.
[0111] The terms "first," "second," etc., used in the specification, claims, and drawings of this disclosure are used to distinguish different objects, not to describe a specific order. Furthermore, the term "comprising," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or device that includes a series of steps or units is not limited to the listed steps or modules, but may optionally include steps or modules not listed, or may optionally include other step units inherent to these processes, methods, apparatuses, products, or devices.
[0112] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been generally described in terms of functionality. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this disclosure.
[0113] The methods and related apparatuses provided in this disclosure are described with reference to the method flowcharts and / or structural diagrams provided in this disclosure. Specifically, each block of the method flowchart and / or structural diagram, as well as combinations of blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions are provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable transmission device to create a machine, such that the instructions, which execute via the processor of the computer or other programmable transmission device, generate instructions for implementing the process. Figure 1 A schematic diagram of one or more processes and / or structures. Figure 1 The computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable transmission 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 A schematic diagram of one or more processes and / or structures. Figure 1 The functions specified in one or more boxes. These computer program instructions may also be loaded onto a computer or other programmable transmission device to cause a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable device for implementing the process. Figure 1 A process or multiple processes and / or structures illustrate the steps of the functions specified in one or more boxes.
[0114] The above-disclosed embodiments are merely preferred embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Therefore, any equivalent variations made in accordance with the claims of this disclosure shall still fall within the scope of this disclosure.
Claims
1. A method for detecting surface defects in a product, characterized in that, include: Acquire the first detection image; The first detection region of the first detection image is obtained by a region detection algorithm; An image dilation operation is performed on the first detection region to obtain a first dilated detection region; The first dilated detection region is binarized to obtain the first dilated binary detection region; Perform an AND operation between the first expanded detection area and the first expanded binary detection area to obtain the defect area; The method of obtaining the first detection region of the first detection image through the region detection algorithm includes: setting a threshold to obtain the first pixel region of the first detection image; obtaining the first grayscale average value of the first pixel region; obtaining a first binary image based on the first grayscale average value; dividing the first binary image into a first upper binary image and a first lower binary image; and determining the upper and lower boundaries of the product in the first detection image based on the first upper binary image and the first lower binary image to obtain the first detection region. The process of determining the upper and lower boundaries of the product in the first detection image based on the first upper binary image and the first lower binary image to obtain the first detection region includes: finding the estimated positions of the product edges in the first upper binary image and the first lower binary image by searching for straight lines; finding non-zero points among the estimated positions of the product edges in the first upper binary image and the first lower binary image to form the edge regions of the product in the first upper binary image and the first lower binary image; finding the lower edge of the edge region of the first upper binary image to determine the upper boundary of the product; finding the upper edge of the edge region of the first lower binary image to determine the lower boundary of the product; and obtaining the first detection region based on the upper boundary and the lower boundary of the product.
2. The method according to claim 1, characterized in that, Obtaining the first detection region of the first detection image through the region detection algorithm also includes: The first binary image is subjected to Gaussian filtering, then erosion, and then N dilation operations are performed on the entire image, where N is an integer greater than or equal to 1.
3. The method according to claim 1, characterized in that, The first detection area is obtained based on the upper boundary and the lower boundary of the product, including: M rectangles are set with the edge points of the upper and lower boundaries of the product as centers, where M is an integer greater than or equal to 1; Adaptive gradient calculation is performed on the M rectangles, and boundary threshold range conditions are superimposed. Then, a quadratic curve is used for fitting to form the true upper boundary and the true lower boundary of the product.
4. The method according to claim 1, characterized in that, Also includes: Perform connected component calculation on the first dilated binary detection region to obtain the background region; Obtain the average grayscale value of the background area.
5. The method according to claim 4, characterized in that, The defect region is obtained by performing a bitwise AND operation between the first expanded detection region and the first expanded binary detection region, including: The defective area is filtered for noise using the average grayscale value of the background area, and the final defective area is determined by using area and brightness conditions.
6. A device for detecting surface defects in products, characterized in that, include: The acquisition unit is used to acquire the first detection image; A region unit is used to obtain a first detection region of the first detection image through a region detection algorithm. An image dilation unit is used to perform an image dilation operation on the first detection region to obtain a first dilated detection region. A binarization unit is used to binarize the first dilated detection region to obtain a first dilated binary detection region. The AND operation unit is used to perform an AND operation between the first expanded detection area and the first expanded binary detection area to obtain a defect area. The region unit is further configured to set a threshold to obtain a first pixel region of the first detection image; obtain a first grayscale average value of the first pixel region; obtain a first binary image based on the first grayscale average value; divide the first binary image into a first upper binary image and a first lower binary image; determine the upper and lower boundaries of the product in the first detection image based on the first upper binary image and the first lower binary image to obtain the first detection region; The region unit is also used to find the estimated position of the product edge in the first upper binary image and the first lower binary image by searching a straight line; and to find the non-zero point among the estimated positions of the product edge in the first upper binary image and the first lower binary image to form the edge region of the product in the first upper binary image and the first lower binary image. Find the lower edge of the edge region of the first upper binary image to determine the upper boundary of the product; The upper edge of the edge region of the first lower binary image is located to determine the lower boundary of the product; the first detection region is obtained based on the upper boundary and the lower boundary of the product.
7. A computer device, characterized in that, Includes processor, memory, and input / output interfaces; The processor is connected to the memory and the input / output interface respectively, wherein the input / output interface is used to receive data and output data, the memory is used to store computer programs, and the processor is used to call the computer programs so that the computer device executes the method according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program adapted to be loaded and executed by a processor to cause a computer device having the processor to perform the method of any one of claims 1-5.
9. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the method described in any one of claims 1-5.