EmguCV的一些代码笔记

 

以下是教程上有关读取摄像头和ImageViewer的使用方法

using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using System.Drawing;
using System.Windows.Forms;
...
 
ImageViewer viewer = new ImageViewer(); //create an image viewer
Capture capture = new Capture(); //create a camera captue
Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
{  //run this until application closed (close button click on image viewer)
   viewer.Image = capture.QueryFrame(); //draw the image obtained from camera
});
viewer.ShowDialog(); //show the image viewer


 

以下是查找边界的
                Contour<System.Drawing.Point> contour = imageTh.FindContours();
                Image<Bgr, Byte> imageResult = imageTh.Convert<Bgr, Byte>();
                imageResult.Draw(contour, new Bgr(System.Drawing.Color.Red), new Bgr(System.Drawing.Color.Green), 2, 2);
                if (contour != null)
                {
                    Seq<Point> dyContourPointsTemp = new Seq<Point>(contour.Ptr, contour.Storage);
                    for (; dyContourPointsTemp != null && dyContourPointsTemp.Ptr.ToInt32() != 0; dyContourPointsTemp = dyContourPointsTemp.HNext)
                    {
                        System.Drawing.Rectangle r = dyContourPointsTemp.BoundingRectangle;
                        System.Drawing.Point mass = new System.Drawing.Point((r.Left + r.Right) / 2, (r.Bottom + r.Top) / 2);

                        Ellipse mass2 = new Ellipse(mass, new System.Drawing.SizeF(2, 2), (float)Math.PI);
                        imageResult.Draw(mass2, new Bgr(System.Drawing.Color.Green), 2);

                    }
                }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值