基于PC的在线图像识别及控制方法研究毕业论文
2021-03-29 21:59:44
摘 要
近年来人们对于健康卫生愈加重视,纸杯作为一般生活用品早已深入到各个公共场所和普通消费者家庭中。而纸杯属于消耗品,人们使用纸杯愈加常态化,生产纸杯的企业需要提高生产效率,但随着近年来人工成本的上升,纸杯生产线上主要使用人工检测,而且人们对于纸杯也提出了更高的质量标准,导致企业面临着一系列问题。并且人工检测存在的问题如效率低,速度慢,成本高等,使得人工检测已经不能满足纸杯生产企业的要求。而随着机器视觉在线检测技术的不断发展和很多案例的成功应用,本文从机器视觉的角度,通过PC的平台使用C Builder软件来开发质量检测系统。主要针对纸杯杯口的圆度变形,杯底和侧壁是否有污渍这两类问题。应用图像处理识别等知识来对纸杯图像进行分析,从而判断纸杯是否有质量问题,并可以通过PC平台直接驱动步进电机进行相应的动作,实现检测过程的自动化。
本论文完成的主要工作如下:
1.对于杯口圆度变形程度检测就是判断纸杯杯口外轮廓的圆度。首先对于纸杯图像进行二值化处理,通过应用OSTU算法来自适应地确定阈值,将纸杯内外区域区分出来,再应用基于Freeman链码的轮廓表示法追踪外轮廓边界,利用链码表存储外轮廓的所有坐标信息,最后介绍了两种判断圆度变形的方法。采用了通过一定数量的外轮廓坐标来拟合圆的方法,比较所有杯口外轮廓点坐标到圆心坐标的距离与半径的偏差大小来判断杯口的圆度变形是否合格。
2.对于污渍的检测是基于污渍相对于纸杯其他区域的灰度值较低和污渍的边缘处会有明显的灰度值较高的污渍轮廓的基本原理,首先通过Sobel边缘检测算子处理,将污渍的边缘信息显现出来,然后进行膨胀腐蚀处理去除无关的杂点和噪声的影响,最后对于纸杯内部区域的联通部分进行区域标记,排除了背景杂点的影响,通过对联通区域的分析来判断污渍是否存在。
3.运动控制主要是通过对计算机串口进行二次开发,直接改变串口引脚电平来作为步进电机驱动器的控制信号。采用了多媒体定时器来提供高精度的定时作用,实现了计算机对于步进电机的实时控制,并且在没有串口的笔记本上应用USB转RS232转换线同样成功地实现了对步进电机的控制。当图像检测系统检测到纸杯图像的质量问题时便产生一个信号,随之PC就直接驱动步进电机转动一圈。
关键词:机器视觉;C Builder;圆度变形检测;污渍检测;运动控制
Abstract
In recent years, people pay more attention to health and hygiene,and paper cups have already penetrated into various public places and ordinary consumer families as a general daily necessities. Paper cups are consumables, so people use paper cups become more normal, the production of paper cups enterprises need to improve production efficiency. But with the increase in labor costs in recent years, the paper cup production line mainly uses manual detection, and people also put a higher quality standard for paper cups, leading enterprises to face a series of problems. Manual detection has some problems, such as low efficiency, slow, and high cost, making manual detection has been unable to meet the requirements of paper cup manufacturers. With the continuous development of machine vision online detection technology and the successful application of many cases, this paper using C Builder software through the PC platform to develop quality inspection system from the perspective of machine vision. Mainly for two problems: the roundness of the degree of paper cup, whether the bottom of the cup and side walls are stained. Apply image processing, image identification and other knowledge to analysis the paper cup image, then determine whether the quality of paper cups, the system can drive the stepper motor directly for the corresponding action through the PC platform, and achieve the automation of detection process.
The main work done in this paper is as follows:
1. Detecting the degree of the roundness of paper cup by determining the roundness of the outer contour of the paper cup. Firstly, binarizing the paper cup image, then applying the OSTU algorithm to adaptively determine the threshold, distinguish the inside and outside of the paper cup image. Applying contour representation based on Freeman chain code to track the outer contour boundary, Use the chain code table to store all the coordinate information of the outer contour. Finally, two methods of judging roundness deformation are introduced, and the method of a number of outer contour coordinates to fit the circle is adopted. Then comparison of the distance between all the coordinates of the outer edge of cup to the center of the circle to generate the deviation of the radius is used to determine whether the roundness of the cup is qualified according to the deviation.
2. The detection of stains based on the two basic principles, the gray value of the stain relative to the other areas of the paper cup is lower and the edges of the stain will have a clear gray profile of the stains. Firstly, the edge information of the stain is displayed by the Sobel edge detection operator. Then, irrelevant miscellaneous points and the effects of noise through the expansion of the corrosion treatment are removed. Finally, the area of the paper inside the joint part of the regional is marked, excluding the impact of background noise. Through the analysis of the connected region to determine whether the stain exists.
3. Motion control is mainly through the secondary development of the computer serial port. Change the serial port pin level directly as a stepper motor driver control signal. Using a multimedia timer to provide high-precision timing effects and realized the real-time control of the computer for stepper motor. The approach also works on notebook that is absence of serial port by applying the USB to RS232 conversion line. A signal is generated when the image detection system detects the quality problem of the paper cup image, then PC directly drives the stepper motor to rotate in one turn.
Key Words: machine vision, C Builder, roundness deformation detection, stain detection, motion control
目 录
第1章 绪论 1
1.1 问题的提出 1
1.2 机器视觉系统的发展现状 1
1.3 基于PC的运动控制器 2
1.4 机器视觉在线检测系统的优点 2
1.5 本文的主要内容 3
第2章 基于PC的整体方案设计 4
2.1 软件部分 4
2.2 硬件部分 6
第3章 杯口圆度变形检测 7
3.1 图像二值化 7
3.1.1 阈值确定 7
3.1.2 最大类间方差阈值分割 8
3.2 轮廓追踪 9
3.2.1 轮廓表示法 10
3.2.2 Freeman链码 10
3.2.3 周围像素点的链码值 11
3.2.4 确定搜索方向 11
3.2.5 轮廓追踪算法及实现 12
3.3 杯口圆度变形判断 13
3.3.1 圆形度判断 13
3.3.2 基于半径差的圆度变形程度判断 14
第4章 污渍检测 17
4.1 常见边缘检测算子 17
4.1.1 一阶微分算子 17
4.1.2 二阶微分算子 18
4.2 膨胀、腐蚀处理 19
4.3 区域标记 20
4.4 污渍判断及框选污渍 21
第5章 运动控制 22
5.1 系统组成 22
5.2 计算机串行口介绍及引脚定义 22
5.3 引脚控制方法介绍 22
5.3.1 电机转速(转/分)与定时器时间(毫秒)的转换 23
5.3.2 定时器选择 24
5.4 串口与驱动器连接图 24
5.5 基于图像识别的质量控制系统流程 25
第6章 总结与展望 26