Movatterモバイル変換


[0]ホーム

URL:


CN111474184B - AOI character defect detection method and device based on industrial machine vision - Google Patents

AOI character defect detection method and device based on industrial machine vision
Download PDF

Info

Publication number
CN111474184B
CN111474184BCN202010306399.1ACN202010306399ACN111474184BCN 111474184 BCN111474184 BCN 111474184BCN 202010306399 ACN202010306399 ACN 202010306399ACN 111474184 BCN111474184 BCN 111474184B
Authority
CN
China
Prior art keywords
image
character
detected
template
matching
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.)
Active
Application number
CN202010306399.1A
Other languages
Chinese (zh)
Other versions
CN111474184A (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.)
Hohai University HHU
Original Assignee
Hohai University HHU
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 Hohai University HHUfiledCriticalHohai University HHU
Priority to CN202010306399.1ApriorityCriticalpatent/CN111474184B/en
Publication of CN111474184ApublicationCriticalpatent/CN111474184A/en
Application grantedgrantedCritical
Publication of CN111474184BpublicationCriticalpatent/CN111474184B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

Translated fromChinese

本发明公开一种可基于工业机器视觉实现的AOI字符缺陷检测方法,包括:获取待检测图像;对待检测图像进行预处理,得到位置已校正的、含字符的感兴趣区域图像;对待检测图像的感兴趣区域图像进行分离,得到字符区域图像;将待检测图像的字符区域图像与预先创建的基准图像模板进行模板匹配,得到模板匹配结果;根据模板匹配结果判断待检测图像是否存在字符缺陷;输出字符缺陷判断结果。本发明利用模板匹配可实现在低像素灰度图情况下ROI区域缺陷的检测,提高了检测效率和准确率,降低检测人工成本。

Figure 202010306399

The invention discloses an AOI character defect detection method that can be realized based on industrial machine vision, comprising: acquiring an image to be detected; preprocessing the image to be detected to obtain a position-corrected image of a region of interest containing characters; The image of the region of interest is separated to obtain a character region image; the character region image of the image to be detected is template matched with a pre-created reference image template to obtain a template matching result; according to the template matching result, it is judged whether the image to be detected has character defects; output Character defect judgment result. The invention utilizes template matching to realize the detection of ROI region defects in the case of low-pixel grayscale images, improves detection efficiency and accuracy, and reduces detection labor costs.

Figure 202010306399

Description

Translated fromChinese
基于工业机器视觉的AOI字符缺陷检测方法和装置AOI character defect detection method and device based on industrial machine vision

技术领域technical field

本发明涉及图像处理及机器视觉技术领域,特别是一种基于工业机器视觉的AOI字符缺陷检测方法和装置。The invention relates to the technical field of image processing and machine vision, in particular to an AOI character defect detection method and device based on industrial machine vision.

背景技术Background technique

机器视觉是用机器代替人眼来做测量和判断,具有易于信息集成的特点,是实现计算机集成制造的基础技术。机器视觉系统最基本的特点就是提高生产的灵活性和自动化程度。在一些不适于人工作业的危险工作环境或者人工视觉难以满足要求的场合,常用机器视觉来替代人工视觉。同时,在大批量重复性工业生产过程中,用机器视觉检测方法可以大大提高生产的效率和自动化程度。Machine vision is to use machines instead of human eyes for measurement and judgment. It has the characteristics of easy information integration and is the basic technology for realizing computer integrated manufacturing. The most basic feature of the machine vision system is to improve the flexibility and automation of production. In some dangerous working environments that are not suitable for manual operation or occasions where artificial vision is difficult to meet the requirements, machine vision is often used to replace artificial vision. At the same time, in the process of large-scale repetitive industrial production, the use of machine vision inspection methods can greatly improve the efficiency and automation of production.

AOI(Automated Optical Inspection,自动光学检测),是基于光学原理来对焊接生产中遇到的常见缺陷进行的检测。现如今,在工业生产中,产品上一般需要印刷上一定的字符信息,而在机器操作的环境下印刷时可能会出现缺陷,会降低产品在质检时的合格率,影响生产的进度。传统技术采用人工检查产品上印刷的字符信息,速度较慢、劳动强度较大,耗时也很长。采用机器视觉的检测方法又受限于对所拍摄的照片质量要求,而往往识别精度较低。AOI (Automated Optical Inspection, Automatic Optical Inspection) is based on the optical principle to detect common defects encountered in welding production. Nowadays, in industrial production, certain character information generally needs to be printed on products, but defects may occur during printing in the environment of machine operation, which will reduce the pass rate of products during quality inspection and affect the progress of production. The traditional technology uses manual inspection of the character information printed on the product, which is slow, labor-intensive, and time-consuming. The detection method using machine vision is also limited by the quality requirements of the photos taken, and the recognition accuracy is often low.

发明内容SUMMARY OF THE INVENTION

本发明的目的是,提供一种基于工业机器视觉的AOI字符缺陷检测方法和装置,通过将图像处理与机器视觉相结合,利用AOI字符缺陷检测技术识别产品外观上的字符缺陷,降低对相机镜头的精度要求,提高识别结果准确度和效率皆较高。The purpose of the present invention is to provide an AOI character defect detection method and device based on industrial machine vision. By combining image processing with machine vision, the AOI character defect detection technology is used to identify the character defects on the appearance of the product, reducing the need for camera lenses. The accuracy and efficiency of the recognition results are improved.

本发明采取的技术方案如下。The technical solution adopted in the present invention is as follows.

一方面,本发明提供一种AOI字符缺陷检测方法,包括:On the one hand, the present invention provides an AOI character defect detection method, comprising:

获取待检测图像;Obtain the image to be detected;

对待检测图像进行预处理,得到位置已校正的、含字符的感兴趣区域图像;Preprocess the image to be detected to obtain a region-of-interest image that has been corrected and contains characters;

对待检测图像的感兴趣区域图像进行分离,得到字符区域图像;The image of the region of interest of the image to be detected is separated to obtain the image of the character region;

将待检测图像的字符区域图像与预先创建的基准图像模板进行模板匹配,得到模板匹配结果;Perform template matching between the character area image of the image to be detected and the pre-created reference image template to obtain a template matching result;

根据模板匹配结果判断待检测图像是否存在字符缺陷;Determine whether the image to be detected has character defects according to the template matching result;

输出字符缺陷判断结果。Output character defect judgment results.

本发明方法中,所述预先创建的基准图像模板利用多个含待检测字符的字符图像样本训练得到,基准图像的图像模板创建及训练过程可采用现有技术。模板匹配可得到的参数包括表征是否可以在待检测图像中找到匹配模型字符的参数值以及字符缺陷个数,根据字符缺陷个数即可判断是否存在字符缺陷。In the method of the present invention, the pre-created reference image template is obtained by training a plurality of character image samples containing characters to be detected, and the image template creation and training process of the reference image can adopt the prior art. The parameters that can be obtained by template matching include a parameter value indicating whether a matching model character can be found in the image to be inspected and the number of character defects. According to the number of character defects, it can be judged whether there is a character defect.

可选的,模板匹配包括:计算匹配分数Score,若Score=0,则待检测图像中不存在基准图像中的字符,若Score≠0,则待检测图像中能够找到基准图像中的字符;Optionally, the template matching includes: calculating the matching score Score, if Score=0, the character in the reference image does not exist in the image to be detected, and if Score≠0, the character in the reference image can be found in the image to be detected;

响应于Score≠0,比较待检测图像的字符区域与基准图像的字符区域,得到字符缺陷个数NumError并输出;In response to Score≠0, compare the character area of the image to be detected and the character area of the reference image, obtain the number of character defects NumError and output;

根据模板匹配结果判断待检测图像是否存在字符缺陷为:若NumErro>0,则待检测图像存在字符缺陷。反之可预判为待检测图像不存在字符缺陷。匹配分数Score是一个0到1之间的数,是模板在搜索图像中可见比例的近似测量。According to the template matching result, it is determined whether the image to be detected has character defects as follows: if NumErro>0, the image to be detected has character defects. On the contrary, it can be predicted that there is no character defect in the image to be detected. The match score Score is a number between 0 and 1 that is an approximate measure of the proportion of the template visible in the search image.

可选的,方法还包括:Optionally, the method also includes:

响应于模板匹配结果中NumErro=0,计算待检测图像的字符区域图像中心坐标,将其与基准图像模板对应的基准图像中字符区域的中心坐标进行比较,计算待检测图像的偏移量;In response to NumErro=0 in the template matching result, calculate the image center coordinates of the character region of the image to be detected, compare it with the center coordinates of the character region in the reference image corresponding to the reference image template, and calculate the offset of the image to be detected;

将计算得到的偏移量与设定阈值进行比较,响应于偏移量大于设定阈值,则输出存在字符缺陷的相应结果信息,否则输出匹配成功的相应结果信息。也即,对于通过模板匹配但存在偏移较大的待检测图像,可进一步判断为存在字符缺陷。Comparing the calculated offset with the set threshold, in response to the offset being greater than the set threshold, output corresponding result information with character defects, otherwise output corresponding result information with successful matching. That is, for an image to be detected that has passed template matching but has a large offset, it can be further determined that there is a character defect.

可选的,偏移量的阈值设置为多个不同取值,每个阈值分别对应一个字符缺陷程度值,字符缺陷结果信息包括偏移程度标志位,标志位的值即为字符缺陷程度值;最终输出的偏移程度标志位的取值为,比偏移量小且与偏移量临近的阈值对应的字符缺陷程度值。Optionally, the threshold of the offset is set to a plurality of different values, each threshold corresponds to a character defect degree value, the character defect result information includes an offset degree flag bit, and the value of the flag bit is the character defect degree value; The value of the final output offset degree flag bit is a character defect degree value that is smaller than the offset and corresponding to a threshold value close to the offset.

可选的,对待检测图像的感兴趣区域图像采用Blob分析算法进行前景与背景的分离,得到字符区域图像。Optionally, the image of the region of interest of the image to be detected is separated from the foreground and the background using a Blob analysis algorithm to obtain a character region image.

可选的,方法还包括,对于待检测图像的感兴趣区域图像,利用Halcon算法中的根据特征值选择区域算子去除图像边框,然后利用缩减图像特定区域算子截取只含有字符的区域,进而对区域进行膨胀处理。Halcon算法为现有算法,膨胀处理可以确保字符完全包含在区域内。Optionally, the method further includes, for the image of the region of interest of the image to be detected, using the selection region operator according to the characteristic value in the Halcon algorithm to remove the image frame, and then using the reduced image specific region operator to intercept the region containing only characters, and then. Dilate the area. The Halcon algorithm is an existing algorithm, and the dilation process can ensure that the characters are completely contained within the region.

可选的,基准图像模板的创建包括:Optionally, the creation of the benchmark image template includes:

确定与待检测图像对应的基准图像以及已知字符缺陷的多个训练样本图像;Determine the reference image corresponding to the image to be detected and a plurality of training sample images of known character defects;

对基准图像确定mark位置点和标定点,并确定字符区域图像;Determine the mark position point and calibration point for the reference image, and determine the character area image;

基于基准图像的字符区域图像创建图像模板;Create an image template based on the character area image of the reference image;

对各训练样本图像按照待检测图像进行预处理和图像分离,得到字符区域图像;Perform preprocessing and image separation on each training sample image according to the image to be detected to obtain a character area image;

利用训练样本的字符区域图像对图像模板进行匹配训练,以调整模板的匹配过程参数,使得参数调整后的模板匹配的结果,符合相应训练样本图像的字符缺陷。mark位置点和标定点的确定用于对训练样本图像和待检测图像进行位置校正。The image template is matched and trained by using the character area image of the training sample to adjust the matching process parameters of the template, so that the template matching result after parameter adjustment is consistent with the character defect of the corresponding training sample image. The determination of the mark position point and the calibration point is used to perform position correction on the training sample image and the image to be detected.

本发明的模板训练采用监视模板算法来调整匹配过程参数,使得图像模板在实际的模板匹配中能够得到更准确的匹配结果。The template training of the present invention adopts the monitoring template algorithm to adjust the parameters of the matching process, so that the image template can obtain a more accurate matching result in the actual template matching.

模板匹配算法可参考现有技术,算法输入主要有:Image,ModelID,AngleStart,AngleExtent,ScaleMin,ScaleMax,MinScore,NumMatches,MaxOverlap,SubPixel,NumLevels,Greediness。其中,参数Image为基准图像,ModelID为模型名称。参数AngleStart和AngleExtent决定了要搜索模型的旋转范围。参数ScaleMin和ScaleMax确定要搜索模型的范围。参数MinScore决定了一个潜在的匹配至少必须被视为图像中模型的一个实例。参数SubPixel亚像素决定是否以亚像素精度提取实例。在搜索过程中使用的金字塔层次的数量是由数字层次NumLevel决定的。参数Greediness决定搜索应该如何“贪婪地”执行。算法的输出主要为:Row,Column,Angle,Scale,Score。其中,模型的发现实例的位置、旋转和比例按行、列、角度和比例返回。坐标的行和列与形状模型在搜索图像中的原点位置有关。每个找到的实例的分数在score中返回。分数是一个介于0和1之间的数字,这是一个关于模型在图像中可见程度的近似度量。例如,如果模型的一半被遮挡,则得分不能超过0.5。The template matching algorithm can refer to the prior art, and the algorithm input mainly includes: Image, ModelID, AngleStart, AngleExtent, ScaleMin, ScaleMax, MinScore, NumMatches, MaxOverlap, SubPixel, NumLevels, Greediness. Among them, the parameter Image is the reference image, and ModelID is the model name. The parameters AngleStart and AngleExtent determine the rotation range of the model to be searched. The parameters ScaleMin and ScaleMax determine the extent of the model to be searched. The parameter MinScore determines that a potential match must be considered at least one instance of the model in the image. The parameter SubPixel determines whether to extract instances with sub-pixel precision. The number of pyramid levels used in the search process is determined by the number level NumLevel. The parameter Greediness determines how "greedy" the search should be performed. The output of the algorithm is mainly: Row, Column, Angle, Scale, Score. where the position, rotation and scale of the discovered instance of the model are returned in row, column, angle and scale. The rows and columns of coordinates relate to the location of the origin of the shape model in the search image. The score for each found instance is returned in the score. The score is a number between 0 and 1, which is an approximate measure of how visible the model is in the image. For example, if half of the model is occluded, the score cannot exceed 0.5.

可选的,方法还包括,将基准图像和待检测图像分别存储于不同的文件夹中;Optionally, the method further includes storing the reference image and the image to be detected in different folders respectively;

对待检测图像进行预处理时,位置校正包括:When preprocessing the image to be inspected, position correction includes:

获取已存储的基准图像的mark位置点和标定点;Obtain the mark position and calibration point of the stored reference image;

获取已存储的待检测图像的mark位置点和标定点;Obtain the mark position and calibration point of the stored image to be detected;

通过仿射变换使得待检测图像与基准图像的mark位置点重合。Through affine transformation, the mark position points of the image to be detected and the reference image are made to coincide.

可选的,定义基准图像的mark位置点为M1(x1,y1)、M2(x2,y2),标定点为P(x,y),待检测图像的位置点为M′1(x′1,y′1)、M′2(x′2,y′2),标定点为P′(x′,y′);Optionally, define the mark position points of the reference image as M1 (x1 , y1 ) and M2 (x2 , y2 ), the calibration point is P(x, y), and the position point of the image to be detected is M ′1 (x′1 , y′1 ), M′2 (x′2 , y′2 ), the calibration point is P′ (x′, y′);

所述仿射变换为:The affine transformation is:

以M1点为基准,建立坐标系x0y0;以M′1点为基准,建立坐标系x0y0的平移坐标系xTyT和旋转坐标系xRyR;则在坐标系x0y0中,P点的相对坐标为P(xr,yr),P’点的相对坐标为P’(x′ry′r),其中xr=x-x1,yr=y-y1,x′r=x′-x′1,y′r=y′-y′1Take M1 point as the benchmark, establish the coordinate system x0 y0 ; take the M′1 point as the benchmark, establish the translation coordinate system xT yT and the rotation coordinate system xR yR of the coordinate system x0 y0; In the system x0 y0 , the relative coordinates of point P are P(xr , yr ), and the relative coordinates of point P' are P'(x'r y'r ), where xr =xx1 , yr = yy1 , x'r =x'-x'1 , y'r =y'-y'1;

P点经过两次坐标系变换得到P′点,其在x0y0坐标系中的相对坐标即为:The point P is transformed into the coordinate system twice to obtain the point P', and its relative coordinates in the x0 y0 coordinate system are:

Figure BDA0002455944070000041
Figure BDA0002455944070000041

其中,x0=x′1-x1,y0=y′1-y1Wherein, x0 =x'1 -x1 , y0 =y'1 -y1 ;

且:and:

Figure BDA0002455944070000042
Figure BDA0002455944070000042

由公式(1)、(2)联立可得P′的机器坐标为:From formulas (1) and (2), the machine coordinates of P' can be obtained as follows:

Figure BDA0002455944070000043
Figure BDA0002455944070000043

其中θ=θ01

Figure BDA0002455944070000044
where θ=θ0 −θ1 and
Figure BDA0002455944070000044

则坐标系旋转角度为:Then the rotation angle of the coordinate system is:

Figure BDA0002455944070000045
Figure BDA0002455944070000045

将公式(4)代入公式(3)即求得P′点的机器坐标,将待检测图像位置按照P′点的机器坐标进行校正。Substitute formula (4) into formula (3) to obtain the machine coordinates of point P', and correct the position of the image to be detected according to the machine coordinates of point P'.

以上即P点到P’点经过两次坐标系变换,即通过一次坐标平移变换将坐标系x0y0平移至坐标系xTyT,通过一次坐标旋转变换将坐标系xTyT旋转θ角至坐标系xRyR,为了计算方便,坐标变换的过程可以看成是先旋转变换再平移变换,即得到式(1)。The above means that the point P to point P' undergoes two coordinate system transformations, that is, the coordinate system x0 y0 is translated to the coordinate system xT yT through a coordinate translation transformation, and the coordinate system xT yT is rotated through a coordinate rotation transformation From the angle θ to the coordinate system xR yR , for the convenience of calculation, the process of coordinate transformation can be regarded as a first rotation transformation and then a translation transformation, that is, formula (1) is obtained.

可选的,模板匹配包括:Optionally, template matching includes:

以基准图像的字符区域图像作为搜索模板T,定义其像素为m×n,待检测图像字符区域图像作为被搜索图S,定义其像素为W×H个像素;The character area image of the reference image is used as the search template T, and its pixels are defined as m×n, and the character area image of the image to be detected is used as the searched image S, and its pixels are defined as W×H pixels;

将搜索模板T叠放在被搜索图S上移动搜索,搜索范围是:The search template T is superimposed on the searched graph S to move the search. The search range is:

1≤i≤W-m1≤i≤W-m

1≤j≤H-n1≤j≤H-n

每次移动多个像素元得到搜索模板覆盖被搜索图的区域为子图Sij,下标i、j为子图Sij左上角在被搜索图Sij上的坐标;Moving multiple pixels each time to obtain the area where the search template covers the searched image is the subimage Sij , and the subscripts i and j are the coordinates of the upper left corner of the sub image Sij on the searched image Sij ;

每次移动后分别计算搜索模板T与子图Sij的匹配程度;Calculate the matching degree of the search template T and the sub-graph Sij after each move;

选择匹配程度最优的子图,将其坐标及周围设定范围作为新的搜索范围;Select the subgraph with the best matching degree, and use its coordinates and surrounding setting range as the new search range;

在新的搜索范围内,每次移动单个像素元,并计算搜索模板T与子图Sij的匹配程度;In the new search range, move a single pixel each time, and calculate the matching degree between the search template T and the sub-image Sij;

在新的搜索范围内,选择匹配程度优的子图,进而计算匹配程度值和缺陷个数。In the new search range, select the subgraph with excellent matching degree, and then calculate the matching degree value and the number of defects.

可选的,每次移动后,搜索模板T与子图Sij的匹配程度根据以下公式中的其中一种确定:Optionally, after each move, the matching degree between the search template T and the subgraph Sij is determined according to one of the following formulas:

Figure BDA0002455944070000051
Figure BDA0002455944070000051

Figure BDA0002455944070000052
Figure BDA0002455944070000052

D(i,j)越小表征匹配程度越优。The smaller D(i, j) is, the better the matching degree is.

例如采用式(5)进行匹配程度计算,将式(5)展开得到:For example, formula (5) is used to calculate the degree of matching, and formula (5) is expanded to obtain:

Figure BDA0002455944070000053
Figure BDA0002455944070000053

从展开的公式中可以看出,中间第二项是一个常数,也就是只跟模板有关系,而第一个和第三个是和原图有关的,随着模板在原图上的移动,这两个值也在发生变化。当D(i,j)的值最小时,说明找到了目标。但是这样做的效率非常低下,每移动一个像素元都要进行一次运算,计算量非常大。It can be seen from the expanded formula that the second item in the middle is a constant, that is, it is only related to the template, while the first and third items are related to the original image. As the template moves on the original image, this Both values are also changing. When the value of D(i, j) is the smallest, it means that the target has been found. However, the efficiency of doing so is very low, and an operation is required for each pixel to be moved, and the amount of calculation is very large.

故本发明进行了算法优化:观察实际模板匹配运算结果可以发现,匹配点附近的匹配误差迅速下降,明显区别于其它位置。针对这一特点,本发明采用了粗精匹配结合的算法,可迅速锁定匹配点大致区域,大大降低整体匹配次数。具体实现方法:先跳动着隔几个点进行一次粗匹配,也就是一次移动多个像素元,从而大致框定匹配区域,然后在附近区域逐一检索获得最佳匹配点。运算量可减少到三分之一以下,且目标提取效果相当好。Therefore, the algorithm is optimized in the present invention: by observing the actual template matching operation results, it can be found that the matching error near the matching point decreases rapidly, which is obviously different from other positions. In view of this feature, the present invention adopts an algorithm of combining rough and fine matching, which can quickly lock the approximate area of the matching point and greatly reduce the overall matching times. The specific implementation method: First, perform a rough matching every few points, that is, move multiple pixels at a time, so as to roughly frame the matching area, and then retrieve the best matching points one by one in the nearby area. The amount of computation can be reduced to less than one third, and the target extraction effect is quite good.

有益效果beneficial effect

本发明利用模板匹配可实现低像素灰度图情况下ROI区域缺陷的问题,同时能够在少样本、低像素的条件下通过AOI检测快速筛选有缺陷的字符图像,检测效率和准确率皆能够得到提高,同时降低人工检测成本。本发明的应用可提高产品的质量以及整个生产流水线的生产效率,促进产品趋向数据化和规范化。The invention uses template matching to solve the problem of ROI area defects in the case of low-pixel grayscale images, and at the same time, it can quickly screen defective character images through AOI detection under the conditions of few samples and low pixels, and both detection efficiency and accuracy can be obtained. Improve and reduce the cost of manual inspection at the same time. The application of the present invention can improve the quality of products and the production efficiency of the entire production line, and promote the trend of dataization and standardization of products.

附图说明Description of drawings

图1为基准图像和待检测图像的预处理过程示意图;1 is a schematic diagram of the preprocessing process of the reference image and the image to be detected;

图2为待检测区域图像的示意图,其中左侧为摄像机或相机视角,右侧框选裁剪后的矩形ROI区域;Fig. 2 is a schematic diagram of an image of an area to be detected, wherein the left side is a camera or a camera angle of view, and the right side frame selects a cropped rectangular ROI area;

图3为本发明一种应用例中的检测结果示意图;3 is a schematic diagram of a detection result in an application example of the present invention;

图4和图5所示为本发明偏移量判断方式不同的两种实施方式的原理流程示意图。FIG. 4 and FIG. 5 are schematic flow charts of the principles of two embodiments of the present invention with different offset determination methods.

具体实施方式Detailed ways

以下结合附图和具体实施例进一步描述。The following is further described in conjunction with the accompanying drawings and specific embodiments.

本发明的发明构思为:针对待检测的字符,确定基准图像,对其进行位置标定、裁剪等处理,将其中的字符区域转换为感兴趣区域(Region of Interest,ROI),从而提高后续检测精度,然后基于基准图像的感兴趣区域进行模板创建以及训练。在检测时,首先获取待检测的图像,对图像进行缩放、旋转、平移等仿射变换,使得待检测图像与基准图像的标定点重合,进而利用模板匹配算法判断待检测图像的字符区域图像中是否存在基准图像中的字符,以及字符所存在的缺陷,进一步的,还可对待检测图像中的字符偏移量进行计算,并根据偏移量进一步确定字符缺陷。The inventive concept of the present invention is: for the characters to be detected, determine a reference image, perform position calibration, cropping and other processing on it, and convert the character region in it into a region of interest (ROI), thereby improving the subsequent detection accuracy , and then perform template creation and training based on the region of interest of the benchmark image. During detection, first acquire the image to be detected, perform affine transformations such as scaling, rotation, translation, etc. on the image, so that the calibration points of the image to be detected and the reference image coincide, and then use the template matching algorithm to determine the character area of the image to be detected. Whether there are characters in the reference image and the defects of the characters, further, the offset of the characters in the image to be detected can be calculated, and the character defects can be further determined according to the offset.

实施例1Example 1

基于前述发明构思,本实施例为一种AOI字符缺陷检测方法,包括:Based on the foregoing inventive concept, the present embodiment is an AOI character defect detection method, including:

获取待检测图像;Obtain the image to be detected;

对待检测图像进行预处理,得到位置已校正的、含字符的感兴趣区域图像;Preprocess the image to be detected to obtain a region-of-interest image that has been corrected and contains characters;

对待检测图像的感兴趣区域图像进行分离,得到字符区域图像;The image of the region of interest of the image to be detected is separated to obtain the image of the character region;

将待检测图像的字符区域图像与预先创建的基准图像模板进行模板匹配,得到模板匹配结果;Perform template matching between the character area image of the image to be detected and the pre-created reference image template to obtain a template matching result;

根据模板匹配结果判断待检测图像是否存在字符缺陷;Determine whether the image to be detected has character defects according to the template matching result;

输出字符缺陷判断结果。Output character defect judgment results.

本发明方法中,所述预先创建的基准图像模板利用多个含待检测字符的字符图像样本训练得到,基准图像的图像模板创建及训练过程可采用现有技术。模板匹配可得到的参数包括表征是否可以在待检测图像中找到匹配模型字符的参数值以及字符缺陷个数,根据字符缺陷个数即可判断是否存在字符缺陷。模板创建过程中通过将字符区域转换为感兴趣区域可提高检测精度,实现低像素灰度图情形下的ROI区域缺陷检测。In the method of the present invention, the pre-created reference image template is obtained by training a plurality of character image samples containing characters to be detected, and the image template creation and training process of the reference image can adopt the prior art. The parameters that can be obtained by template matching include a parameter value indicating whether a matching model character can be found in the image to be inspected and the number of character defects. According to the number of character defects, it can be judged whether there is a character defect. In the process of template creation, the detection accuracy can be improved by converting the character area into a region of interest, and the defect detection of the ROI area in the case of low-pixel grayscale images can be realized.

实施例1-1Example 1-1

基于实施例1,本实施例具体介绍基于工业机器视觉的AOI字符缺陷检测方法。Based onEmbodiment 1, this embodiment specifically introduces an AOI character defect detection method based on industrial machine vision.

本发明模板匹配建立在基准图像模板的创建和待检测图像的位置校正和字符区域选择基础上,参考图1所示,在实际的检测实施前,需要首先确定和获取基准图像,确定基准图像的标定点和mark点。需要进行检测时,则需要首先获取待检测图像,通过其mark点,然后进行仿射变换使得待检测图像与基准图像mark点重合实现位置校正,进而裁剪得到含字符的矩形图像区域,如图2所示。The template matching of the present invention is based on the creation of the reference image template and the position correction of the image to be detected and the selection of the character area. Referring to FIG. 1, before the actual detection is implemented, it is necessary to first determine and acquire the reference image, and determine the size of the reference image. Calibration point and mark point. When detection is required, it is necessary to first obtain the image to be detected, pass its mark points, and then perform affine transformation to make the image to be detected coincide with the mark points of the reference image to achieve position correction, and then crop to obtain a rectangular image area containing characters, as shown in Figure 2 shown.

参考图4所示,本实施例中,方法的实现主要涉及以下内容。Referring to FIG. 4 , in this embodiment, the implementation of the method mainly involves the following contents.

一、基准图像采集和处理1. Baseline image acquisition and processing

(1)新建名为Standard的文件夹存放.png格式的基准图像;(1) Create a new folder named Standard to store the benchmark image in .png format;

(2)使用500万像素的工业相机进行拍摄,将获取的基准图像存到Standard文件夹中;(2) Use a 5-megapixel industrial camera to shoot, and store the acquired reference image in the Standard folder;

(3)通过阈值判断、形状选择的方式对基准图像进行mark点位置标定、区域选择、裁剪图像,得到基准图像的感兴趣区域,存入新的image_processing文件夹中;(3) Carry out mark point position calibration, region selection, and cropping of the reference image by means of threshold judgment and shape selection to obtain the region of interest of the reference image and store it in a new image_processing folder;

(4)利用二值化算法分割图像前景和背景,得到字符区域图像。(4) Use the binarization algorithm to segment the foreground and background of the image to obtain the character area image.

本实施例采用Blob分析的方法进行基准图像的预处理,包括:计算基准图像的面积Aera_original,对其进行GAUSS滤波后使其变得平滑易处理,采用二值化阈值的方法,其中’LightDark’系数选取为’Dark’来对图像进行二值化,并计算二值化后字符Region的面积Value,计算Aera_original与Value之差,若Aera_original与Value之差小于Value,则需对图像进行反色处理,再用二值化阈值对图像进行灰度值分割;反之,则直接用二进制阈值进行灰度值分割;因为在选取ROI区域时可能会有边框干扰,故需要用根据特征值选择区域的算法进行去除边框处理;去除边框处理后用缩减图像特定区域的方法去截取只含有字符的区域并对区域进行膨胀处理,以确保字符完全包含在框选的区域内。In this embodiment, the Blob analysis method is used to preprocess the reference image, which includes: calculating the area Aera_original of the reference image, performing GAUSS filtering on it to make it smooth and easy to handle, and using the method of binarization threshold, where 'LightDark' The coefficient is selected as 'Dark' to binarize the image, calculate the area Value of the character Region after binarization, and calculate the difference between Aera_original and Value. If the difference between Aera_original and Value is less than Value, the image needs to be inverted. , and then use the binary threshold to segment the gray value of the image; otherwise, directly use the binary threshold to segment the gray value; because there may be border interference when selecting the ROI area, it is necessary to use an algorithm that selects the area according to the eigenvalue. Perform frame removal processing; after frame removal processing, use the method of reducing the specific area of the image to intercept the area containing only characters and perform expansion processing on the area to ensure that the characters are completely included in the area selected by the frame.

二、模板创建和训练2. Template creation and training

基于基准图像的字符区域图像创建图像模板;Create an image template based on the character area image of the reference image;

利用多组字符图像样本对图像模板进行匹配训练,以调整模板匹配算法的过程参数,确保其高精度的匹配,在此基础上调节NumLevels、Greediness等参数提高匹配速度。Use multiple sets of character image samples to perform matching training on image templates to adjust the process parameters of the template matching algorithm to ensure high-precision matching. On this basis, parameters such as NumLevels and Greediness are adjusted to improve the matching speed.

模板匹配算法输入主要有:Image,ModelID,AngleStart,AngleExtent,ScaleMin,ScaleMax,MinScore,NumMatches,MaxOverlap,SubPixel,NumLevels,Greediness。其中,参数Image为基准图像,ModelID为模型名称。参数AngleStart和AngleExtent决定了要搜索模型的旋转范围。参数ScaleMin和ScaleMax确定要搜索模型的范围。参数MinScore决定了一个潜在的匹配至少必须被视为图像中模型的一个实例。参数SubPixel亚像素决定是否以亚像素精度提取实例。在搜索过程中使用的金字塔层次的数量是由数字层次NumLevel决定的。参数Greediness决定搜索应该如何“贪婪地”执行。算法的输出主要为:Row,Column,Angle,Scale,Score。其中,模型的发现实例的位置、旋转和比例按行、列、角度和比例返回。坐标的行和列与形状模型在搜索图像中的原点位置有关。每个找到的实例的分数在score中返回。分数是一个介于0和1之间的数字,这是一个关于模型在图像中可见程度的近似度量。例如,如果模型的一半被遮挡,则得分不能超过0.5。The input of the template matching algorithm mainly includes: Image, ModelID, AngleStart, AngleExtent, ScaleMin, ScaleMax, MinScore, NumMatches, MaxOverlap, SubPixel, NumLevels, Greediness. Among them, the parameter Image is the reference image, and ModelID is the model name. The parameters AngleStart and AngleExtent determine the rotation range of the model to be searched. The parameters ScaleMin and ScaleMax determine the extent of the model to be searched. The parameter MinScore determines that a potential match must be considered at least one instance of the model in the image. The parameter SubPixel determines whether to extract instances with sub-pixel precision. The number of pyramid levels used in the search process is determined by the number level NumLevel. The parameter Greediness determines how "greedy" the search should be performed. The output of the algorithm is mainly: Row, Column, Angle, Scale, Score. where the position, rotation and scale of the discovered instance of the model are returned in row, column, angle and scale. The rows and columns of coordinates relate to the location of the origin of the shape model in the search image. The score for each found instance is returned in the score. The score is a number between 0 and 1, which is an approximate measure of how visible the model is in the image. For example, if half of the model is occluded, the score cannot exceed 0.5.

本发明使用监视模板来进行检查参数的适用性,并可以找到合适的参数,此外通过监视模板来获得这个模板的轮廓,可用于后面的匹配。接着将框架转换为XLD轮廓(contour),创建形状模板shape model。在创建形状模板时需要注意的是对于NumLevels、Contrast、Metric等参数设置尤为重要,需要在测试图片上经过反复调试,从而选择最优参数。The present invention uses the monitoring template to check the applicability of the parameters, and can find suitable parameters, in addition, the outline of the template is obtained by monitoring the template, which can be used for subsequent matching. The frame is then converted to an XLD contour (contour) to create a shape model. When creating a shape template, it should be noted that parameter settings such as NumLevels, Contrast, and Metric are particularly important. It is necessary to repeatedly debug the test image to select the optimal parameters.

经过试验验证,模板匹配的参数NumLevels、Greediness,取值分别为5、0.9时匹配速度最快且精度最高。After experimental verification, when the parameters NumLevels and Greediness of template matching are 5 and 0.9 respectively, the matching speed is the fastest and the accuracy is the highest.

三、待检测图像的获取和处理3. Acquisition and processing of images to be detected

1.新建Processing文件夹存放.png格式的待检测图像,使用500万像素的工业相机进行拍摄,将获取的待检测图像分别存到两个文件夹中。1. Create a new Processing folder to store the images to be detected in .png format, shoot with a 5-megapixel industrial camera, and store the acquired images to be detected in two folders respectively.

2.获取待检测图像mark点及标定点坐标M′1(x′1,y′1)、M′2(x′2,y′2)、P′(x′,y′),通过平移、缩放、旋转等仿射变换,使得待检测图像与基准图像mark点重合,然后裁剪图像大小。2. Obtain the mark point of the image to be detected and the coordinates of the calibration point M′1 (x′1 , y′1 ), M′2 (x′2 , y′2 ), P′ (x′, y′), and by translation , scaling, rotation and other affine transformations, so that the image to be detected coincides with the mark points of the reference image, and then the image size is cropped.

基准图像mark点mark1、mark2和标定点的坐标分别为M1(x1,y1)、M2(x2,y2)、P(x,y),则仿射变换过程为:The coordinates of the reference image mark points mark1, mark2 and the calibration point are M1 (x1 , y1 ), M2 (x2 , y2 ), P(x, y), respectively, then the affine transformation process is:

以M1点为基准,建立坐标系x0y0;以M′1点为基准,建立坐标系xTyT和坐标系xRyR。则在坐标系x0y0中,P点的相对坐标为P(xr,yr),P′点的相对坐标为P′(x′r,y′r),其中xr=x-x1,yr=y-y1,x′r=x′-x′1,y′r=y′-y′1Taking the M1 point as the benchmark, establish the coordinate system x0 y0 ; taking the M′1 point as the benchmark, establish the coordinate system xT yT and the coordinate system xR yR . Then in the coordinate system x0 y0 , the relative coordinates of point P are P(xr , yr ), and the relative coordinates of point P' are P'(x'r , y'r ), where xr =xx1 , yr =yy1 , x'r =x'-x'1 , y'r =y'-y'1 .

P点经过两次坐标系变换得到P’点,即通过一次坐标平移变换将坐标系x0y0平移至坐标系xTyT,再通过一次坐标旋转变换将坐标系xTyT旋转θ角至坐标系xRyRPoint P is transformed into the coordinate system twice to obtain the point P', that is, the coordinate system x0 y0 is translated to the coordinate system xT yT through a coordinate translation transformation, and the coordinate system xT yT is rotated by θ through a coordinate rotation transformation. Angle to coordinate system xR yR .

为了计算方便,坐标变换的过程也可以看成是先旋转变换再平移变换,则经过变换后得到P′点在坐标系x0y0中的相对坐标为:For the convenience of calculation, the process of coordinate transformation can also be regarded as rotation transformation and then translation transformation. After transformation, the relative coordinates of point P' in the coordinate system x0 y0 are:

Figure BDA0002455944070000091
Figure BDA0002455944070000091

其中,x0=x′1-x1,y0=y′1-y1Wherein, x0 =x'1 -x1 , and y0 =y'1 -y1 .

又有there are

Figure BDA0002455944070000092
Figure BDA0002455944070000092

由公式(1)、(2)联立求得P’的机器坐标为The machine coordinates of P' obtained by formulas (1) and (2) simultaneously are:

Figure BDA0002455944070000093
Figure BDA0002455944070000093

其中θ=θ01

Figure BDA0002455944070000094
where θ=θ0 −θ1 and
Figure BDA0002455944070000094

所以坐标系旋转角度为So the rotation angle of the coordinate system is

Figure BDA0002455944070000101
Figure BDA0002455944070000101

代入公式(3)即可最终求得P’点的机器坐标,实现待检测图像位置校正。Substitute into formula (3) to finally obtain the machine coordinates of point P', and realize the position correction of the image to be detected.

位置校正后,进行矩形ROI区域框选裁剪,留下包含字符区域的部分即字符区域图像,具体为:After the position correction, the rectangular ROI area is selected and cropped, and the part containing the character area, that is, the character area image, is left, specifically:

根据图像的绝对坐标获取矩形感兴趣区域算子,将图像分割成仅包含字符的矩形区域后进行裁剪,存入image_processing文件夹中,此时图像中仍是存在背景色的。对于基准图像和待处理图像的感兴趣区域图像,可在模板匹配前分别对两者进行二值化分割处理,分别得到用于模板匹配的字符区域图像,也可以分别预先处理得到字符区域图像。Obtain the rectangular region of interest operator based on the absolute coordinates of the image, divide the image into rectangular regions containing only characters, and then crop them and store them in the image_processing folder. At this time, the image still has a background color. For the region of interest images of the reference image and the image to be processed, binarization and segmentation processing can be performed on both before template matching to obtain character area images for template matching, or character area images can be obtained by preprocessing.

此外,还可通过对图像进行高斯滤波平滑图像边缘,降低像素低对图像处理带来的影响;In addition, the image edge can be smoothed by Gaussian filtering to reduce the impact of low pixels on image processing;

对于二值化分割得到的字符区域图像可能存在的其他干扰噪声,可对其进行面积大小选择,只保留含有字符的区域,接着根据矩形形状框选区域进行区域膨胀放大,以确保字符完全包含在框选的区域内。通过试验验证,选取字符区域时的膨胀系数在取值为2时,效果最佳。For other interfering noises that may exist in the character area image obtained by binarization segmentation, the area size can be selected, and only the area containing the characters can be retained, and then the area is expanded and enlarged according to the rectangle-shaped frame selection area to ensure that the characters are completely included in the within the selected area. It is verified by experiments that when the expansion coefficient of the character area is selected as 2, the effect is the best.

四、模板匹配4. Template matching

将待检测图像的字符区域图像与基于基准图像字符区域创建后训练得到的图像模板,进行模板匹配,判断待检测图像的字符区域是否存在字符缺陷。The image of the character area of the image to be detected is matched with the image template obtained after training based on the character area of the reference image, and template matching is performed to determine whether there is a character defect in the character area of the image to be detected.

在模板匹配算法的基本原理是将搜索模板T(m×n个像素)叠放在被搜索图S(W×H个像素)上平移,模板覆盖被搜索图的那块区域叫子图Sij。下标i,j为子图左上角在被搜索图S上的坐标。搜索范围是:The basic principle of the template matching algorithm is to overlay the search template T (m×n pixels) on the searched image S (W×H pixels) for translation, and the area where the template covers the searched image is called subgraph Sij . The subscripts i and j are the coordinates of the upper left corner of the subgraph on the searched graph S. The search scope is:

1≤i≤W-m1≤i≤W-m

1≤j≤H-n1≤j≤H-n

通过比较T和Sij的相似性,完成模板匹配过程。衡量模板T和子图Sij的匹配程度,可用下列两种测度:By comparing the similarity of T and Sij, the template matching process is completed. To measure the matching degree between template T and subgraph Sij, the following two measures can be used:

Figure BDA0002455944070000102
Figure BDA0002455944070000102

or

Figure BDA0002455944070000103
Figure BDA0002455944070000103

将上面第一个式子展开得到如下:Expand the first expression above to get the following:

Figure BDA0002455944070000111
Figure BDA0002455944070000111

从展开的公式中可以看出,中间第二项是一个常数,也就是只跟模板有关系,而第一个和第三个是和原图有关的,随着模板在原图上的移动,这两个值也在发生变化。当D(i,j)的值最小时,说明找到了目标。但是这样做的效率非常低下,每移动一个像素元都要进行一次运算,计算量非常大。It can be seen from the expanded formula that the second item in the middle is a constant, that is, it is only related to the template, while the first and third items are related to the original image. As the template moves on the original image, this Both values are also changing. When the value of D(i, j) is the smallest, it means that the target has been found. However, the efficiency of doing so is very low, and an operation is required for each pixel to be moved, and the amount of calculation is very large.

由于通过观察实际模板匹配运算结果发现,匹配点附近的匹配误差迅速下降,明显区别于其它位置。因此针对这一特点,本发明采用粗精匹配结合的算法迅速锁定匹配点大致区域,可大大降低整体匹配次数。具体实现方法:先跳动着隔几个点进行一次粗匹配,大致框定匹配区域,然后在附近区域逐一检索获得最佳匹配点。也即:By observing the actual template matching operation results, it is found that the matching error near the matching point decreases rapidly, which is obviously different from other positions. Therefore, in view of this feature, the present invention adopts an algorithm combining rough and fine matching to quickly lock the approximate area of the matching point, which can greatly reduce the overall matching times. The specific implementation method is as follows: First, perform a rough matching at a few points, roughly frame the matching area, and then retrieve the best matching points one by one in the nearby area. That is:

在确定初始搜索范围后,每次移动多个像素元得到搜索模板覆盖被搜索图的区域为子图Sij,下标i、j为子图Sij左上角在被搜索图Sij上的坐标;After the initial search range is determined, the area where the search template covers the searched image is obtained by moving multiple pixel elements each time as the subimage Sij, and the subscripts i and j are the coordinates of the upper left corner of the subimage Sij on the searched image Sij;

每次移动后分别计算搜索模板T与子图Sij的匹配程度;Calculate the matching degree of the search template T and the sub-graph Sij after each move;

选择匹配程度最优的子图,将其坐标及周围设定范围作为新的搜索范围;Select the subgraph with the best matching degree, and use its coordinates and surrounding setting range as the new search range;

在新的搜索范围内,每次移动单个像素元,并计算搜索模板T与子图Sij的匹配程度;In the new search range, move a single pixel each time, and calculate the matching degree between the search template T and the sub-image Sij;

在新的搜索范围内,选择匹配程度优的子图,进而计算匹配程度值和缺陷个数。In the new search range, select the subgraph with excellent matching degree, and then calculate the matching degree value and the number of defects.

实践证明,以上算法改进可使得模板匹配的运算量减少到三分之一以下,且目标提取效果相当好。Practice has proved that the above algorithm improvement can reduce the computational complexity of template matching to less than one third, and the target extraction effect is quite good.

通过模板匹配,可得到匹配分数Score,若Score=0,则待检测图像中不存在基准图像中的字符,若Score≠0,则待检测图像中能够找到基准图像中的字符,这种情况下,模板匹配算法将比较待检测图像的字符区域与基准图像的字符区域,得到字符缺陷个数NumError并输出。匹配分数Score是一个0到1之间的数,是模板在搜索图像中可见比例的近似测量。Through template matching, the matching score Score can be obtained. If Score=0, the character in the reference image does not exist in the image to be detected. If Score≠0, the character in the reference image can be found in the image to be detected. In this case , the template matching algorithm will compare the character area of the image to be detected and the character area of the reference image to obtain the number of character defects NumError and output. The match score Score is a number between 0 and 1 that is an approximate measure of the proportion of the template visible in the search image.

本实施例根据模板匹配结果判断待检测图像是否存在字符缺陷即为:若NumErro>0,则待检测图像存在字符缺陷。反之可预判为待检测图像不存在字符缺陷。In this embodiment, according to the template matching result, it is determined whether the image to be detected has a character defect: if NumErro>0, the image to be detected has a character defect. On the contrary, it can be predicted that there is no character defect in the image to be detected.

五、字符偏移量判断Five, character offset judgment

对于模板匹配结果中NumErro=0的情形,前期可初步判断为无字符缺陷,而字符偏移量判断可进一步检测字符缺陷,排查出存在偏移较大的待检测图像。For the case of NumErro=0 in the template matching result, it can be preliminarily judged that there is no character defect, and the character offset judgment can further detect the character defect, and find out the image to be detected with a large offset.

字符偏移量判断具体为:The character offset judgment is as follows:

计算待检测图像的字符区域图像中心坐标,将其与基准图像模板对应的基准图像中字符区域的中心坐标进行比较,计算待检测图像的偏移量;偏移量的计算可以是:求取待检测图像中字符区域与基准图像中字符区域的中心坐标,计算两者列向量的差值,作为偏移量值;Calculate the image center coordinates of the character area of the image to be detected, compare it with the center coordinates of the character area in the reference image corresponding to the reference image template, and calculate the offset of the image to be detected; the offset calculation can be: Detect the center coordinates of the character area in the image and the character area in the reference image, and calculate the difference between the two column vectors as the offset value;

将计算得到的偏移量与设定阈值进行比较,响应于偏移量大于设定阈值,则输出存在字符缺陷的相应结果信息,否则输出匹配成功的相应结果信息。Comparing the calculated offset with the set threshold, in response to the offset being greater than the set threshold, output corresponding result information with character defects, otherwise output corresponding result information with successful matching.

具体的偏移量判断结果可根据需要设置,如一种方式为:偏移量的阈值设置为多个不同取值0、C0等,每个阈值分别对应一个字符缺陷程度值,字符缺陷结果信息包括偏移程度标志位,标志位的值即为字符缺陷程度值;最终输出的偏移程度标志位的取值为,比偏移量小且与偏移量临近的阈值对应的字符缺陷程度值;如图4所示,根据待检测字符确定正偏移量阈值C0和负偏移量阈值-C0,当C>C0时,字符向右偏移较大,判断标志flag=3,判定为NG;C<-C0时,字符向左偏移较大,判断标志flag=2,判定为NG;-C0<C<C0时,字符位置在正常范围内,判断标志flag=0,判定为PASS。The specific offset judgment result can be set as needed. For example, one method is: the threshold of the offset is set to a plurality ofdifferent values 0, C0, etc., each threshold corresponds to a character defect degree value, and the character defect result information includes: Offset degree flag bit, the value of the flag bit is the character defect degree value; the value of the final output offset degree flag bit is the character defect degree value corresponding to the threshold smaller than the offset and close to the offset; As shown in Figure 4, the positive offset threshold C0 and the negative offset threshold -C0 are determined according to the character to be detected. When C>C0, the character is shifted to the right by a large amount, and the judgment flag flag=3 is judged as NG; When C<-C0, the character is shifted to the left by a large amount, the judgment flag flag=2, it is judged as NG; when -C0<C<C0, the character position is within the normal range, the judgment flag flag=0, and it is judged as PASS.

如图5,另一种方式还可以是:As shown in Figure 5, another way can also be:

当偏移量大于0小于C0,代表字符偏移程度较小,标志位flag为0,可输出PASS表示字符无缺陷检测通过;当偏移量大于C0则代表字符偏移程度较大,标志位flag为2,或者偏移量更大,大于更大的阈值时,flag为3,此时可输出NG表示字符有缺陷,检测不通过。When the offset is greater than 0 and less than C0, it means that the degree of character offset is small, and the flag bit flag is 0, and PASS can be output to indicate that the character has passed the defect-free detection; when the offset value is greater than C0, it means that the degree of character offset is relatively large, and the flag bit When the flag is 2, or the offset is larger than the larger threshold, the flag is 3. At this time, NG can be output to indicate that the character is defective and the test fails.

这种方式下,偏移量的计算结果为非负值。In this way, the offset is calculated as a non-negative value.

本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。As will be appreciated by those skilled in the art, the embodiments of the present application may be provided as a method, a system, or a computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.

本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的系统。The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present application. It will be understood that each flow and/or block in the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to the processor of a general purpose computer, special purpose computer, embedded processor or other programmable data processing device to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing device produce A system for implementing the functions specified in one or more of the flowcharts and/or one or more blocks of the block diagrams.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令系统的制造品,该指令系统实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable memory result in an article of manufacture comprising a system of instructions, the instructions The system implements the functions specified in the flow or flow of the flowcharts and/or the block or blocks of the block diagrams.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded on a computer or other programmable data processing device to cause a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process such that The instructions provide steps for implementing the functions specified in the flow or blocks of the flowcharts and/or the block or blocks of the block diagrams.

以上结合附图对本发明的实施例进行了描述,但是本发明并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本发明的启示下,在不脱离本发明宗旨和权利要求所保护的范围情况下,还可做出很多形式,这些均属于本发明的保护之内。The embodiments of the present invention have been described above with reference to the accompanying drawings, but the present invention is not limited to the above-mentioned specific embodiments. The above-mentioned specific embodiments are only illustrative rather than restrictive. Under the inspiration of the present invention, without departing from the scope of protection of the present invention and the claims, many forms can be made, which all belong to the protection of the present invention.

Claims (9)

1. An AOI character defect detection method is characterized by comprising the following steps:
acquiring an image to be detected;
preprocessing an image to be detected to obtain an interested area image with corrected position and containing characters;
separating the images of the interested areas of the images to be detected to obtain character area images;
carrying out template matching on the character area image of the image to be detected and a pre-established reference image template to obtain a template matching result;
judging whether the image to be detected has character defects or not according to the template matching result;
outputting a character defect judgment result;
wherein the creating of the reference image template comprises:
determining a reference image corresponding to an image to be detected and a plurality of training sample images with known character defects;
determining mark position points and calibration points of the reference image, and determining a character area image;
creating an image template based on the character area image of the reference image;
preprocessing and separating images of each training sample according to the images to be detected to obtain character area images;
and performing matching training on the image template by using the character area image of the training sample to adjust the parameters of the matching process of the template, so that the result of template matching after parameter adjustment meets the character defects of the corresponding training sample image.
2. The method of claim 1, wherein template matching comprises: calculating a matching Score, wherein if the Score is 0, characters in the reference image do not exist in the image to be detected, and if the Score is not 0, the characters in the reference image can be found in the image to be detected;
in response to that Score is not equal to 0, comparing the character area of the image to be detected with the character area of the reference image to obtain and output a number NumError of character defects;
judging whether the character defects exist in the image to be detected according to the template matching result: if NumErro is larger than 0, the character defect exists in the image to be detected.
3. The method of claim 2, further comprising:
responding to the NumErro which is 0 in the template matching result, calculating the center coordinates of the character area image of the image to be detected, comparing the center coordinates with the center coordinates of the character area in the reference image corresponding to the reference image template, and calculating the offset of the image to be detected;
and comparing the calculated offset with a set threshold, and outputting corresponding result information with character defects in response to the fact that the offset is greater than the set threshold, otherwise outputting corresponding result information with successful matching.
4. The method as claimed in claim 3, wherein the threshold value of the offset is set to a plurality of different values, each threshold value corresponds to a character defect degree value, the character defect result information includes an offset degree flag bit, and the value of the flag bit is the character defect degree value; the value of the finally output offset degree zone bit is a character defect degree value which is smaller than the offset and corresponds to a threshold value close to the offset.
5. The method as claimed in claim 1, wherein a Blob analysis algorithm is used for separating foreground and background of the image of the region of interest of the image to be detected, so as to obtain a character region image;
the method further comprises the steps of selecting an area operator according to the characteristic value in the Halcon algorithm to remove image frames of the image of the region of interest of the image to be detected, then intercepting the area only containing characters by using the operator for reducing the specific area of the image, and further performing expansion processing on the area to obtain a final character area image.
6. The method of claim 1, further comprising storing the reference image and the image to be detected in different folders, respectively;
when the image to be detected is preprocessed, the position correction comprises the following steps:
acquiring mark position points and calibration points of a stored reference image;
acquiring mark position points and calibration points of a stored image to be detected;
and enabling the mark position points of the image to be detected and the reference image to coincide through affine transformation.
7. The method of claim 6, wherein the mark position point of the reference image is defined as M1 (x1 ,y1 )、M2 (x2 ,y2 ) The index point is P (x, y), and the position point of the image to be detected is M'1 (x′1 ,y′1 )、M′2 (x′2 ,y′2 ) The index point is P ' (x ', y ');
the affine transformation is:
with M1 Establishing a coordinate system x by taking the point as a reference0 y0 (ii) a From M'1 Establishing a coordinate system x by taking the point as a reference0 y0 Of a translational coordinate system xT yT And a rotating coordinate system xR yR (ii) a Then in the coordinate system x0 y0 In (3), the relative coordinate of the point P is P (x)r ,yr ) The relative coordinate of point P ' is P ' (x 'r y′r ) Wherein x isr =x-x1 ,yr =y-y1 ,x′r =x′-x′1 ,y′r =y′-y′1
The P point is transformed by a coordinate system twice to obtain a P' point which is located at x0 y0 The relative coordinates in the coordinate system are:
Figure FDA0003681409350000031
wherein x is0 =x′1 -x1 ,y0 =y′1 -y1
And:
Figure FDA0003681409350000032
the machine coordinate of P' obtained by equations (1) and (2) is:
Figure FDA0003681409350000033
where θ is θ01 And is
Figure FDA0003681409350000034
The rotation angle of the coordinate system is:
Figure FDA0003681409350000035
and substituting the formula (4) into the formula (3) to obtain the machine coordinate of the P 'point, and correcting the image position to be detected according to the machine coordinate of the P' point.
8. The method of claim 1, wherein template matching comprises:
taking a character area image of a reference image as a search template T, defining the pixel of the character area image as m multiplied by n, taking a character area image of an image to be detected as a searched image S, and defining the pixel of the character area image as W multiplied by H pixels;
the search template T is overlaid on the searched graph S for moving search, and the search range is as follows:
1≤i≤W-m
1≤j≤H-n
moving a plurality of pixel elements each time to obtain a search template covering the area of the searched graph as a subgraph Sij Subscripts i, j are subgraphs Sij In the upper left corner of the searched image Sij Coordinates of (3);
after each movement, respectively calculating the matching degree of the search template T and the subgraph Sij;
selecting a subgraph with the optimal matching degree, and taking the coordinate and the surrounding set range of the subgraph as a new search range;
in a new search range, moving a single pixel element each time, and calculating the matching degree of a search template T and a subgraph Sij;
and in the new search range, selecting the sub-graph with the excellent matching degree, and further calculating the matching degree value and the defect number.
9. The method of claim 8, wherein after each move, the degree of matching of the search template T to the subgraph Sij is determined according to one of the following equations:
Figure FDA0003681409350000041
Figure FDA0003681409350000042
the smaller the D (i, j), the better the characteristic matching degree.
CN202010306399.1A2020-04-172020-04-17AOI character defect detection method and device based on industrial machine visionActiveCN111474184B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202010306399.1ACN111474184B (en)2020-04-172020-04-17AOI character defect detection method and device based on industrial machine vision

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202010306399.1ACN111474184B (en)2020-04-172020-04-17AOI character defect detection method and device based on industrial machine vision

Publications (2)

Publication NumberPublication Date
CN111474184A CN111474184A (en)2020-07-31
CN111474184Btrue CN111474184B (en)2022-08-16

Family

ID=71754001

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202010306399.1AActiveCN111474184B (en)2020-04-172020-04-17AOI character defect detection method and device based on industrial machine vision

Country Status (1)

CountryLink
CN (1)CN111474184B (en)

Families Citing this family (27)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN114078109B (en)*2020-08-132024-12-27富联精密电子(天津)有限公司 Image processing method, electronic device and storage medium
CN112270329A (en)*2020-10-302021-01-26北京华维国创电子科技有限公司Accurate MARK point acquisition and identification algorithm based on multi-level algorithm fusion
CN112651972A (en)*2020-11-112021-04-13北京平恒智能科技有限公司Positioning method using integral constraint of double positioning
CN112782179A (en)*2020-12-222021-05-11北京市新技术应用研究所Method and system for detecting defects of light-reflecting surface of product
CN112557412A (en)*2020-12-252021-03-26无锡歌迪亚自动化科技有限公司Automatic code-spraying printing defect detection system and detection method
CN112381827B (en)*2021-01-152021-04-27中科慧远视觉技术(北京)有限公司Rapid high-precision defect detection method based on visual image
CN112837302B (en)*2021-02-092024-02-13广东拓斯达科技股份有限公司Method and device for monitoring state of die, industrial personal computer, storage medium and system
CN113111868B (en)*2021-03-162023-08-18广州大学 A character defect detection method, system, device and storage medium
CN113160154B (en)*2021-04-082024-07-02杭州电子科技大学Method and system for detecting paint spraying defects of five-star feet based on machine vision
CN113295617B (en)*2021-05-182022-11-25广州慧炬智能科技有限公司Multi-target offset detection method without reference point
CN113327204B (en)*2021-06-012024-03-15中科晶源微电子技术(北京)有限公司Image calibration method, device, equipment and storage medium
CN115511769A (en)*2021-06-042022-12-23深圳鑫成泰达科技有限公司Normalization detection method for packaged character images on production line
CN113487538B (en)*2021-06-082024-03-22维库(厦门)信息技术有限公司Multi-target segmentation defect detection method and device and computer storage medium thereof
CN113609897A (en)*2021-06-232021-11-05阿里巴巴新加坡控股有限公司Defect detection method and defect detection system
CN113689397A (en)*2021-08-232021-11-23湖南视比特机器人有限公司Workpiece circular hole feature detection method and workpiece circular hole feature detection device
CN113538427B (en)*2021-09-162022-01-07深圳市信润富联数字科技有限公司Product defect identification method, device, equipment and readable storage medium
CN114354491A (en)*2021-12-302022-04-15苏州精创光学仪器有限公司DCB ceramic substrate defect detection method based on machine vision
CN114549504B (en)*2022-03-012024-11-15安徽工业技术创新研究院六安院 A method for appearance quality inspection based on machine vision
CN116932793B (en)2022-04-082025-09-30鸿海精密工业股份有限公司 Data deletion method, device, equipment and storage medium for visual inspection
TWI824473B (en)*2022-04-082023-12-01鴻海精密工業股份有限公司Method and device for deleting data by visual detection, electronic device, and computer-readable storage medium
CN114881996B (en)*2022-05-252025-04-08京东方科技集团股份有限公司 Defect detection method and device
CN115330705B (en)*2022-08-042025-08-15西北工业大学Skin paint surface defect detection method based on self-adaptive weighting template NCC
CN116109573A (en)*2022-12-282023-05-12凌云光技术股份有限公司Optical character verification method, device, electronic equipment and storage medium
CN116129435B (en)*2023-04-142023-08-08歌尔股份有限公司Character defect detection method, device, equipment and storage medium
CN117011167B (en)*2023-07-032024-08-20广东盈科电子有限公司Image positioning correction method, system and device for nixie tube and storage medium
CN118366167B (en)*2024-04-162025-07-29广东奥普特科技股份有限公司Character defect detection method and related equipment
CN118941645B (en)*2024-07-222025-02-25华翌智能装备(杭州)有限公司 A machine calibration method for AOI automatic optical inspection machines in the SMT industry

Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101464951A (en)*2007-12-212009-06-24北大方正集团有限公司Image recognition method and system
CN108982508A (en)*2018-05-232018-12-11江苏农林职业技术学院A kind of plastic-sealed body IC chip defect inspection method based on feature templates matching and deep learning

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101464951A (en)*2007-12-212009-06-24北大方正集团有限公司Image recognition method and system
CN108982508A (en)*2018-05-232018-12-11江苏农林职业技术学院A kind of plastic-sealed body IC chip defect inspection method based on feature templates matching and deep learning

Also Published As

Publication numberPublication date
CN111474184A (en)2020-07-31

Similar Documents

PublicationPublication DateTitle
CN111474184B (en)AOI character defect detection method and device based on industrial machine vision
CN108776140B (en)Machine vision-based printed matter flaw detection method and system
CN105046252B (en)A kind of RMB prefix code recognition methods
US6778703B1 (en)Form recognition using reference areas
JP7649350B2 (en) SYSTEM AND METHOD FOR DETECTING AND CLASSIFYING PATTERNS IN IMAGES WITH A VISION SYSTEM - Patent application
CN109426814B (en)Method, system and equipment for positioning and identifying specific plate of invoice picture
CN111680688A (en)Character recognition method and device, electronic equipment and storage medium
US20080226171A1 (en)Correcting device and method for perspective transformed document images
CN112085024A (en) A method for character recognition on the surface of a tank
CN105913093A (en)Template matching method for character recognizing and processing
CN108647706B (en) Item recognition classification and defect detection method based on machine vision
CN106897990B (en) Character defect detection method of tire mold
CN113903024A (en)Handwritten bill numerical value information identification method, system, medium and device
CN110363196B (en)Method for accurately recognizing characters of inclined text
US7340089B2 (en)Geometric pattern matching using dynamic feature combinations
CN113688846A (en)Object size recognition method, readable storage medium, and object size recognition system
CN110288040B (en)Image similarity judging method and device based on topology verification
CN115294062A (en) Text printing defect detection method based on text recognition and template matching
CN111222507A (en) Automatic identification method of digital meter reading, computer readable storage medium
CN115512381A (en)Text recognition method, text recognition device, text recognition equipment, storage medium and working machine
CN114119644A (en)Template matching method based on edge features
CN114004858A (en) Method and device for recognizing surface coding of aviation cable based on machine vision
CN113658039A (en) A method for determining the splicing sequence of medicine bottle label images
CN112686265A (en)Hierarchic contour extraction-based pictograph segmentation method
CN120279238A (en)Embroidery positioning printing method, equipment and storage medium based on machine vision

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp