【OpenCv/EmguCv】指针式仪表读数(一)
2017-10-27 21:50
991 查看
1. 预处理
1.1 双边滤波
img.SmoothBilatral(int val1,int val2,int,val3)
![](https://i.imgur.com/YYmemRE.png)
(原图)
![](https://i.imgur.com/sLbbLEi.png)
(双边滤波)
![](https://i.imgur.com/STydJw8.png)
(高斯滤波)
高斯滤波将整张图都变得模糊了,双边滤波则保留了清晰轮廓特征,效果比较好。
1.2 灰度并二值
img.Convert<Gray, byte>()//灰度化g
![](https://i.imgur.com/oH77AwC.png)
(灰度图)
ThresholdBinary(new Gray(Parameters.BinVal),new Gray(255));//二值化
![](https://i.imgur.com/DnFOUhl.png)
(二值图)
2. 指针提取
1.1 帧差法提取指针
用当前帧减去上一帧得到运动的指针图像。private Image<Gray,byte> SubBackground(Image<Gray,byte>pic) { Image<Gray, byte> gray = new Image<Gray, byte>(pic.Size); if (tag == 0) { Subbg[0] = pic;//背景帧(上一帧) tag = 1; return Subbg[0]; } else { Subbg[1] = pic; gray = Subbg[1] - Subbg[0];//当前帧减去背景帧(上一帧) Subbg[0] = Subbg[1]; } return gray; }
![](https://i.imgur.com/xd5f9eb.png)
(指针)
2.2 霍夫圆检测
对灰度图进行霍夫圆检测。private Image<Bgr, byte> CirclePic(Image<Gray, byte> pic) { Image<Bgr, byte> outpic = new Image<Bgr, byte>(pic.Size); //霍夫圆检测 CircleF[] circle = CvInvoke.HoughCircles(pic, Emgu.CV.CvEnum.HoughType.Gradient, 10, 1000); foreach (CircleF c in circle) { CvInvoke.Circle(outpic, new Point((int)c.Center.X, (int)c.Center.Y), (int)c.Radius, new MCvScalar(255, 255, 0), 5); center.X = (int)c.Center.X; center.Y = (int)c.Center.Y; radius = c.Radius; outpic.Draw(new CircleF(new PointF(center.X, center.Y), 5), new Bgr(255, 0, 255), 10); outpic.Draw(new LineSegment2D(new Point(0, center.Y), new Point(pic.Width, center.Y)), new Bgr(Color.Blue), 2); outpic.Draw(new LineSegment2D(new Point(center.X, 0), new Point(center.X, pic.Height)), new Bgr(Color.Blue), 2); outpic.Draw(new Point(center.X, center.Y).ToString(), new Point(center.X,center.Y), Emgu.CV.CvEnum.FontFace.HersheyComplexSmall, 1, new Bgr(255, 0, 255)); } return outpic; }
2.3 直线检测
对帧差法提取到的指针图像进行直线检测。检测到的结果包含多条直线,首先对长度不符合的进行过滤(这里排除长度小于70的线段),过滤后仍然包含多条线段,但是我们只需要一条,所以进行直线合并,只保留一条。
//返回直线端点的坐标 public Point AvrPoint(Point[] point) { Point outpoint = new Point(0, 0); int p_x = 0; int p_y = 0; int n = 0; foreach (Point p in point) { if (p.X != 0 && p.Y != 0) { p_x += p.X; p_y += p.Y; n++; } } if (n != 0) { p_x = p_x / n; p_y = p_y / n; } outpoint = new Point(p_x, p_y); return outpoint; }
2.4 绘制指针
以圆心为指针的一端,2.3中求得的线段端点为另一端绘制直线。并在同一张图片上绘制出圆心和圆(刻度盘)
![](https://i.imgur.com/nq225No.png)
相关文章推荐
- 【OpenCv/EmguCv】指针式仪表读数(二)
- OpenCV(EmguCV)2.1新特性介紹之圖像差異StereoSGBM與設置窗口屬性SetWindowProperty(StereoSGBM Of OpenCV 2.1)
- 完整opencv(emgucv)人脸、检测、采集、识别、匹配、对比
- OpenCv,EmguCv及.net之间的互动(The Interaction of OpenCv, EmguCv AND .net)
- Opencv EmguCv 基本识别步骤
- OpenCV、EmguCV之打开图片
- OpenCV(EmguCV)2.1新特性介绍之图像分割GrabCut(GrabCut Of OpenCV 2.1)
- EmguCV学习 与opencv的区别和联系
- EmguCV3.3(C# OpenCV)高清入门视频教程
- bgr转换为Hsv(Matlab、OpenCV、Emgucv)
- OpenCV中的结构体、类与EmguCV的对应表
- OpenCV(EmguCV)2.1新特性介绍之图像分割GrabCut(GrabCut Of OpenCV 2.1)
- OpenCv,EmguCv及.net之间的图像类型转换
- 使用emguCV/C# opencv绘制自定义直方图
- VS2010平台下的OpenCV、EmguCV( C#)安装、使用配置
- OpenCV与EmguCV中的图像轮廓提取
- c#下使用opencv—安装opencv及EmguCV(一)
- opencv与emgucv的参数传递
- OpenCV、EmguCV之保存图片
- EmguCV(OpenCV)实现高效显示视频(YUV)叠加包括汉字