本发明的实施方式Embodiments of the invention
为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
需说明的是,当部件被称为“固定于”或“设置于”另一个部件,它可以直接在另一个部件上或者间接在该另一个部件上。当一个部件被称为是“连接于”另一个部件,它可以是直接连接到另一个部件或者间接连接至该另一个部件上。It should be noted that when a component is referred to as being “fixed” or “disposed on” another component, it can be directly on another component or indirectly on the other component. When a component is said to be "connected to" another component, it can be directly connected to the other component or indirectly connected to the other component.
还需说明的是,本发明实施例的附图中相同或相似的标号对应相同或相似的部件;在本发明的描述中,需要理解的是,若有术语“上”、“下”、“左”、“右”等指示的方位或位置关系为基于附图所示的方位或位置关系,仅是为了便于描述本发明和简化描述,而不是指示或暗示所指的装置或元件必须具有特定的方位、以特定的方位构造和操作,因此,附图中描述位置关系的用语仅用于示例性说明,不能理解为对本专利的限制,对于本领域的普通技术人员而言,可以根据具体情况理解上述术语的具体含义。It should also be noted that the same or similar reference numerals in the drawings of the embodiments of the present invention correspond to the same or similar parts; in the description of the present invention, it should be understood that if there are terms “upper”, “lower”, and “ The orientation or positional relationship indicated by "left", "right", etc. is based on the orientation or positional relationship shown in the drawings, only to facilitate the description of the present invention and simplify the description, and does not indicate or imply that the device or element referred to must have a specific The orientation and construction and operation in a specific orientation are used. Therefore, the terms used to describe the positional relationship in the drawings are for illustrative purposes only, and cannot be construed as a limitation of this patent. For those of ordinary skill in the art, they can Understand the specific meaning of the above terms.
此外,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个或者更多该特征。在本发明的描述中,“多个”的含义是两个或两个以上,除非另有明确具体的限定。In addition, the terms “first” and “second” are used for description purposes only, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise specifically limited.
请参考图1-2所示,本发明实施例提供一种口罩在线检测系统,包括:机柜5、输送机构1、翻转机构3、图像采集机构2、图像处理软件6、分选机构4和PLC控制系统 7。Please refer to FIG. 1-2, an embodiment of the present invention provides an online mask detection system, including: cabinet 5, conveying mechanism 1, turnover mechanism 3, image acquisition mechanism 2, image processing software 6, sorting mechanism 4 and PLC Control system 7.
其中,机柜5作为承载主体,用于安装输送机构1、翻转机构3、图像采集机构2、图像处理软件6、分选机构4和PLC控制系统 7。Among them, the cabinet 5 is used as a main body for installing the conveying mechanism 1, the turnover mechanism 3, the image acquisition mechanism 2, the image processing software 6, the sorting mechanism 4 and the PLC control system 7.
其中,输送机构1用于带动带检测口罩在机柜5上进行移动,以将待检测口罩依次输送到图像采集机构2处、翻转机构3处、分选机构4处。Among them, the conveying mechanism 1 is used to drive the detection mask to move on the cabinet 5 to sequentially convey the mask to be detected to the image collecting mechanism 2, the turning mechanism 3, and the sorting mechanism 4 in sequence.
其中,翻转机构3用于将待检测口罩翻转180°,即将待检测口罩的正面朝上翻转成反面朝上,以便图像采集机构2分别采集待检测口罩的正面图像和反面图像。Wherein, the flip mechanism 3 is used to flip the mask to be detected 180 °, that is, to flip the face-up of the mask to be detected upside-down, so that the image acquisition mechanism 2 collects the front and back images of the mask to be detected respectively.
其中,图像处理软件6用于对图像采集机构2采集的正面图像和反面图像与预设的口罩标准进行对比,若正面图像在预设的口罩标准范围内,则待检测口罩为良品,若正面图像和/或反面图像不在预设的口罩标准范围内,则待检测口罩为不良品,在本实施例中,口罩标准根据每个生产商的品质要求去设定,这里不作限定。Among them, the image processing software 6 is used to compare the front image and the back image collected by the image collection mechanism 2 with the preset mask standard. If the front image is within the preset mask standard range, the mask to be detected is good. If the image and / or the reverse image are not within the preset mask standard range, the mask to be detected is a defective product. In this embodiment, the mask standard is set according to the quality requirements of each manufacturer, which is not limited here.
其中,分选机构4用于将不良品和良品区分收集,以便保证良品的质量和不良品的回收利用。Among them, the sorting mechanism 4 is used to collect defective products and good products separately in order to ensure the quality of the good products and the recycling of the bad products.
其中,PLC控制系统 7分别与输送机构1、翻转机构3、图像采集机构2、图像处理软件6和分选机构4电性连接,PLC控制系统 7用于实现该口罩在线检测系统的自动化检测,从而提高待检测口罩的检测效率和质量,节约人工成本。Among them, the PLC control system 7 is electrically connected to the conveying mechanism 1, the turnover mechanism 3, the image acquisition mechanism 2, the image processing software 6 and the sorting mechanism 4, respectively, and the PLC control system 7 is used to realize the automatic detection of the mask online detection system. Therefore, the detection efficiency and quality of the mask to be detected are improved, and labor cost is saved.
具体地,在本实施例中,输送机构1包括:设于机柜5上的输送皮带12、输送电机11、第一光纤传感器13和吹耳带机构14。在本实施例中,机柜5内部中空,机柜5的上表面开设有开口,开口用于安装输送机构1和便于翻转机构3的翻转运动。Specifically, in this embodiment, the conveying mechanism 1 includes: a conveying belt 12 provided on the cabinet 5, a conveying motor 11, a first optical fiber sensor 13, and an ear-blowing belt mechanism 14. In this embodiment, the interior of the cabinet 5 is hollow, and an opening is provided on the upper surface of the cabinet 5. The opening is used to install the conveying mechanism 1 and facilitate the turning movement of the turning mechanism 3.
其中,输送皮带12设置有两条,两条输送皮带12间隔设置在机柜5上,待检测口罩的两端分别横放在两条输送皮带12上,驱动电机442用于驱动输送皮带12运转,吹耳带机构14用于对耳带进行吹气以使耳带展开,方便检测,第一光纤传感器13用于感应待检测口罩,当待检测口罩移动到吹耳带机构14处后,第一光纤传感器13将感应到待检测口罩的感应信号反馈给PLC控制系统 7,PLC控制系统 7控制吹耳带机构14实行对耳带进行吹气动作。在其他实施例中,输送皮带12可以设置有三条、四条或五条。Among them, two conveyor belts 12 are provided, and two conveyor belts 12 are arranged on the cabinet 5 at intervals. The two ends of the mask to be detected are placed horizontally on the two conveyor belts 12, and the driving motor 442 is used to drive the conveyor belt 12 to run. The ear strap mechanism 14 is used to blow the ear strap to expand the ear strap for easy detection. The first optical fiber sensor 13 is used to sense the mask to be detected. After the mask to be detected moves to the ear strap mechanism 14, the first The optical fiber sensor 13 feeds back the induction signal sensed to the mask to be detected to the PLC control system 7, and the PLC control system 7 controls the ear-blowing belt mechanism 14 to perform the air blowing action on the ear belt. In other embodiments, the conveyor belt 12 may be provided with three, four, or five belts.
更具体地,在本实施例中,吹耳带机构14包括:转动设于机柜5上的、用于牵引待检测口罩的上夹料皮带141和下夹料皮带142,用于对耳带进行吹气的吹气管144,以及,用于控制吹气管144通断的电磁阀143,电磁阀143与PLC控制系统 7电性连接,在本实施例中,电磁阀143为吹气型电磁阀143,用于向吹气管144中输送压缩空气,以将待检测口罩两端的耳带吹气展开,在其他实施例中,吹气管144连接有吹气泵。More specifically, in this embodiment, the ear-blowing belt mechanism 14 includes: rotating an upper clamping belt 141 and a lower clamping belt 142 provided on the cabinet 5 for pulling the mask to be detected, for performing An air blowing pipe 144 for blowing air, and a solenoid valve 143 for controlling the blowing of the air blowing pipe 144. The solenoid valve 143 is electrically connected to the PLC control system 7. In this embodiment, the solenoid valve 143 is a blow-type solenoid valve 143 , Used to send compressed air into the air blowing tube 144 to expand the earbands at both ends of the mask to be tested. In other embodiments, the air blowing tube 144 is connected to an air blowing pump.
其中,上夹料皮带141和下夹料皮带142用于将待检测口罩夹住,防止待检测口罩被吹气管144吹走脱离输送机构1,同时也可牵引待检测口罩移动。在本实施中,上夹料皮带141和下夹料皮带142通过两组辊轴安装在机柜5上,两组辊轴转动安装在机柜5上的机箱上,机箱上安装用驱动两组辊轴转动的步进电机。Among them, the upper clamping belt 141 and the lower clamping belt 142 are used to clamp the mask to be detected, to prevent the mask to be detected from being blown away from the conveying mechanism 1 by the air blowing pipe 144, and also to move the mask to be detected to move. In this implementation, the upper clamping belt 141 and the lower clamping belt 142 are installed on the cabinet 5 through two sets of roller shafts, and the two sets of roller shafts are rotatably installed on the cabinet on the cabinet 5, and the cabinet is driven by two sets of roller shafts Rotating stepper motor.
在本实施例中,翻转机构3包括:转动设于机柜5上的翻转杆32,以及,用于驱动翻转杆32转动的翻转电机31。其中,翻转杆32包括:延长方向与待检测口罩输送方向相垂直的主杆321,以及,至少两根垂直设置于主杆321上的支杆322,支杆322在两条输送皮带12之间翻转支杆322在翻转过程中用于实现待检测口罩的180°翻转。在其他实施例中,翻转杆32可用翻转板代替。In this embodiment, the turning mechanism 3 includes: turning the turning lever 32 provided on the cabinet 5 and a turning motor 31 for driving the turning lever 32 to turn. Wherein, the turning bar 32 includes: a main bar 321 whose extension direction is perpendicular to the conveying direction of the mask to be detected, and at least two supporting bars 322 arranged vertically on the main bar 321, and the supporting bar 322 is between the two conveying belts 12 The turning rod 322 is used to turn the mask to be detected 180 ° during turning. In other embodiments, the flip lever 32 may be replaced with a flip board.
在本实施例中,图像采集机构2包括:设置于机柜5上的支架22,设置于支架22上的直线导轨26,活动式设置于直线导轨26上的图像采集模组21,设置于支架22上的、用于驱动图像采集模组21在直线导轨26上往复运动的直线电机25,以及,间隔设于机柜5上的第二光纤传感器23和第三光纤传感器24;其中,翻转机构3位于第二光纤传感器23与第三光纤传感器24之间。In this embodiment, the image acquisition mechanism 2 includes: a bracket 22 provided on the cabinet 5, a linear guide 26 provided on the support 22, and an image acquisition module 21 movably provided on the linear guide 26, provided on the support 22 The linear motor 25 for driving the image acquisition module 21 to reciprocate on the linear guide 26 and the second optical fiber sensor 23 and the third optical fiber sensor 24 spaced on the cabinet 5; wherein, the turning mechanism 3 is located Between the second optical fiber sensor 23 and the third optical fiber sensor 24.
将第二光纤传感器23的感应位置设为一号检测位,将第三光纤传感器24的感应位置设为二号检测位,一号检测位用于图像采集模组21采集待检测口罩的正面图像,二号检测位用于图像采集模组21采集待检测口罩的反面图像。The sensing position of the second optical fiber sensor 23 is set to the first detection position, and the sensing position of the third optical fiber sensor 24 is set to the second detection position. The first detection position is used by the image acquisition module 21 to collect the front image of the mask to be detected The second detection position is used by the image collection module 21 to collect the reverse image of the mask to be detected.
具体地,图像采集模组21包括:设置于直线导轨26上的、与PLC控制系统 7、图像处理软件6电性连接的相机211,设置于相机211上的镜头212,以及,设置于相机211上的光源213;其中,光源213的光照射向待检测口罩。Specifically, the image acquisition module 21 includes: a camera 211 disposed on the linear guide 26, electrically connected to the PLC control system 7 and the image processing software 6, a lens 212 disposed on the camera 211, and a camera 211 The light source 213 on the top; wherein, the light of the light source 213 is irradiated to the mask to be detected.
在本实施例中直线导轨26和直线电机25采用丝杠结构来实现图像采集模组21在一号检测位与二号检测位之间往复运动。In this embodiment, the linear guide 26 and the linear motor 25 adopt a screw structure to realize the reciprocating movement of the image acquisition module 21 between the first detection position and the second detection position.
当第二光纤传感器23感应到待检测口罩时,相机211拍照采集正面图像并传递给图像处理软件6,若图像处理软件6判断为不良品,则等待下一个待检测口罩,若图像处理软件6判断为良品,则直线电机25驱动相机211运动到二号检测位处,此时待检测口罩运动到翻转机构3处进行180°翻转,当第三光纤传感器24感应到翻转后的待检测口罩时,相机211拍照采集反面图像并传递给图像处理软件6进行判断。When the second optical fiber sensor 23 senses the mask to be detected, the camera 211 takes a picture to collect a frontal image and passes it to the image processing software 6. If the image processing software 6 determines that it is a defective product, it waits for the next mask to be detected. If the image processing software 6 If it is judged as a good product, the linear motor 25 drives the camera 211 to move to the second detection position. At this time, the mask to be detected moves to the turning mechanism 3 to be turned 180 °. When the third fiber sensor 24 senses the turned mask to be detected , The camera 211 takes a picture and collects the reverse image and passes it to the image processing software 6 for judgment.
具体地,在本实施例中,光源213为中间开孔型面光源213,镜头212穿设于光源213的中心,这样设置便于光源213照射待检测口罩后不存在阴影,有效保证相机211拍照的清晰度。Specifically, in this embodiment, the light source 213 is a central aperture type surface light source 213, and the lens 212 is placed in the center of the light source 213, so that the setting is convenient for the light source 213 to irradiate the mask to be detected without shadows, effectively ensuring that the camera 211 takes pictures Clarity.
在本实施中,分选机构4包括:并排设置于输送机构1上方的不良品处理机构41和良品处理机构43,以及,并排设置于输送机构1下方的不良品收集箱42和良品收集机构44;其中,不良品处理机构41用于将不良品转移至不良品收集箱42中,良品处理机构43用于将良品转移至良品收集机构44中。In this embodiment, the sorting mechanism 4 includes: a defective product processing mechanism 41 and a good product processing mechanism 43 arranged side by side above the conveying mechanism 1, and a defective product collection box 42 and a good product collection mechanism 44 arranged side by side below the conveying mechanism 1 ; Among them, the defective product processing mechanism 41 is used to transfer the defective products to the defective product collection box 42, and the good product processing mechanism 43 is used to transfer the good products to the good product collection mechanism 44.
在本实施例中,不良品处理机构41包括:与PLC控制系统 7电性连接的第四光纤传感器411和第一气缸412,第一气缸412用于将位于两条输送皮带12上的不良品推入至不良品收集箱42中。In this embodiment, the defective product processing mechanism 41 includes: a fourth optical fiber sensor 411 electrically connected to the PLC control system 7 and a first air cylinder 412. The first air cylinder 412 is used to store defective products located on the two conveyor belts 12 Push it into the defective product collection box 42.
在本实施例中,良品处理机构43包括:第五光纤传感器431和第二气缸432,良品收集机构44包括:设置于输送皮带12下方的良品收集皮带441,以及用于驱动良品收集皮带441运转的驱动电机442,第二气缸432用于将良品推入至良品收集皮带441上,第五光纤传感器431、第二气缸432和驱动电机442与PLC控制系统 7电性连接。当良品收集皮带441上的同一位置收集的良品数量达到预定数量后,驱动电机442驱动良品收集皮带441运转一个至两个待检测口罩宽度,从而继续收集良品。In this embodiment, the good product processing mechanism 43 includes: a fifth optical fiber sensor 431 and a second cylinder 432, and the good product collection mechanism 44 includes: a good product collection belt 441 disposed below the conveying belt 12, and a device for driving the good product collection belt 441 to operate The driving motor 442, the second cylinder 432 are used to push the good products onto the good product collection belt 441, the fifth optical fiber sensor 431, the second cylinder 432 and the driving motor 442 are electrically connected to the PLC control system 7. When the number of good products collected at the same position on the good product collection belt 441 reaches a predetermined number, the drive motor 442 drives the good product collection belt 441 to run one to two mask widths to be detected, thereby continuing to collect good products.
在本实施例中,两条输送皮带12通过支撑架伸出机柜5的一端,第一气缸412、第二气缸432、第四光纤传感器411和第五光纤传感器431通过支撑架设置在输送皮带12上方且位于两条输送皮带12之间。第一气缸412和第二气缸432的活塞杆伸出方向向下设置,以便将待检测口罩向下推入不良品收集箱42中或良品收集机构44中。在本实施例中,输送电机11为步进电机或伺服电机,翻转电机31为步进电机,驱动电机442为调速电机。In this embodiment, two conveyor belts 12 extend out of one end of the cabinet 5 through the support frame, and the first cylinder 412, the second cylinder 432, the fourth fiber sensor 411, and the fifth fiber sensor 431 are disposed on the conveyor belt 12 through the support frame Above and between two conveyor belts 12. The extending direction of the piston rods of the first cylinder 412 and the second cylinder 432 is set downward so as to push the mask to be detected downward into the defective product collection box 42 or the good product collection mechanism 44. In this embodiment, the conveying motor 11 is a stepping motor or a servo motor, the turning motor 31 is a stepping motor, and the driving motor 442 is a speed regulating motor.
如图1-8所示,本实施例还在于提供一种口罩在线检测方法,包括:As shown in FIGS. 1-8, this embodiment also provides a mask online detection method, including:
S1、通过与图像处理软件6电性连接的图像采集机构2采集一号检测位处无待检测口罩的一号背景图和采集二号检测位处无待检测口罩的二号背景图,并将一号背景图和二号背景图分别转换为一号背景灰度图和二号背景灰度图;S1. Through the image acquisition mechanism 2 electrically connected to the image processing software 6, collect the first background image without the mask to be detected at the first detection position and the second background image without the mask to be detected at the second detection position, and The background image No. 1 and the background image No. 2 are converted into the gray image No. 1 background and the gray image No. 2 background, respectively;
S2、输送机构1将待检测口罩输送至一号检测位处,通过图像采集机构2在一号检测位处采集含有待检测口罩的一号检测图,图像处理软件6对一号检测图进行识别、并与预设的口罩标准进行对比,若判断为不良品,则将待检测口罩通过分选机构4作不良品收集,若判断为良品,则进行下一步骤;S2. The conveying mechanism 1 conveys the mask to be detected to the No. 1 detection position. The image acquisition mechanism 2 collects the No. 1 detection map containing the mask to be detected at the No. 1 detection position. The image processing software 6 recognizes the No. 1 detection map And compare with the preset mask standard. If it is judged as a defective product, the mask to be detected is collected as a defective product through the sorting mechanism 4. If it is judged as a good product, the next step is performed;
S3、通过翻转机构3对良品进行翻转180°,输送机构1将翻转180°后的良品输送至二号检测位处;S3. The good product is turned 180 ° through the turning mechanism 3, and the conveying mechanism 1 conveys the good product turned 180 ° to the second detection position;
S4、图像采集机构2在二号检测位处采集含有良品的二号检测图,图像处理软件6对二号检测图进行识别、并与预设的口罩标准进行对比,若判断为不良品,则作不良品收集,若判断为良品,则作良品收集。S4. The image collection mechanism 2 collects the second inspection map containing good products at the second inspection location. The image processing software 6 recognizes the second inspection map and compares it with the preset mask standard. If it is judged as a defective product, Collect defective products. If judged as good products, collect good products.
在本实施例中,步骤S2具体包括以下处理步骤:S21、将一号检测图的四个顶点标记为P1(0,0)、P2(w,0)、P3(0,h)、P4(w,h)和中心点Pc0(w/2,h/2),并通过图像处理软件6将一号检测图转换为一号检测灰度图;In this embodiment, step S2 specifically includes the following processing steps: S21. Mark the four vertices of the No. 1 detection map as P1 (0, 0), P2 (w, 0), P3 (0, h), P4 ( w, h) and the central point Pc0 (w / 2, h / 2), and through the image processing software 6, the No. 1 detection map is converted into the No. 1 detection gray map;
S22、将一号检测灰度图与一号背景灰度图进行图像前景处理得到口罩正面灰度图,并对口罩正面灰度图进行图像二值化处理得到口罩正面二值化图像;其中,口罩正面灰度图的中心点为Pc1(cx,cy);S22. Perform image foreground processing on the grayscale image of No. 1 detection and the grayscale image of the background of No. 1 to obtain a grayscale image on the front of the mask, and binarize the grayscale image on the front of the mask to obtain a binary image on the front of the mask; The center point of the grayscale image on the front of the mask is Pc1 (cx, cy);
S23、将口罩正面二值化图像进行固定次数的图像膨胀处理和图像腐蚀处理,并采用轮廓提取算法提取口罩正面轮廓,选择其中面积最大的口罩正面轮廓,对最大口罩正面轮采用最小外接矩形算法提取口罩正面的第一最小外接矩形;S23. Perform a fixed number of image dilation and image erosion on the frontal binarized image of the mask, and use the contour extraction algorithm to extract the frontal contour of the mask, select the frontal contour of the mask with the largest area, and use the smallest external rectangle algorithm for the largest frontal wheel of the mask Extract the first smallest circumscribed rectangle on the front of the mask;
S24、若第一最小外接矩形提取失败,则判断无口罩处理;若第一最小外接矩形提取成功,计算出第一最小外接矩形的长度值和宽度值,将长度值和宽度值与分别与预设的口罩标准相减得到长度差值和高度差值,若长度差值和/或高度差值超出预定的口罩标准范围,则判为不良品,反之,进行下一步骤。S24. If the extraction of the first minimum circumscribed rectangle fails, it is judged that there is no mask processing; if the extraction of the first minimum circumscribed rectangle is successful, the length and width values of the first minimum circumscribed rectangle are calculated, and the length and width values are compared with the pre-respectively. The set mask standard is subtracted to obtain the length difference and height difference. If the length difference and / or height difference exceeds the predetermined mask standard range, it is judged as a defective product, otherwise, the next step is performed.
S25、输出第一最小矩形的四个顶点坐标P11、P12、P13、P14,和中心点坐标Pc1(cx,cy),计算出连线L1(P13,P14)与连线L2(P3,P4)之间的夹角A1,计算出中心点 Pc1(cx,cy)相对于中心点Pc0(w/2,h/2)之间的水平方向偏移量Hx1和垂直方向偏移量Vy1;S25. Output the four vertex coordinates P11, P12, P13, P14 of the first smallest rectangle, and the center point coordinates Pc1 (cx, cy), calculate the line L1 (P13, P14) and the line L2 (P3, P4) Between the included angle A1, the horizontal offset Hx1 and the vertical offset Vy1 between the center point Pc1 (cx, cy) and the center point Pc0 (w / 2, h / 2) are calculated;
S26、对一号检测灰度图在水平方向上平移Hx1,在垂直方向上平移Vy1,以使中心点Pc1(cx,cy)和中心点Pc0(w/2,h/2)重合,得到一号检测灰度平移图;其中,一号检测灰度平移图的四个顶点为P21、P22、P23、P24,和中心点坐标Pc2(cx,cy),此时cx与w/2值相等,cy与h/2值相等;S26. The grayscale image of No. 1 is translated by Hx1 in the horizontal direction and Vy1 in the vertical direction, so that the central point Pc1 (cx, cy) and the central point Pc0 (w / 2, h / 2) coincide, and a No. 1 detection gray shift map; among them, the four vertices of No. 1 detection gray shift map are P21, P22, P23, P24, and the center point coordinates Pc2 (cx, cy), at this time cx is equal to w / 2 value, The cy and h / 2 values are equal;
S27、将一号检测灰度平移图以中心点Pc0(w/2,h/2)为原点进行旋转,旋转角度为夹角A1的度数,得到一号检测灰度旋转图;其中,一号检测灰度旋转图的四个顶点为P31、P32、P33、P34,中心点为Pc2(cx,cy);S27. Rotate the No.1 detection grayscale translation image with the center point Pc0 (w / 2, h / 2) as the origin, and the rotation angle is the degree of the included angle A1, to obtain the No.1 detection grayscale rotation image; The four vertices of the grayscale rotation map are P31, P32, P33, P34, and the center point is Pc2 (cx, cy);
S28、对一号检测灰度旋转图与预设的口罩标准进行对比判断,若判断为不良品,则将待检测口罩通过分选机构4作不良品收集,若判断为良品,则作良品收集。S28. Compare and judge the grayscale rotation image of No. 1 detection with the preset mask standard. If it is judged to be a defective product, the mask to be detected is collected by the sorting mechanism 4 as a defective product. If it is judged as a good product, it is collected as a good product. .
在本实施例中,步骤S28包括以下对比判断步骤:In this embodiment, step S28 includes the following comparison judgment step:
S281、采用预先设置的两个耳带检测规则框E1对口罩正面的耳带缺陷进行检测:采用轮廓提取算法对耳带检测区域的耳带图像轮廓属性进行计算和判断,若耳带图像轮廓属性不在预定的口罩标准范围内,则判断为耳带不良;S281. Use two preset earband detection rule frames E1 to detect the earband defects on the front of the mask: use the contour extraction algorithm to calculate and judge the outline attributes of the earband image in the earband detection area. If it is not within the predetermined mask standard range, it is determined that the ear strap is bad;
S282、采用预先设置的脏污检测规则框D1对口罩正面的脏污缺陷进行检测:采用固定阈值二值化处理算法对脏污检测区域进行处理,统计二值化处理后图像内零点数量,若零点数量不在预定的口罩标准范围内,则判断为脏污不良;S282. Use the pre-set dirt detection rule frame D1 to detect the dirt defects on the front of the mask: use a fixed threshold binarization algorithm to process the dirt detection area, and count the number of zeros in the image after binarization. If the number of zero points is not within the predetermined mask standard range, it is judged to be dirty;
S283、采用预先设置的鼻条检测规则框N1对口罩正面的鼻条缺陷进行检测:采用轮廓提取算法对鼻条检测区域的鼻条图像轮廓属性进行计算和判断,若鼻条图像轮廓属性不在预设的口罩标准范围内,则判断为鼻条不良,若鼻条图像轮廓的属性在预设的口罩标准范围内,则采用最小外接矩形算法计算出鼻条的最小外接矩形,并输出鼻条的最小外接矩形的四个顶点坐标和中心点坐标,判断鼻条的最小外接矩形的四个顶点坐标和中心点坐标是否在预设的口罩标准范围之内,若不在预设的口罩标准范围之内,则判断为鼻条不良;当一号检测位处的待检测口罩均未出现耳带不良、脏污不良和鼻条不良时,则待检测口罩为良品。其中,步骤S281、S282、S283的检测顺序不分先后。S283. Use the preset nose strip detection rule frame N1 to detect the nose strip defects on the front of the mask: use the contour extraction algorithm to calculate and judge the contour attributes of the nose strip image in the nose strip detection area. Within the standard range of the mask, it is determined that the nose strip is bad. If the attribute of the contour of the nose strip image is within the preset standard range of the mask, the minimum circumscribed rectangle algorithm is used to calculate the minimum circumscribed rectangle of the nose strip, and the minimum output The coordinates of the four vertices and the center point of the circumscribed rectangle determine whether the coordinates of the four vertices and the center point of the smallest circumscribed rectangle of the nose bar are within the preset standard range of the mask, if they are not within the preset standard range of the mask, It is judged that the nose strip is bad; when none of the masks to be tested at the detection position No. 1 have bad ear straps, dirty dirt and bad nose strips, the mask to be tested is good. The detection order of steps S281, S282, and S283 is in no particular order.
在本实施例中,步骤S4和步骤S2的处理过程和方式均相同,附图同样相同,在此不再提供。其中,步骤S4中包括以下处理步骤:S41、将二号检测图的四个顶点同样标记为P1(0,0)、P2(w,0)、P3(0,h)、P4(w,h)和中心点Pc0(w/2,h/2),并通过图像处理软件6将二号检测图转换为二号检测灰度图;In this embodiment, the processing procedures and methods of step S4 and step S2 are the same, and the drawings are also the same, which will not be provided here. Among them, step S4 includes the following processing steps: S41, the four vertices of the second detection map are also marked as P1 (0, 0), P2 (w, 0), P3 (0, h), P4 (w, h ) And the central point Pc0 (w / 2, h / 2), and through the image processing software 6 to convert the No. 2 detection map into the No. 2 detection grayscale map;
S42、将二号检测灰度图与二号背景灰度图进行图像前景处理得到口罩反面灰度图,并对口罩反面灰度图进行图像二值化处理得到口罩反面二值化图像;S42: Perform image foreground processing on the grayscale image of the second detection and the grayscale image of the second background to obtain the grayscale image of the reverse side of the mask, and perform binarization of the grayscale image of the reverse side of the mask to obtain a binary image of the reverse side of the mask;
S43、将口罩反面二值化图像进行固定次数的图像膨胀处理和图像腐蚀处理,并采用轮廓提取算法提取口罩反面轮廓,选择其中面积最大的口罩反面轮廓,对最大口罩反面轮采用最小外接矩形算法提取口罩反面的第二最小外接矩形;S43. Perform a fixed number of image dilation and image erosion processing on the reverse image of the mask, and use the contour extraction algorithm to extract the contour of the mask, select the contour of the mask with the largest area, and use the smallest external rectangle algorithm for the largest mask. Extract the second smallest circumscribed rectangle on the reverse side of the mask;
S44、若第二最小外接矩形提取失败,则判断无口罩处理;若第二最小外接矩形提取成功,计算出第二最小外接矩形的长度值和宽度值,将长度值和宽度值与分别与预设的口罩标准相减得到长度差值和高度差值,若长度差值和/或高度差值超出预定的口罩标准范围,则判为不良品,反之,进行下一步骤;S44. If the extraction of the second smallest circumscribed rectangle fails, it is judged that there is no mask processing; if the extraction of the second smallest circumscribed rectangle is successful, the length value and width value of the second smallest circumscribed rectangle are calculated, and the length value and the width value The set mask standard is subtracted to obtain the length difference and height difference. If the length difference and / or height difference exceeds the predetermined mask standard range, it will be judged as a defective product, otherwise, proceed to the next step;
S45、输出第二最小矩形的四个顶点坐标P11、P12、P13、P14,和中心点坐标Pc1(cx,cy),计算出连线L3(P13,P14)与连线L4(P3,P4)之间的夹角A2,计算出中心点 Pc1(cx,cy)相对于中心点Pc0(w/2,h/2)之间的水平方向偏移量Hx2和垂直方向偏移量Vy2;S45, output the four vertex coordinates P11, P12, P13, P14 of the second smallest rectangle, and the center point coordinates Pc1 (cx, cy), calculate the connection line L3 (P13, P14) and the connection line L4 (P3, P4) Between the included angle A2, the horizontal offset Hx2 and the vertical offset Vy2 between the center point Pc1 (cx, cy) and the center point Pc0 (w / 2, h / 2) are calculated;
S46、对一号检测灰度图在水平方向上平移Hx2,在垂直方向上平移Vy2,以使中心点Pc1(cx,cy)和中心点Pc0(w/2,h/2)重合,得到二号检测灰度平移图;S46. The grayscale image of No. 1 is translated by Hx2 in the horizontal direction and Vy2 in the vertical direction, so that the center point Pc1 (cx, cy) and the center point Pc0 (w / 2, h / 2) coincide, and two No. detection grayscale shift map;
S47、将二号检测灰度平移图以中心点Pc0(w/2,h/2)为原点进行旋转,旋转角度为夹角A2的度数,得到二号检测灰度旋转图;S47. Rotate the No. 2 detection grayscale translation map with the center point Pc0 (w / 2, h / 2) as the origin, and the rotation angle is the degree of the included angle A2, to obtain the No.2 detection grayscale rotation map;
S48、对二号检测灰度旋转图与预设的口罩标准进行如下对比判断:S48. Compare and judge the grayscale rotation map of No. 2 detection with the preset mask standard as follows:
采用预先设置的两个耳带检测规则框E1对口罩反面的耳带缺陷进行检测:采用轮廓提取算法对耳带检测区域的耳带图像轮廓属性进行计算和判断,若耳带图像轮廓属性不在预定的口罩标准范围内,则判断为耳带不良;Use the preset two earband detection rule frames E1 to detect the earband defects on the reverse side of the mask: use the contour extraction algorithm to calculate and judge the earband image outline attributes of the earband detection area, if the earband image outline attributes are not predetermined Within the standard range of the mask, it is judged that the ear strap is bad;
采用预先设置的脏污检测规则框D1对口罩反面的脏污缺陷进行检测:采用固定阈值二值化处理算法对脏污检测区域进行处理,统计二值化处理后图像内零点数量,若零点数量不在预定的口罩标准范围内,则判断为脏污不良;Use the pre-set dirt detection rule frame D1 to detect the dirt defects on the reverse side of the mask: use a fixed threshold binarization algorithm to process the dirt detection area, count the number of zeros in the image after the binarization, if the number of zeros If it is not within the predetermined mask standard, it is judged to be dirty;
采用预先设置的鼻条检测规则框N1对口罩反面的鼻条缺陷进行检测:采用轮廓提取算法对鼻条检测区域的鼻条图像轮廓属性进行计算和判断。若鼻条图像轮廓属性不在预设的口罩标准范围内,则判断为鼻条不良,若鼻条图像轮廓的属性在预设的口罩标准范围内,则采用最小外接矩形算法计算出鼻条的最小外接矩形,并输出最小外接矩形的四个顶点坐标和中心点坐标,判断最小外接矩形的四个顶点坐标和中心点坐标是否在预设的口罩标准范围之内,若不在预设的口罩标准范围之内,则判断为鼻条不良;当二号检测位处的待检测口罩均未出现耳带不良、脏污不良和鼻条不良时,则待检测口罩为良品。The nose strip detection rule frame N1 set in advance is used to detect the nose strip defects on the reverse side of the mask: the contour extraction algorithm is used to calculate and judge the contour attributes of the nose strip image in the nose strip detection area. If the contour attribute of the nose strip image is not within the preset mask standard range, it is determined that the nose strip is bad. If the attribute of the contour image of the nose strip is within the preset mask standard range, the minimum external rectangle algorithm is used to calculate the minimum external connection of the nose strip Rectangle, and output the coordinates of the four vertices and center of the smallest circumscribed rectangle to determine whether the coordinates of the four vertices and the coordinates of the center of the smallest circumscribed rectangle are within the preset standard range of the mask, if they are not within the preset standard range of the mask It is judged that the nose strip is bad; when the mask to be tested at the second detection position does not show bad ear straps, dirty dirt and bad nose strips, the mask to be tested is good.
在本实施例中,图像前景处理包括:将一号检测灰度图与一号背景灰度图的同一位置的像素值进行相减得到第一绝对值,将二号检测灰度图与二号背景灰度图的同一位置的像素值相减得到第二绝对值。若第一绝对值在预设的口罩标准范围内,则该位置的像素值设为255;否则,若第一绝对值大于预设的口罩标准范围,则该位置的像素值使用一号检测灰度图的像素值。若第二绝对值在预设的口罩标准范围内,则该位置的像素值设为255;否则,若第二绝对值大于预设的口罩标准范围,则该位置的像素值使用二号检测灰度图的像素值。In this embodiment, the image foreground processing includes: subtracting the pixel values at the same position of the grayscale image No. 1 and the grayscale background image No. 1 to obtain the first absolute value, and detecting the grayscale image No. 2 and No. 2 The pixel values at the same position of the background grayscale image are subtracted to obtain the second absolute value. If the first absolute value is within the preset mask standard range, the pixel value at that position is set to 255; otherwise, if the first absolute value is greater than the preset mask standard range, the pixel value at that position is The pixel value of the degree graph. If the second absolute value is within the preset mask standard range, the pixel value at that position is set to 255; otherwise, if the second absolute value is greater than the preset mask standard range, then the pixel value at that position uses the No. 2 detection gray The pixel value of the degree graph.
本发明实施例提供的在线口罩检测装置及方法对待检测口罩自动输送,检测待检测口罩的正面与反面,从而具体检测效率高、自动化程度高的优点。The on-line mask detection device and method provided by the embodiments of the present invention automatically transport the mask to be detected, and detect the front and back sides of the mask to be detected, thereby achieving the advantages of high specific detection efficiency and high degree of automation.