[go: up one dir, main page]

CN111325728A - Product defect detection method, device, equipment and storage medium - Google Patents

Product defect detection method, device, equipment and storage medium Download PDF

Info

Publication number
CN111325728A
CN111325728A CN202010102720.4A CN202010102720A CN111325728A CN 111325728 A CN111325728 A CN 111325728A CN 202010102720 A CN202010102720 A CN 202010102720A CN 111325728 A CN111325728 A CN 111325728A
Authority
CN
China
Prior art keywords
image
product
segmentation result
image segmentation
algorithm
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010102720.4A
Other languages
Chinese (zh)
Other versions
CN111325728B (en
Inventor
贡毅
刘真榕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Southern University of Science and Technology
Original Assignee
Southern University of Science and Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Southern University of Science and Technology filed Critical Southern University of Science and Technology
Priority to CN202010102720.4A priority Critical patent/CN111325728B/en
Publication of CN111325728A publication Critical patent/CN111325728A/en
Application granted granted Critical
Publication of CN111325728B publication Critical patent/CN111325728B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/0002Inspection of images, e.g. flaw detection
    • G06T7/0004Industrial image inspection
    • G06T7/0006Industrial image inspection using a design-rule based approach
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/11Region-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/13Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/155Segmentation; Edge detection involving morphological operators
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10004Still image; Photographic image
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/30Computing systems specially adapted for manufacturing

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Investigating Materials By The Use Of Optical Means Adapted For Particular Applications (AREA)
  • Image Processing (AREA)
  • Image Analysis (AREA)

Abstract

本发明公开了一种产品缺陷检测方法、装置、设备及存储介质,涉及自动检测技术领域,其中,一种产品缺陷检测方法包括:获取待检测产品图像;采用大律算法对待检测产品图像进行处理,得到第一图像分割结果;采用高斯混合模型算法对待检测产品图像进行处理,得到第二图像分割结果;采用后处理算法对第一图像分割结果和第二图像分割结果进行处理,得到检测结果。本发明能够大幅度地提高检测速度,适用于不同类型产品的表面缺陷检测,还能够减小不同光源、检测件摆放角度和阴影情况等外界因素对检测结果的影响,实现对生产线产品缺陷的准确检测。

Figure 202010102720

The invention discloses a product defect detection method, device, equipment and storage medium, and relates to the technical field of automatic detection, wherein a product defect detection method includes: acquiring an image of a product to be detected; , obtain the first image segmentation result; use the Gaussian mixture model algorithm to process the image of the product to be detected to obtain the second image segmentation result; use the post-processing algorithm to process the first image segmentation result and the second image segmentation result to obtain the detection result. The invention can greatly improve the detection speed, is suitable for surface defect detection of different types of products, and can also reduce the influence of external factors such as different light sources, detection parts placement angles and shadow conditions on the detection results, and realize the detection of product defects in the production line. Accurate detection.

Figure 202010102720

Description

产品缺陷检测方法、装置、设备及存储介质Product defect detection method, device, equipment and storage medium

技术领域technical field

本发明涉及自动检测技术领域,尤其是涉及一种产品缺陷检测方法、装置、设备及存储介质。The present invention relates to the technical field of automatic detection, in particular to a product defect detection method, device, equipment and storage medium.

背景技术Background technique

在工业生产过程中,由于机械震动、声音及光线等外界环境以及复杂的生产工艺,可能导致生产出的产品外观不良,从而使生产出的产品变成缺陷产品,降低了生产效率。为了保障产品的外观符合相应的生产要求,需要对工业生产过程中的产品进行一系列检测。In the process of industrial production, due to the external environment such as mechanical vibration, sound and light, as well as complex production processes, the appearance of the produced products may be poor, so that the produced products become defective products and reduce production efficiency. In order to ensure that the appearance of the product meets the corresponding production requirements, it is necessary to carry out a series of inspections on the products in the industrial production process.

目前,产品表面缺陷检测方法主要包括人工检测和机器视觉检测两种。人工检测的方式,存在检测效率低、产品生产成本高等问题。机器视觉检测的方式,可以实现表面缺陷检测的自动化,但是在现有的机器视觉检测中的表面缺陷检测模型都只是针对某种特定的产品表面或者特定的某类缺陷进行检测。但是,在实际的生产过程中,一条生产线可能生产多种产品,不同类型的产品的表面缺陷类型也可能不相同。此时,对不同的产品检测表面缺陷时,都需要设计开发不同的表面缺陷检测模型,整个过程周期长,耗费的时间和人力成本也较高。At present, the detection methods of product surface defects mainly include manual detection and machine vision detection. The manual detection method has the problems of low detection efficiency and high production cost. The machine vision inspection method can realize the automation of surface defect detection, but the surface defect detection models in the existing machine vision inspection only detect a specific product surface or a specific type of defect. However, in the actual production process, a production line may produce a variety of products, and the types of surface defects of different types of products may also be different. At this time, when detecting surface defects of different products, it is necessary to design and develop different surface defect detection models. The whole process cycle is long, and the time and labor costs are also high.

发明内容SUMMARY OF THE INVENTION

本发明的目的是至少在一定程度上解决现有技术中存在的技术问题之一。为此,本发明提出一种产品缺陷检测方法,能够大幅度地提高检测速度,适用于不同类型产品的表面缺陷检测。The purpose of the present invention is to solve one of the technical problems existing in the prior art at least to a certain extent. Therefore, the present invention proposes a product defect detection method, which can greatly improve the detection speed and is suitable for surface defect detection of different types of products.

本发明还提出一种产品缺陷检测装置。The invention also provides a product defect detection device.

本发明还提出一种产品缺陷检测设备。The invention also provides a product defect detection device.

本发明还提出一种计算机可读存储介质。The present invention also provides a computer-readable storage medium.

第一方面,本发明的一个实施例提供了一种产品缺陷检测方法,包括:In a first aspect, an embodiment of the present invention provides a product defect detection method, including:

获取待检测产品图像;Obtain the image of the product to be detected;

采用大律(Otsu)算法对待检测产品图像进行处理,得到第一图像分割结果;The image of the product to be detected is processed by using the Otsu algorithm to obtain the first image segmentation result;

采用高斯混合模型算法对待检测产品图像进行处理,得到第二图像分割结果;The Gaussian mixture model algorithm is used to process the image of the product to be detected, and the second image segmentation result is obtained;

采用后处理算法对第一图像分割结果和第二图像分割结果进行处理,得到检测结果。A post-processing algorithm is used to process the first image segmentation result and the second image segmentation result to obtain a detection result.

本发明实施例的一种产品缺陷检测方法至少具有如下有益效果:A product defect detection method according to the embodiment of the present invention has at least the following beneficial effects:

1.能够大幅度地提高检测速度;1. Can greatly improve the detection speed;

2.适用于不同类型产品的表面缺陷检测;2. Suitable for surface defect detection of different types of products;

3.能够减小不同光源、检测件摆放角度和阴影情况等外界因素对检测结果的影响,实现对生产线产品缺陷的准确检测。3. It can reduce the influence of external factors such as different light sources, inspection parts placement angles and shadows on the inspection results, and achieve accurate detection of product defects in the production line.

根据本发明的另一些实施例的一种产品缺陷检测方法,采用Otsu算法对待检测产品图像进行处理,得到第一图像分割结果,包括:According to a product defect detection method according to other embodiments of the present invention, the Otsu algorithm is used to process the image of the product to be detected to obtain a first image segmentation result, including:

对待检测产品图像进行灰度处理,得到灰度图;Perform grayscale processing on the image of the product to be detected to obtain a grayscale image;

对灰度图进行伽马校正,得到伽马校正图;Perform gamma correction on the grayscale image to obtain a gamma corrected image;

对伽马校正图进行Otsu分割,得到Otsu分割结果;Perform Otsu segmentation on the gamma correction map to obtain the Otsu segmentation result;

对Otsu分割结果进行形态学处理,得到形态学矫正结果;Perform morphological processing on Otsu segmentation results to obtain morphological correction results;

对形态学矫正结果进行中值滤波,得到第一图像分割结果。Perform median filtering on the morphological correction result to obtain the first image segmentation result.

本发明实施例的一种产品缺陷检测方法,对传统的Otsu算法进行了改进,传统的Otsu算法包括灰度处理和Otsu分割,而改进的Otsu算法还包括伽马校正、形态学处理和中值滤波。改进的Otsu算法相较于传统的Otsu算法,由于计算更加简便,因此能够在不耗费大量计算时间的情况下,快速、稳定地对产品图像进行检测,并且还提高了检测的准确度。A product defect detection method according to an embodiment of the present invention improves the traditional Otsu algorithm. The traditional Otsu algorithm includes grayscale processing and Otsu segmentation, while the improved Otsu algorithm also includes gamma correction, morphological processing and median value. filter. Compared with the traditional Otsu algorithm, the improved Otsu algorithm is simpler to calculate, so it can detect product images quickly and stably without spending a lot of computing time, and also improves the detection accuracy.

根据本发明的另一些实施例的一种产品缺陷检测方法,对Otsu分割结果进行形态学处理,得到形态学矫正结果,包括:According to a product defect detection method according to other embodiments of the present invention, morphological processing is performed on the Otsu segmentation result to obtain a morphological correction result, including:

采用低通滤波法对Otsu分割结果进行灰度平滑和边缘平滑,得到形态学矫正结果。The low-pass filtering method is used to perform grayscale smoothing and edge smoothing on the Otsu segmentation results, and the morphological correction results are obtained.

根据本发明的另一些实施例的一种产品缺陷检测方法,采用高斯混合模型算法对待检测产品图像进行处理,得到第二图像分割结果,包括:According to a product defect detection method according to other embodiments of the present invention, a Gaussian mixture model algorithm is used to process the image of the product to be detected to obtain a second image segmentation result, including:

对待检测产品图像进行色调饱和值(HSV)空间颜色提取,得到HSV彩色图;Extract the hue saturation value (HSV) space color of the image of the product to be detected to obtain the HSV color map;

对HSV彩色图进行期望最大值(EM)算法分割,得到第二图像分割结果。The expected maximum (EM) algorithm segmentation is performed on the HSV color image to obtain the second image segmentation result.

本发明实施例的一种产品缺陷检测方法,通过高斯混合模型对输入的待检测产品图像的像素值进行模拟,通过不同的单高斯模型来确定每个像素点的类型,从而对产品图像进行检测,得到第二图像分割结果。In a product defect detection method according to an embodiment of the present invention, a Gaussian mixture model is used to simulate the pixel value of an input image of a product to be detected, and different single Gaussian models are used to determine the type of each pixel, so as to detect the product image. , to obtain the second image segmentation result.

根据本发明的另一些实施例的一种产品缺陷检测方法,对HSV彩色图进行EM算法分割,得到第二图像分割结果,包括:According to a product defect detection method according to other embodiments of the present invention, EM algorithm segmentation is performed on the HSV color image to obtain a second image segmentation result, including:

建立高斯混合模型;Build a Gaussian mixture model;

采用高斯混合模型对HSV彩色图进行处理,得到高斯混合模型的模型数;The Gaussian mixture model is used to process the HSV color map to obtain the model number of the Gaussian mixture model;

根据高斯混合模型的模型数,得到高斯混合模型的优化模型;According to the number of models of the Gaussian mixture model, the optimal model of the Gaussian mixture model is obtained;

采用EM算法对优化模型进行参数估计,得到第二图像分割结果。The EM algorithm is used to estimate the parameters of the optimized model, and the second image segmentation result is obtained.

根据本发明的另一些实施例的一种产品缺陷检测方法,采用后处理算法对第一图像分割结果和第二图像分割结果进行处理,得到检测结果,包括:According to a product defect detection method according to other embodiments of the present invention, a post-processing algorithm is used to process the first image segmentation result and the second image segmentation result to obtain the detection result, including:

对第一图像分割结果和第二图像分割结果进行处理,得到第三图像分割结果;processing the first image segmentation result and the second image segmentation result to obtain a third image segmentation result;

采用形态学重建法对第三图像分割结果进行漏洞边缘检测和漏洞修补,得到检测结果。The morphological reconstruction method is used to detect and repair the vulnerability edge of the third image segmentation result, and the detection result is obtained.

本发明实施例的一种产品缺陷检测方法,通过漏洞边缘检测和漏洞修补,能够克服光照令EM算法难以正确分类的问题,从而提高了EM算法检测的准确性。A product defect detection method according to an embodiment of the present invention can overcome the problem that illumination makes it difficult for the EM algorithm to classify correctly through vulnerability edge detection and vulnerability repair, thereby improving the detection accuracy of the EM algorithm.

第二方面,本发明的一个实施例提供了一种产品缺陷检测装置,包括:In a second aspect, an embodiment of the present invention provides a product defect detection device, including:

图像获取模块,用于获取待检测产品图像;The image acquisition module is used to acquire the image of the product to be detected;

第一图像分割模块,用于采用Otsu算法对待检测产品图像进行处理,得到第一图像分割结果;a first image segmentation module, used to process the image of the product to be detected by using the Otsu algorithm to obtain a first image segmentation result;

第二图像分割模块,用于采用高斯混合模型算法对待检测产品图像进行处理,得到第二图像分割结果;The second image segmentation module is used to process the image of the product to be detected by using a Gaussian mixture model algorithm to obtain a second image segmentation result;

后处理模块,用于采用后处理算法对第一图像分割结果和第二图像分割结果进行处理,得到检测结果。The post-processing module is used for processing the first image segmentation result and the second image segmentation result by using a post-processing algorithm to obtain a detection result.

本发明实施例的一种产品缺陷检测装置至少具有如下有益效果:A product defect detection device according to an embodiment of the present invention has at least the following beneficial effects:

1.第一图像分割模块分割结果稳定、快速,第二图像分割模块分割结果精准、计算速度较快且不需要大量的训练样本;1. The segmentation results of the first image segmentation module are stable and fast, and the segmentation results of the second image segmentation module are accurate, fast in calculation, and do not require a large number of training samples;

2.后处理模块对第一图像分割结果和第二图像分割结果进行处理,既能可靠地检测产品图像,又能大幅度地提高检测的速度;2. The post-processing module processes the first image segmentation result and the second image segmentation result, which can not only detect the product image reliably, but also greatly improve the detection speed;

3.适用于不同类型产品的表面缺陷检测;3. Suitable for surface defect detection of different types of products;

4.能够减小不同光源、检测件摆放角度和阴影情况等外界因素对检测结果的影响,实现对生产线产品缺陷的准确检测。4. It can reduce the influence of external factors such as different light sources, inspection parts placement angles and shadows on the inspection results, and achieve accurate detection of product defects in the production line.

根据本发明的另一些实施例的一种产品缺陷检测装置,后处理算法包括漏洞边缘检测和漏洞修补。According to a product defect detection device according to other embodiments of the present invention, the post-processing algorithm includes vulnerability edge detection and vulnerability repair.

第三方面,本发明的一个实施例提供了一种产品缺陷检测设备,包括:In a third aspect, an embodiment of the present invention provides a product defect detection device, including:

至少一个处理器,以及,at least one processor, and,

与至少一个处理器通信连接的存储器;其中,a memory communicatively coupled to the at least one processor; wherein,

存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够执行本发明的一些实施例的一种产品缺陷检测方法。The memory stores instructions executable by the at least one processor to enable the at least one processor to perform a product defect detection method according to some embodiments of the present invention.

本发明实施例的一种产品缺陷检测设备至少具有如下有益效果:A product defect detection device according to an embodiment of the present invention has at least the following beneficial effects:

1.能够大幅度地提高检测速度;1. Can greatly improve the detection speed;

2.适用于不同类型产品的表面缺陷检测;2. Suitable for surface defect detection of different types of products;

3.能够减小不同光源、检测件摆放角度和阴影情况等外界因素对检测结果的影响,实现对生产线产品缺陷的准确检测。3. It can reduce the influence of external factors such as different light sources, inspection parts placement angles and shadows on the inspection results, and achieve accurate detection of product defects in the production line.

第四方面,本发明的一个实施例提供了一种计算机可读存储介质,计算机可读存储介质存储有计算机可执行指令,计算机可执行指令用于使计算机执行本发明的一些实施例的一种产品缺陷检测方法。In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to cause a computer to execute one of some embodiments of the present invention Product defect detection methods.

本发明实施例的一种计算机可读存储介质至少具有如下有益效果:A computer-readable storage medium according to an embodiment of the present invention has at least the following beneficial effects:

1.能够大幅度地提高检测速度;1. Can greatly improve the detection speed;

2.适用于不同类型产品的表面缺陷检测;2. Suitable for surface defect detection of different types of products;

3.能够减小不同光源、检测件摆放角度和阴影情况等外界因素对检测结果的影响,实现对生产线产品缺陷的准确检测。3. It can reduce the influence of external factors such as different light sources, inspection parts placement angles and shadows on the inspection results, and achieve accurate detection of product defects in the production line.

附图说明Description of drawings

图1是本发明实施例中一种产品缺陷检测方法的一具体实施例的流程示意图;1 is a schematic flowchart of a specific embodiment of a product defect detection method in an embodiment of the present invention;

图2是本发明实施例中一种产品缺陷检测方法的另一具体实施例的流程示意图;2 is a schematic flowchart of another specific embodiment of a product defect detection method in an embodiment of the present invention;

图3是本发明实施例中一种产品缺陷检测方法的另一具体实施例的流程示意图;3 is a schematic flowchart of another specific embodiment of a product defect detection method in an embodiment of the present invention;

图4是本发明实施例中一种产品缺陷检测方法的另一具体实施例的流程示意图;4 is a schematic flowchart of another specific embodiment of a product defect detection method in an embodiment of the present invention;

图5是本发明实施例中一种产品缺陷检测装置的一具体实施例的模块框图。FIG. 5 is a block diagram of a module of a specific embodiment of a product defect detection device in an embodiment of the present invention.

具体实施方式Detailed ways

以下将结合实施例对本发明的构思及产生的技术效果进行清楚、完整地描述,以充分地理解本发明的目的、特征和效果。显然,所描述的实施例只是本发明的一部分实施例,而不是全部实施例,基于本发明的实施例,本领域的技术人员在不付出创造性劳动的前提下所获得的其他实施例,均属于本发明保护的范围。The concept of the present invention and the technical effects produced will be clearly and completely described below with reference to the embodiments, so as to fully understand the purpose, characteristics and effects of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, other embodiments obtained by those skilled in the art without creative efforts are all within the scope of The scope of protection of the present invention.

在本发明的描述中,如果某一特征被称为“设置”、“固定”、“连接”、“安装”在另一个特征,它可以直接设置、固定、连接在另一个特征上,也可以间接地设置、固定、连接、安装在另一个特征上。In the description of the present invention, if a feature is referred to as "arranged", "fixed", "connected", "installed" on another feature, it can be directly set, fixed, connected to the other feature, or it can be Indirectly set, fastened, connected, mounted on another feature.

在本发明实施例的描述中,如果涉及到“多个”,其含义是两个以上,如果涉及到“大于”、“小于”、“超过”,均应理解为不包括本数,如果涉及到“以上”、“以下”、“以内”,均应理解为包括本数。如果涉及到“第一”、“第二”,应当理解为用于区分技术特征,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量或者隐含指明所指示的技术特征的先后关系。In the description of the embodiments of the present invention, if it refers to "multiple", it means more than two. If it refers to "greater than", "less than", and "exceeds", it should be understood as not including this number. "Above", "below" and "within" should be understood to include the number. If it refers to "first" and "second", it should be understood to be used to distinguish technical features, but not to indicate or imply relative importance, or to imply indicate the number of indicated technical features or to imply indicate the indicated The sequence of technical features.

实施例1Example 1

参照图1,示出了本发明实施例中一种产品缺陷检测方法的一具体实施例的流程示意图。如图1所示,本发明实施例的一种产品缺陷检测方法,具体步骤包括:Referring to FIG. 1 , a schematic flowchart of a specific embodiment of a product defect detection method in an embodiment of the present invention is shown. As shown in FIG. 1 , the specific steps of a product defect detection method according to an embodiment of the present invention include:

S1000.获取待检测产品图像。S1000. Obtain an image of the product to be detected.

获取待检测产品图像,可以使用产品扫描成像设备对待检测产品进行扫描,获取待检测产品图像样本。To obtain an image of the product to be inspected, a product scanning imaging device can be used to scan the product to be inspected to obtain image samples of the product to be inspected.

S1100.采用大律(Otsu)算法对待检测产品图像进行处理,得到第一图像分割结果。S1100. Use the Otsu algorithm to process the image of the product to be detected to obtain a first image segmentation result.

Otsu算法是按图像的灰度特性,将图像分成背景和目标两个部分。背景和目标之间的类间方差越大,说明构成图像的两个部分的差别越大,当部分目标被错分成背景,或者部分背景被错分成目标,都会导致两个部分的差别变小。因此,使类间方差最大的分割意味着错分的概率最小。The Otsu algorithm divides the image into two parts: background and target according to the grayscale characteristics of the image. The greater the inter-class variance between the background and the target, the greater the difference between the two parts that make up the image. When part of the target is mistakenly divided into the background, or part of the background is mistakenly divided into the target, the difference between the two parts will become smaller. Therefore, the segmentation that maximizes the between-class variance means that the probability of misclassification is minimized.

在本发明实施例的另一些具体实施例中,参照图2,示出了本发明实施例中一种产品缺陷检测方法的另一具体实施例的流程示意图。如图2所示,本发明实施例的一种产品缺陷检测方法,采用Otsu算法对待检测产品图像进行处理,得到第一图像分割结果,具体步骤包括:In other specific embodiments of the embodiments of the present invention, referring to FIG. 2 , a schematic flowchart of another specific embodiment of a product defect detection method in an embodiment of the present invention is shown. As shown in Figure 2, a product defect detection method according to an embodiment of the present invention adopts the Otsu algorithm to process the image of the product to be detected to obtain a first image segmentation result, and the specific steps include:

S1110.对待检测产品图像进行灰度处理,得到灰度图。S1110. Perform grayscale processing on the image of the product to be detected to obtain a grayscale image.

灰度图像上每个像素的颜色值又称为灰度,指黑白图像中点的颜色深度,范围一般从0到255,白色为255,黑色为0。所谓灰度值是指色彩的浓淡程度。本实施例对待检测产品图像进行灰度处理,可采用如下四种方式中的任一种:The color value of each pixel on a grayscale image, also known as grayscale, refers to the color depth of a point in a black-and-white image, generally ranging from 0 to 255, with 255 for white and 0 for black. The so-called gray value refers to the degree of shade of color. In this embodiment, the grayscale processing of the image of the product to be detected can be performed in any of the following four ways:

(1)分量法,将RGB彩色图像中的三分量的亮度作为三个灰度图像的灰度值,可根据应用需要选取一种灰度图像。(1) Component method, the brightness of the three components in the RGB color image is used as the grayscale value of the three grayscale images, and one grayscale image can be selected according to the application needs.

(2)最大值法,将RGB彩色图像中的三分量的亮度最大值作为灰度图的灰度值。(2) The maximum value method, the maximum value of the brightness of the three components in the RGB color image is used as the gray value of the gray image.

(3)平均值法,将RGB彩色图像中的三分量的亮度平均值作为灰度图的灰度值。(3) The average value method, the average value of the brightness of the three components in the RGB color image is used as the gray value of the gray image.

(4)加权平均法,根据重要性及其它指标,将RGB彩色图像中的三个分量以不同的权值进行加权平均。(4) Weighted average method, according to the importance and other indicators, the three components in the RGB color image are weighted and averaged with different weights.

S1120.对灰度图进行伽马校正,得到伽马校正图。S1120. Perform gamma correction on the grayscale image to obtain a gamma correction image.

伽马校正能够消除在图片采集时光照不平衡对成像效果的影响。对灰度图进行伽马校正,是对图像灰度值进行非线性操作,使输出图像灰度值与输入图像灰度值呈指数关系。Gamma correction can eliminate the influence of lighting imbalance on the imaging effect when the picture is captured. Gamma correction for grayscale image is a nonlinear operation on the grayscale value of the image, so that the grayscale value of the output image has an exponential relationship with the grayscale value of the input image.

S1130.对伽马校正图进行Otsu分割,得到Otsu分割结果。S1130. Perform Otsu segmentation on the gamma correction image to obtain an Otsu segmentation result.

对伽马校正图进行Otsu分割,将阈值从0-255依次遍历,寻找最优阈值,取最优阈值把伽马校正图分为前景色与背景色,两部分的类间方差越大,说明两部分差别越大,便能有效的分割图像。Perform Otsu segmentation on the gamma correction map, traverse the thresholds from 0-255 in order, find the optimal threshold, and take the optimal threshold to divide the gamma correction map into foreground color and background color. The greater the difference between the two parts, the more effectively the image can be segmented.

S1140.对Otsu分割结果进行形态学处理,得到形态学矫正结果。S1140. Perform morphological processing on the Otsu segmentation result to obtain a morphological correction result.

对Otsu分割结果进行形态学处理,能够消除Otsu分割结果中出现的边缘毛刺。Morphological processing of Otsu segmentation results can eliminate edge burrs in Otsu segmentation results.

在本发明实施例的另一些具体实施例中,对Otsu分割结果进行形态学处理,得到形态学矫正结果,包括采用低通滤波法对Otsu分割结果进行灰度平滑和边缘平滑,得到形态学矫正结果。In other specific embodiments of the embodiments of the present invention, morphological processing is performed on the Otsu segmentation result to obtain a morphological correction result, including using a low-pass filtering method to perform grayscale smoothing and edge smoothing on the Otsu segmentation result to obtain a morphological correction result. result.

采用低通滤波法能够使灰度图中的像素值平坦,变化不大的点保留(对应分割区域),将图中像素值剧烈变化的点滤掉(对应边缘毛刺)。低通滤波法具体包括如下步骤:The low-pass filtering method can make the pixel value in the grayscale image flat, keep the points with little change (corresponding to the segmentation area), and filter out the points with sharp changes in the pixel value in the image (corresponding to edge burrs). The low-pass filtering method specifically includes the following steps:

S1141.确定核函数的大小。S1141. Determine the size of the kernel function.

低维空间线性不可分的模式,通过非线性映射到高维特征空间,则可能实现线性可分,但是如果直接采用这种技术在高维空间进行分类或回归,则存在确定非线性映射函数的形式和参数、特征空间维数等问题,而最大的障碍则是在高维特征空间运算时存在的“维数灾难”。采用核函数技术可以有效地解决这样问题。The linearly inseparable mode of the low-dimensional space can be linearly separable by nonlinear mapping to the high-dimensional feature space, but if this technique is directly used for classification or regression in the high-dimensional space, there is a form that determines the nonlinear mapping function. And parameters, feature space dimensions and other issues, and the biggest obstacle is the "curse of dimensionality" that exists in high-dimensional feature space operations. The use of kernel function technology can effectively solve such problems.

核函数能够将高维空间的内积运算转化为低维输入空间的核函数计算,从而巧妙地解决了在高维特征空间中计算的“维数灾难”等问题。核函数的大小可根据实际情况来确定。The kernel function can transform the inner product operation of the high-dimensional space into the kernel function calculation of the low-dimensional input space, thus ingeniously solving the problem of "curse of dimensionality" calculated in the high-dimensional feature space. The size of the kernel function can be determined according to the actual situation.

S1142.确定锚点位置。S1142. Determine the anchor point position.

在原图像中选取一锚点位置,锚点位置可根据实际情况确定。Select an anchor point position in the original image, and the anchor point position can be determined according to the actual situation.

S1143.根据核函数和锚点位置,确定锚点的像素值。S1143. Determine the pixel value of the anchor point according to the kernel function and the anchor point position.

通过计算锚点周围区域的像素点值来确定锚点的像素值,将锚点周围区域的像素点值与核函数的权重做卷积,得到锚点的像素值。通过核函数,平滑区域的像素点值将不会变化,而毛刺区域将会因为周围像素点数量的分布被重新平滑。The pixel value of the anchor point is determined by calculating the pixel value of the area around the anchor point, and the pixel value of the anchor point is convolved with the weight of the kernel function to obtain the pixel value of the anchor point. Through the kernel function, the pixel value of the smooth area will not change, and the glitch area will be re-smoothed due to the distribution of the number of surrounding pixels.

S1150.对形态学矫正结果进行中值滤波,得到第一图像分割结果。S1150. Perform median filtering on the morphological correction result to obtain a first image segmentation result.

中值滤波的方法与低通滤波法相似,仅是核函数的选取有所不同。在低通滤波中,根据核函数的权重和锚点周围区域的像素点值来确定锚点的像素值。而在中值滤波中,锚点的像素值是核函数覆盖区域的中值。中值滤波能够消除Otsu分割中出现的不符合实际情况的微小缺陷区域。The median filtering method is similar to the low-pass filtering method, but the selection of the kernel function is different. In low-pass filtering, the pixel value of the anchor point is determined according to the weight of the kernel function and the pixel value of the area around the anchor point. In median filtering, the pixel value of the anchor point is the median value of the area covered by the kernel function. The median filter can eliminate the small defect areas that do not meet the actual situation in Otsu segmentation.

本发明实施例的一种产品缺陷检测方法,对传统的Otsu算法进行了改进,传统的Otsu算法包括灰度处理和Otsu分割,而改进的Otsu算法还包括伽马校正、形态学处理和中值滤波。改进的Otsu算法相较于传统的Otsu算法,由于计算更加简便,因此能够在不耗费大量计算时间的情况下,快速、稳定地对产品图像进行检测,并且还提高了检测的准确度。A product defect detection method according to an embodiment of the present invention improves the traditional Otsu algorithm. The traditional Otsu algorithm includes grayscale processing and Otsu segmentation, while the improved Otsu algorithm also includes gamma correction, morphological processing and median value. filter. Compared with the traditional Otsu algorithm, the improved Otsu algorithm is simpler to calculate, so it can detect product images quickly and stably without spending a lot of computing time, and also improves the detection accuracy.

S1200.采用高斯混合模型算法对待检测产品图像进行处理,得到第二图像分割结果。S1200. Use a Gaussian mixture model algorithm to process the image of the product to be detected to obtain a second image segmentation result.

高斯混合模型就是用高斯概率密度函数精确地量化事物,将一个事物分解为若干的基于高斯概率密度函数形成的模型。对图像背景建立高斯模型的原理及过程:图像灰度直方图反映的是图像中某个灰度值出现的频次,也可以看作是图像灰度概率密度的估计。如果图像所包含的目标区域和背景区域相差比较大,且背景区域和目标区域在灰度上有一定的差异,那么该图像的灰度直方图呈现双峰-谷形状,其中一个峰对应于目标,另一个峰对应于背景的中心灰度。对于复杂的图像,尤其是工业产品图像,一般是多峰的。通过将直方图的多峰特性看作是多个高斯分布的叠加,可以解决图像的分割问题。The Gaussian mixture model is to use the Gaussian probability density function to accurately quantify things, and decompose a thing into several models based on the Gaussian probability density function. The principle and process of establishing a Gaussian model for the image background: the image grayscale histogram reflects the frequency of a certain grayscale value in the image, and can also be regarded as an estimation of the grayscale probability density of the image. If the image contains a large difference between the target area and the background area, and there is a certain difference in grayscale between the background area and the target area, then the grayscale histogram of the image presents a double peak-valley shape, and one of the peaks corresponds to the target area. , the other peak corresponds to the central grayscale of the background. For complex images, especially industrial product images, they are generally multimodal. The image segmentation problem can be solved by considering the multimodal nature of the histogram as a superposition of multiple Gaussian distributions.

在本发明实施例的另一些具体实施例中,参照图3,示出了本发明实施例中一种产品缺陷检测方法的另一具体实施例的流程示意图。如图3所示,本发明实施例的一种产品缺陷检测方法,采用高斯混合模型算法对待检测产品图像进行处理,得到第二图像分割结果,具体步骤包括:In other specific embodiments of the embodiments of the present invention, referring to FIG. 3 , a schematic flowchart of another specific embodiment of a product defect detection method in an embodiment of the present invention is shown. As shown in FIG. 3 , in a product defect detection method according to an embodiment of the present invention, a Gaussian mixture model algorithm is used to process an image of a product to be detected to obtain a second image segmentation result. The specific steps include:

S1210.对待检测产品图像进行色调饱和值(HSV)空间颜色提取,得到HSV彩色图。S1210. Perform hue saturation value (HSV) space color extraction on the image of the product to be detected to obtain an HSV color map.

S1220.对HSV彩色图进行期望最大值(EM)算法分割,得到第二图像分割结果。S1220. Perform expected maximum (EM) algorithm segmentation on the HSV color image to obtain a second image segmentation result.

在本发明实施例的另一些具体实施例中,对HSV彩色图进行EM算法分割,得到第二图像分割结果,具体步骤包括:In other specific embodiments of the embodiments of the present invention, the EM algorithm is performed on the HSV color image to obtain a second image segmentation result, and the specific steps include:

S1221.建立高斯混合模型。S1221. Build a Gaussian mixture model.

本发明实施例的高斯混合模型的数学表达形式如式(1)所示:The mathematical expression form of the Gaussian mixture model of the embodiment of the present invention is shown in formula (1):

Figure BDA0002387409430000081
Figure BDA0002387409430000081

其中,x表示像素点,p(x)表示像素点在图片中出现的概率。k表示像素点的类型(缺陷或非缺陷),p(k)表示图片中不同像素点类型的概率。p(x/k)表示在已知像素点类型的情况下,像素点在图片中出现的概率。πk与p(k)相同,表示图片中不同像素点类型的概率。因为像素点类型的概率分布属于离散模型,所以可以用小于1的数表示,需要注意的是必须满足

Figure BDA0002387409430000082
的条件。N(x/μkk)表示高斯分布,其中μk和Σk分别表示高斯分布的均值和方差。Among them, x represents the pixel point, and p(x) represents the probability of the pixel point appearing in the picture. k represents the type of pixel (defective or non-defective), and p(k) represents the probability of different pixel types in the picture. p(x/k) represents the probability of a pixel appearing in the picture given the known pixel type. π k is the same as p(k) and represents the probability of different pixel types in the image. Because the probability distribution of the pixel type belongs to a discrete model, it can be represented by a number less than 1. It should be noted that it must meet the
Figure BDA0002387409430000082
conditions of. N(x/μ k , Σ k ) represents a Gaussian distribution, where μ k and Σ k represent the mean and variance of the Gaussian distribution, respectively.

高斯混合模型的本质是融合几个单高斯模型,使得模型更加复杂,从而产生更复杂的样本。理论上,如果某个高斯混合模型融合的单高斯模型的个数足够多,它们之间的权重设定得足够合理,这个混合模型就可以拟合任意分布的样本。The essence of the Gaussian mixture model is to fuse several single Gaussian models to make the model more complex, resulting in more complex samples. In theory, if there are enough single Gaussian models fused by a Gaussian mixture model, and the weights between them are set reasonably enough, the mixture model can fit samples of any distribution.

S1222.采用高斯混合模型对HSV彩色图进行处理,得到高斯混合模型的模型数。S1222. Use the Gaussian mixture model to process the HSV color map to obtain the model number of the Gaussian mixture model.

本发明实施例的高斯混合模型的模型数根据式(2)确定:The model number of the Gaussian mixture model of the embodiment of the present invention is determined according to formula (2):

Figure BDA0002387409430000091
Figure BDA0002387409430000091

其中,Y表示输入的图片,

Figure BDA0002387409430000092
以及θ表示高斯分布的参数,对应式(1)中的μkk
Figure BDA0002387409430000093
表示输入图片的编码长度,πk表示图片中不同像素点类型的概率,P表示高斯分布的参数数量,K表示模型数量,N表示每张图片的像素点数量,
Figure BDA0002387409430000094
表示对参数数量的惩罚项。Among them, Y represents the input image,
Figure BDA0002387409430000092
And θ represents the parameters of the Gaussian distribution, corresponding to μ k , Σ k in formula (1),
Figure BDA0002387409430000093
Indicates the encoding length of the input image, π k represents the probability of different pixel types in the image, P represents the number of parameters of the Gaussian distribution, K represents the number of models, N represents the number of pixels in each image,
Figure BDA0002387409430000094
Represents a penalty term for the number of parameters.

将HSV彩色图输入到高斯混合模型中,通过式(2)能够计算得到最优的模型数。The HSV color map is input into the Gaussian mixture model, and the optimal number of models can be calculated by formula (2).

S1223.根据高斯混合模型的模型数,得到高斯混合模型的优化模型。S1223. Obtain an optimization model of the Gaussian mixture model according to the number of models of the Gaussian mixture model.

确定了最优的模型数,从而可以对高斯混合模型进一步地优化,得到优化模型。The optimal number of models is determined, so that the Gaussian mixture model can be further optimized to obtain the optimized model.

S1224.采用EM算法对优化模型进行参数估计,得到第二图像分割结果。S1224. Use the EM algorithm to estimate the parameters of the optimization model to obtain a second image segmentation result.

EM算法的是一种参数估计的迭代算法,本发明实施例的EM算法,具体包括如下步骤:The EM algorithm is an iterative algorithm for parameter estimation, and the EM algorithm in the embodiment of the present invention specifically includes the following steps:

(1)E步骤(1) E step

第一步是通过对Q方程的估计来完成的,Q方程的数学表达形式如式(3)所示:The first step is done by estimating the Q equation. The mathematical expression of the Q equation is shown in equation (3):

Q(μ,∑,π,μ222)=Eγ[In p(y,γ/μ,Σ,π)/Y,μ222] (3)Q(μ,Σ,π,μ 222 )=E γ [In p(y,γ/μ,Σ,π)/Y,μ 222 ] (3)

其中,Y表示输入的图片,μ和Σ分别表示高斯分布的均值和方差,π表示图片中不同像素点类型的概率,

Figure BDA0002387409430000101
Among them, Y represents the input image, μ and Σ represent the mean and variance of the Gaussian distribution, respectively, π represents the probability of different pixel types in the image,
Figure BDA0002387409430000101

在迭代算法中,第一次Q方程的更新需要自动设置迭代初始值。第一次之后的Q方程的迭代值是通过M步骤得到的结果计算的。In the iterative algorithm, the first update of the Q equation needs to automatically set the initial value of the iteration. The iterative values of the Q equation after the first time are calculated from the results obtained in the M steps.

(2)M步骤(2) M step

M步骤是参数的估计步骤,三个参数估计公式紧凑形式的数学表达式如式(4)所示:The M step is the parameter estimation step, and the mathematical expression of the compact form of the three parameter estimation formulas is shown in equation (4):

μi+1i+1i+1=arg max Q(μ,∑,π,μiii) (4)μ i+1i+1i+1 =arg max Q(μ,Σ,π,μ iii ) (4)

其中,μ和Σ分别表示高斯分布的均值和方差,π表示图片中不同像素点类型的概率,上角标i代表第i次迭代的结果。Among them, μ and Σ represent the mean and variance of the Gaussian distribution, respectively, π represents the probability of different pixel types in the picture, and the superscript i represents the result of the ith iteration.

式(4)中三个参数估计公式的具体表达式和建模的具体形式相关,三个参数估计公式的数学表达式如式(5)至式(7)所示:The specific expressions of the three parameter estimation formulas in formula (4) are related to the specific forms of modeling, and the mathematical expressions of the three parameter estimation formulas are shown in formulas (5) to (7):

Figure BDA0002387409430000102
Figure BDA0002387409430000102

Figure BDA0002387409430000103
Figure BDA0002387409430000103

Figure BDA0002387409430000104
Figure BDA0002387409430000104

其中,μk和Σk分别表示高斯分布的均值和方差,πk表示图片中不同像素点类型的概率,上角标i表示第i次迭代的结果。T表示像素点数量,N(.)表示高斯分布,y表示像素点,K表示模型数,

Figure BDA0002387409430000105
Among them, μ k and Σ k represent the mean and variance of the Gaussian distribution, respectively, π k represents the probability of different pixel types in the picture, and the superscript i represents the result of the ith iteration. T represents the number of pixels, N(.) represents Gaussian distribution, y represents pixels, K represents the number of models,
Figure BDA0002387409430000105

E步骤和M步骤是EM算法的主要步骤,EM算法在步骤(1)和步骤(2)之间迭代,迭代停止的判断公式如式(8)所示:The E step and the M step are the main steps of the EM algorithm. The EM algorithm iterates between steps (1) and (2), and the judgment formula for iterative stop is shown in formula (8):

Figure BDA0002387409430000106
Figure BDA0002387409430000106

其中,μk和Σk分别表示高斯分布的均值和方差,N(.)代表高斯分布,x代表像素点,πk表示图片中不同像素点类型的概率,K代表模型数。当p(x/π,μ,Σ)到达一定的数值后停止迭代过程。Among them, μ k and Σ k represent the mean and variance of the Gaussian distribution, respectively, N(.) represents the Gaussian distribution, x represents the pixel point, π k represents the probability of different pixel types in the image, and K represents the number of models. Stop the iterative process when p(x/π, μ, Σ) reaches a certain value.

本发明实施例的一种产品缺陷检测方法,通过高斯混合模型对输入的待检测产品图像的像素值进行模拟,通过不同的单高斯模型来确定每个像素点的类型,从而对产品图像进行检测,得到第二图像分割结果。In a product defect detection method according to an embodiment of the present invention, a Gaussian mixture model is used to simulate the pixel value of an input image of a product to be detected, and different single Gaussian models are used to determine the type of each pixel, so as to detect the product image. , to obtain the second image segmentation result.

S1300.采用后处理算法对第一图像分割结果和第二图像分割结果进行处理,得到检测结果。S1300. Use a post-processing algorithm to process the first image segmentation result and the second image segmentation result to obtain a detection result.

在本发明实施例的另一些具体实施例中,参照图4,示出了本发明实施例中一种产品缺陷检测方法的另一具体实施例的流程示意图。如图4所示,本发明实施例的一种产品缺陷检测方法,采用后处理算法对第一图像分割结果和第二图像分割结果进行处理,得到检测结果,具体步骤包括:In other specific embodiments of the embodiments of the present invention, referring to FIG. 4 , a schematic flowchart of another specific embodiment of a product defect detection method in the embodiments of the present invention is shown. As shown in FIG. 4 , in a product defect detection method according to an embodiment of the present invention, a post-processing algorithm is used to process the first image segmentation result and the second image segmentation result to obtain the detection result. The specific steps include:

S1310.对第一图像分割结果和第二图像分割结果进行处理,得到第三图像分割结果。S1310. Process the first image segmentation result and the second image segmentation result to obtain a third image segmentation result.

对第一图像分割结果和第二图像分割结果进行处理,首先,将第一图像分割结果转换成第一矩阵,将第二图像分割结果转换成第二矩阵。然后,将第一矩阵和第二矩阵的对应元素相卷积,得到第三矩阵。最后,按照之前的矩阵转换规则,对第三矩阵进行逆转换,就能得到第三图像分割结果。第三图像分割结果实质上是第一图像分割结果和第二图像分割结果的交集。The first image segmentation result and the second image segmentation result are processed. First, the first image segmentation result is converted into a first matrix, and the second image segmentation result is converted into a second matrix. Then, the corresponding elements of the first matrix and the second matrix are convolved to obtain a third matrix. Finally, according to the previous matrix transformation rule, the third matrix is inversely transformed, and the third image segmentation result can be obtained. The third image segmentation result is essentially the intersection of the first image segmentation result and the second image segmentation result.

在本发明实施例的矩阵转换规则中,缺陷分割区域的像素值取1,正常区域的像素值取0。通过将第一矩阵和第二矩阵的对应元素相卷积,第一图像分割结果和第二图像分割结果都分割出来的缺陷区域将会设为1,而两者其一分割出来的缺陷区域和非缺陷区域将会设为0。In the matrix conversion rule of the embodiment of the present invention, the pixel value of the defect segmentation area is 1, and the pixel value of the normal area is 0. By convolving the corresponding elements of the first matrix and the second matrix, the defect area segmented by both the first image segmentation result and the second image segmentation result will be set to 1, and the defect area segmented by either of the two will be set to 1. Non-defective areas will be set to 0.

S1320.采用形态学重建法对第三图像分割结果进行漏洞边缘检测和漏洞修补,得到检测结果。S1320. Use the morphological reconstruction method to detect and repair the vulnerability edge of the third image segmentation result, and obtain the detection result.

漏洞产生的原因是采集图像时的光照令EM算法无法正确的分类。采用形态学重建法对第三图像分割结果进行漏洞边缘检测和漏洞修补,就是为了排除因光照影响导致算法误判的因素。The reason for the vulnerability is that the illumination at the time of capturing the image prevents the EM algorithm from classifying correctly. The morphological reconstruction method is used to detect and repair the vulnerability edge of the third image segmentation result in order to eliminate the factors that cause the algorithm to misjudge due to the influence of illumination.

本发明实施例的形态学重建法具体包括以下两个步骤:The morphological reconstruction method in the embodiment of the present invention specifically includes the following two steps:

(1)漏洞边缘检测步骤(1) Vulnerability edge detection steps

对图像分割结果进行矩阵转换后,对于一个像素点,如果周围的上下左右4个像素点中存在两种不同的像素值,那么说明这个像素点属于边缘,并将此像素点的位置进行保存。将坐标原点(1,1)定义为图像左上角的像素点,利用边缘检测算法将图像中所有像素值为1的像素点遍历后,得到整张图像中所有存在的边缘点。After performing matrix transformation on the image segmentation result, for a pixel, if there are two different pixel values in the surrounding 4 pixels, it means that this pixel belongs to the edge, and the position of this pixel is saved. The origin of the coordinates (1,1) is defined as the pixel point in the upper left corner of the image, and all the pixel points with the pixel value of 1 in the image are traversed by the edge detection algorithm, and all the existing edge points in the entire image are obtained.

(2)漏洞修补步骤(2) Vulnerability patching steps

利用漏洞边缘区域连接起来是一个闭合包络线的特点,首先,在图像上随机选取一个点,记录该点的横坐标,并在边缘点的集合中寻找与其横坐标相同的点。然后,选择横向方向,在这两个边缘点的中间的所有像素点都属于漏洞,这一步骤可以视为漏洞区域的搜索。将中间的漏洞像素点的像素值从0设为1,从而完成一部分漏洞的修补。接下来重新选取一个边缘点重复修补步骤,直到漏洞修补完成。Using the characteristics of a closed envelope to connect the edge areas of the vulnerability, first, randomly select a point on the image, record the abscissa of the point, and find the point with the same abscissa in the set of edge points. Then, select the horizontal direction, all the pixels in the middle of these two edge points belong to the vulnerability, this step can be regarded as the search of the vulnerability area. Set the pixel value of the middle vulnerability pixel from 0 to 1, so as to complete the patching of part of the vulnerability. Next, re-select an edge point and repeat the patching steps until the vulnerability patching is completed.

本发明实施例的一种产品缺陷检测方法,通过漏洞边缘检测和漏洞修补,能够克服光照令EM算法难以正确分类的问题,从而提高了EM算法检测的准确性。A product defect detection method according to an embodiment of the present invention can overcome the problem that illumination makes it difficult for the EM algorithm to classify correctly through vulnerability edge detection and vulnerability repair, thereby improving the detection accuracy of the EM algorithm.

实施例2Example 2

参照图5,示出了本发明实施例中一种产品缺陷检测装置的一具体实施例的模块框图。如图5所示,本发明实施例的一种产品缺陷检测装置,包括图像获取模块,用于获取待检测产品图像;第一图像分割模块,用于采用Otsu算法对待检测产品图像进行处理,得到第一图像分割结果;第二图像分割模块,用于采用高斯混合模型算法对待检测产品图像进行处理,得到第二图像分割结果;后处理模块,用于采用后处理算法对第一图像分割结果和第二图像分割结果进行处理,得到检测结果。Referring to FIG. 5 , a block diagram of a module of a specific embodiment of a product defect detection apparatus in an embodiment of the present invention is shown. As shown in FIG. 5 , a product defect detection device according to an embodiment of the present invention includes an image acquisition module, which is used to acquire an image of the product to be detected; a first image segmentation module is used to process the image of the product to be detected by using the Otsu algorithm to obtain The first image segmentation result; the second image segmentation module is used to process the image of the product to be detected by using the Gaussian mixture model algorithm to obtain the second image segmentation result; the post-processing module is used to use the post-processing algorithm to process the first image segmentation result and The second image segmentation result is processed to obtain a detection result.

本发明实施例的一种产品缺陷检测装置,第一图像分割模块分割结果稳定、快速,第二图像分割模块分割结果精准、计算速度较快且不需要大量的训练样本,后处理模块对第一图像分割结果和第二图像分割结果进行处理,既能可靠地检测产品图像,又能大幅度地提高检测的速度。In a product defect detection device according to an embodiment of the present invention, the first image segmentation module has stable and fast segmentation results, the second image segmentation module has accurate segmentation results, fast calculation speed, and does not require a large number of training samples, and the post-processing module is responsible for the first image segmentation module. The image segmentation result and the second image segmentation result are processed, which can not only detect the product image reliably, but also greatly improve the detection speed.

在本发明实施例的另一些具体实施例中,后处理算法包括漏洞边缘检测和漏洞修补。通过漏洞边缘检测和漏洞修补,能够克服光照令EM算法难以正确分类的问题,从而提高了EM算法检测的准确性。In other specific embodiments of the embodiments of the present invention, the post-processing algorithm includes vulnerability edge detection and vulnerability repair. Through vulnerability edge detection and vulnerability repair, the problem that illumination makes it difficult for the EM algorithm to classify correctly can be overcome, thereby improving the detection accuracy of the EM algorithm.

本发明实施例的一种产品缺陷检测装置可以运行于桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备中。一种产品缺陷检测装置,可运行的装置可包括,但不仅限于,处理器、存储器。本领域技术人员可以理解,所述例子仅仅是一种产品缺陷检测装置的示例,并不构成对一种产品缺陷检测装置的限定,可以包括比例子更多或更少的部件,或者组合某些部件,或者不同的部件,例如一种产品缺陷检测装置还可以包括输入输出设备、网络接入设备、总线等。A product defect detection apparatus according to an embodiment of the present invention can run in computing devices such as a desktop computer, a notebook computer, a palmtop computer, and a cloud server. A product defect detection device, the operable device may include, but not limited to, a processor and a memory. Those skilled in the art can understand that the example is only an example of a product defect detection device, and does not constitute a limitation to a product defect detection device, which may include more or less components, or a combination of some Components, or different components, such as a product defect detection device, may also include input and output devices, network access devices, buses, and the like.

实施例3Example 3

本发明实施例提供了一种产品缺陷检测设备,基于实施例1,包括至少一个处理器,以及,与至少一个处理器通信连接的存储器;其中,存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够执行本发明的一些实施例的一种产品缺陷检测方法。An embodiment of the present invention provides a product defect detection device, based on Embodiment 1, comprising at least one processor, and a memory connected in communication with the at least one processor; wherein, the memory stores instructions executable by the at least one processor , the instructions are executed by at least one processor to enable the at least one processor to execute a product defect detection method according to some embodiments of the present invention.

本发明实施例的一种产品缺陷检测设备,能够大幅度地提高检测速度,适用于不同类型产品的表面缺陷检测,还能够减小不同光源、检测件摆放角度和阴影情况等外界因素对检测结果的影响,实现对生产线产品缺陷的准确检测。The product defect detection device according to the embodiment of the present invention can greatly improve the detection speed, is suitable for the detection of surface defects of different types of products, and can also reduce the influence of external factors such as different light sources, placement angles of detection parts, and shadows on detection. The impact of the results, to achieve accurate detection of product defects in the production line.

本发明实施例的一种产品缺陷检测设备,处理器可以是中央处理单元(CentralProcessing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital SignalProcessor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等,处理器是一种产品缺陷检测方法的可运行装置的控制中心,利用各种接口和线路连接整个一种产品缺陷检测方法的可运行装置的各个部分。In a product defect detection device according to an embodiment of the present invention, the processor may be a central processing unit (Central Processing Unit, CPU), or other general-purpose processors, digital signal processors (Digital Signal Processors, DSP), application-specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. Parts of an operational device for a defect detection method.

存储器可用于存储计算机程序和/或模块,处理器通过运行或执行存储在所述存储器内的计算机程序和/或模块,以及调用存储在存储器内的数据,实现一种产品缺陷检测方法的可运行装置的各种功能。存储器可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据手机的使用所创建的数据(比如音频数据、电话本等)等。此外,存储器可以包括高速随机存取存储器,还可以包括非易失性存储器,例如硬盘、内存、插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(SecureDigital,SD)卡,闪存卡(Flash Card)、至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。The memory can be used to store computer programs and/or modules, and the processor can implement a product defect detection method by running or executing the computer programs and/or modules stored in the memory, and calling the data stored in the memory. various functions of the device. The memory can mainly include a stored program area and a stored data area, wherein the stored program area can store an operating system, an application program (such as a sound playback function, an image playback function, etc.) required for at least one function; data (such as audio data, phone book, etc.) In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, internal memory, plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.

实施例4Example 4

本发明实施例提供了一种计算机可读存储介质,基于实施例1,计算机可读存储介质存储有计算机可执行指令,计算机可执行指令用于使计算机执行本发明的一些实施例的一种产品缺陷检测方法。An embodiment of the present invention provides a computer-readable storage medium. Based on Embodiment 1, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to cause a computer to execute a product of some embodiments of the present invention. Defect detection method.

本发明实施例的一种计算机可读存储介质,能够大幅度地提高检测速度,适用于不同类型产品的表面缺陷检测,还能够减小不同光源、检测件摆放角度和阴影情况等外界因素对检测结果的影响,实现对生产线产品缺陷的准确检测。A computer-readable storage medium according to the embodiment of the present invention can greatly improve the detection speed, is suitable for surface defect detection of different types of products, and can also reduce the impact of external factors such as different light sources, detection parts placement angles, and shadow conditions. The influence of the detection results, to achieve accurate detection of product defects in the production line.

上面结合附图对本发明实施例作了详细说明,但是本发明不限于上述实施例,在所述技术领域普通技术人员所具备的知识范围内,还可以在不脱离本发明宗旨的前提下作出各种变化。此外,在不冲突的情况下,本发明的实施例及实施例中的特征可以相互组合。The embodiments of the present invention have been described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned embodiments. Within the scope of knowledge possessed by those of ordinary skill in the technical field, various modifications can be made without departing from the purpose of the present invention. kind of change. Furthermore, the embodiments of the present invention and features in the embodiments may be combined with each other without conflict.

Claims (10)

1.一种产品缺陷检测方法,其特征在于,包括:1. a product defect detection method, is characterized in that, comprises: 获取待检测产品图像;Obtain the image of the product to be detected; 采用Otsu算法对所述待检测产品图像进行处理,得到第一图像分割结果;The Otsu algorithm is used to process the image of the product to be detected to obtain a first image segmentation result; 采用高斯混合模型算法对所述待检测产品图像进行处理,得到第二图像分割结果;The Gaussian mixture model algorithm is used to process the image of the product to be detected to obtain a second image segmentation result; 采用后处理算法对所述第一图像分割结果和所述第二图像分割结果进行处理,得到检测结果。A post-processing algorithm is used to process the first image segmentation result and the second image segmentation result to obtain a detection result. 2.根据权利要求1所述的一种产品缺陷检测方法,其特征在于,所述采用Otsu算法对所述待检测产品图像进行处理,得到第一图像分割结果,包括:2. A product defect detection method according to claim 1, wherein the Otsu algorithm is used to process the image of the product to be detected to obtain a first image segmentation result, comprising: 对所述待检测产品图像进行灰度处理,得到灰度图;Perform grayscale processing on the image of the product to be detected to obtain a grayscale image; 对所述灰度图进行伽马校正,得到伽马校正图;performing gamma correction on the grayscale image to obtain a gamma correction image; 对所述伽马校正图进行Otsu分割,得到Otsu分割结果;Otsu segmentation is performed on the gamma correction map to obtain an Otsu segmentation result; 对所述Otsu分割结果进行形态学处理,得到形态学矫正结果;Morphological processing is performed on the Otsu segmentation result to obtain a morphological correction result; 对所述形态学矫正结果进行中值滤波,得到所述第一图像分割结果。Perform median filtering on the morphological correction result to obtain the first image segmentation result. 3.根据权利要求2所述的一种产品缺陷检测方法,其特征在于,所述对所述Otsu分割结果进行形态学处理,得到形态学矫正结果,包括:3. a kind of product defect detection method according to claim 2 is characterized in that, described carrying out morphological processing to described Otsu segmentation result, obtains morphological correction result, comprising: 采用低通滤波法对所述Otsu分割结果进行灰度平滑和边缘平滑,得到所述形态学矫正结果。The low-pass filtering method is used to perform grayscale smoothing and edge smoothing on the Otsu segmentation result to obtain the morphological correction result. 4.根据权利要求1至3任一项所述的一种产品缺陷检测方法,其特征在于,所述采用高斯混合模型算法对所述待检测产品图像进行处理,得到第二图像分割结果,包括:4. A product defect detection method according to any one of claims 1 to 3, wherein the Gaussian mixture model algorithm is used to process the image of the product to be detected to obtain a second image segmentation result, comprising: : 对所述待检测产品图像进行HSV空间颜色提取,得到HSV彩色图;Perform HSV space color extraction on the image of the product to be detected to obtain an HSV color map; 对所述HSV彩色图进行EM算法分割,得到所述第二图像分割结果。EM algorithm segmentation is performed on the HSV color image to obtain the second image segmentation result. 5.根据权利要求4所述的一种产品缺陷检测方法,其特征在于,所述对所述HSV彩色图进行EM算法分割,得到所述第二图像分割结果,包括:5. A product defect detection method according to claim 4, characterized in that, performing EM algorithm segmentation on the HSV color image to obtain the second image segmentation result, comprising: 建立高斯混合模型;Build a Gaussian mixture model; 采用所述高斯混合模型对所述HSV彩色图进行处理,得到所述高斯混合模型的模型数;Using the Gaussian mixture model to process the HSV color map to obtain the model number of the Gaussian mixture model; 根据所述高斯混合模型的模型数,得到所述高斯混合模型的优化模型;According to the number of models of the Gaussian mixture model, the optimization model of the Gaussian mixture model is obtained; 采用EM算法对所述优化模型进行参数估计,得到所述第二图像分割结果。The EM algorithm is used to estimate the parameters of the optimized model to obtain the second image segmentation result. 6.根据权利要求4所述的一种产品缺陷检测方法,其特征在于,所述采用后处理算法对所述第一图像分割结果和所述第二图像分割结果进行处理,得到检测结果,包括:6 . The method for detecting product defects according to claim 4 , wherein the post-processing algorithm is used to process the first image segmentation result and the second image segmentation result to obtain a detection result, comprising: 6 . : 对所述第一图像分割结果和所述第二图像分割结果进行处理,得到第三图像分割结果;processing the first image segmentation result and the second image segmentation result to obtain a third image segmentation result; 采用形态学重建法对所述第三图像分割结果进行漏洞边缘检测和漏洞修补,得到所述检测结果。The morphological reconstruction method is used to perform edge detection and repair on the third image segmentation result to obtain the detection result. 7.一种产品缺陷检测装置,其特征在于,包括:7. A product defect detection device, characterized in that, comprising: 图像获取模块,用于获取待检测产品图像;The image acquisition module is used to acquire the image of the product to be detected; 第一图像分割模块,用于采用Otsu算法对所述待检测产品图像进行处理,得到第一图像分割结果;a first image segmentation module, used to process the image of the product to be detected by using the Otsu algorithm to obtain a first image segmentation result; 第二图像分割模块,用于采用高斯混合模型算法对所述待检测产品图像进行处理,得到第二图像分割结果;A second image segmentation module, configured to process the image of the product to be detected by using a Gaussian mixture model algorithm to obtain a second image segmentation result; 后处理模块,用于采用后处理算法对所述第一图像分割结果和所述第二图像分割结果进行处理,得到检测结果。The post-processing module is configured to use a post-processing algorithm to process the first image segmentation result and the second image segmentation result to obtain a detection result. 8.根据权利要求7所述的一种产品缺陷检测装置,其特征在于,所述后处理算法包括漏洞边缘检测和漏洞修补。8 . The device for detecting product defects according to claim 7 , wherein the post-processing algorithm includes vulnerability edge detection and vulnerability repair. 9 . 9.一种产品缺陷检测设备,其特征在于,包括:9. A product defect detection device, characterized in that, comprising: 至少一个处理器,以及,at least one processor, and, 与至少一个所述处理器通信连接的存储器;其中,a memory communicatively coupled to at least one of the processors; wherein, 所述存储器存储有可被至少一个所述处理器执行的指令,所述指令被至少一个所述处理器执行,以使至少一个所述处理器能够执行如权利要求1至6任一项所述的产品缺陷检测方法。The memory stores instructions executable by at least one of the processors, the instructions being executed by the at least one of the processors to enable the at least one of the processors to perform the execution of any one of claims 1 to 6 product defect detection method. 10.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机可执行指令,所述计算机可执行指令用于使计算机执行如权利要求1至6任一项所述的产品缺陷检测方法。10. A computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to cause a computer to execute the method according to any one of claims 1 to 6. product defect detection method.
CN202010102720.4A 2020-02-19 2020-02-19 Product defect detection method, device, equipment and storage medium Active CN111325728B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010102720.4A CN111325728B (en) 2020-02-19 2020-02-19 Product defect detection method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010102720.4A CN111325728B (en) 2020-02-19 2020-02-19 Product defect detection method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111325728A true CN111325728A (en) 2020-06-23
CN111325728B CN111325728B (en) 2023-05-30

Family

ID=71167337

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010102720.4A Active CN111325728B (en) 2020-02-19 2020-02-19 Product defect detection method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111325728B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113516619A (en) * 2021-04-09 2021-10-19 重庆大学 Product surface flaw identification method based on image processing technology
CN113592787A (en) * 2021-07-13 2021-11-02 苏州汇川控制技术有限公司 Light emitting component detection method, light emitting component detection device, terminal equipment and storage medium
CN114494210A (en) * 2022-01-28 2022-05-13 江苏豪尚新材料科技有限公司 Plastic film production defect detection method and system based on image processing
CN115529475A (en) * 2021-12-29 2022-12-27 北京智美互联科技有限公司 Method and system for detecting video flow content and controlling wind
CN117094974A (en) * 2023-08-23 2023-11-21 河钢数字技术股份有限公司 Image-based defect detection method and device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170154238A1 (en) * 2015-11-26 2017-06-01 Le Holdings (Beijing) Co., Ltd. Method and electronic device for skin color detection
WO2017092431A1 (en) * 2015-12-01 2017-06-08 乐视控股(北京)有限公司 Human hand detection method and device based on skin colour
CN110751623A (en) * 2019-09-06 2020-02-04 深圳新视智科技术有限公司 Joint feature-based defect detection method, device, equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170154238A1 (en) * 2015-11-26 2017-06-01 Le Holdings (Beijing) Co., Ltd. Method and electronic device for skin color detection
WO2017092431A1 (en) * 2015-12-01 2017-06-08 乐视控股(北京)有限公司 Human hand detection method and device based on skin colour
CN110751623A (en) * 2019-09-06 2020-02-04 深圳新视智科技术有限公司 Joint feature-based defect detection method, device, equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
徐海燕;郭京;: "基于HMT模型的带钢表面缺陷检测研究" *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113516619A (en) * 2021-04-09 2021-10-19 重庆大学 Product surface flaw identification method based on image processing technology
CN113592787A (en) * 2021-07-13 2021-11-02 苏州汇川控制技术有限公司 Light emitting component detection method, light emitting component detection device, terminal equipment and storage medium
CN115529475A (en) * 2021-12-29 2022-12-27 北京智美互联科技有限公司 Method and system for detecting video flow content and controlling wind
CN114494210A (en) * 2022-01-28 2022-05-13 江苏豪尚新材料科技有限公司 Plastic film production defect detection method and system based on image processing
CN117094974A (en) * 2023-08-23 2023-11-21 河钢数字技术股份有限公司 Image-based defect detection method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN111325728B (en) 2023-05-30

Similar Documents

Publication Publication Date Title
CN111325728B (en) Product defect detection method, device, equipment and storage medium
CN110930390B (en) Chip pin missing detection method based on semi-supervised deep learning
CN109872303B (en) Surface defect visual inspection method, device and electronic equipment
CN108305260B (en) Method, device and device for detecting corner points in an image
CN111915704A (en) Apple hierarchical identification method based on deep learning
CN109658381A (en) A kind of copper face defect inspection method of the flexible IC package substrate based on super-pixel
CN116664565A (en) Hidden crack detection method and system for photovoltaic solar cell
TWI765442B (en) Method for defect level determination and computer readable storage medium thereof
CN111695373B (en) Zebra stripes positioning method, system, medium and equipment
CN114298985B (en) Defect detection method, device, equipment and storage medium
CN108764328A (en) The recognition methods of Terahertz image dangerous material, device, equipment and readable storage medium storing program for executing
CN110570442A (en) Contour detection method under complex background, terminal device and storage medium
CN110909772B (en) High-precision real-time multi-scale dial pointer detection method and system
CN110807404A (en) Form line detection method, device, terminal and storage medium based on deep learning
CN117557565B (en) Detection method and device for lithium battery pole piece
CN114445318A (en) A defect detection method, device, electronic device and storage medium
CN111986126A (en) A multi-target detection method based on improved VGG16 network
CN117094975A (en) Method and device for detecting surface defects of steel and electronic equipment
CN117292337A (en) Remote sensing image target detection method
CN111553927B (en) Checkerboard corner detection method, detection system, computer device and storage medium
CN119540205A (en) Method and system for inspecting residual film on IC substrate
TWI498830B (en) A method and system for license plate recognition under non-uniform illumination
CN118823427A (en) A manhole cover hidden danger detection system based on YOLOV8 improved algorithm
CN115719326A (en) PCB defect detection method and device
CN118822940A (en) Defect detection methods, devices, media, products and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant