以下是教程上有關讀取攝像頭和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);
}
}