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);

                    }
                }

發佈了60 篇原創文章 · 獲贊 11 · 訪問量 49萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章