主要需要用到Capture类,VideoWriter,对象构造函数如下:
public Capture(int camIndex);----用于初始化摄像头。
public VideoWriter(string fileName, int fps, Size size, bool isColor);-----建立视频生产文件。
主要用到函数:
public virtual bool Retrieve(IOutputArray image, int channel = 0); //生成图像
public void Write(Mat frame); 写对象:
CvInvoke.PutText(tu1, DateTime.Now.ToString(), new Point(50, 50), Emgu.CV.CvEnum.FontFace.HersheyPlain, 1, new MCvScalar(0, 0, 255)); 写日期时间
实际效果:
重要代码如下:
如需定时更新,增加计时的功能,更改名字
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util.TypeEnum;
namespace lablecheck
{
public partial class capter_test : Form
{
public capter_test()
{
InitializeComponent();
cap1 = new Capture();
cap1.ImageGrabbed+=new EventHandler(cap1_ImageGrabbed);
wr1 = new VideoWriter("1.avi", 30, new Size(cap1.Width, cap1.Height), true);
cap1.Start();
}
VideoWriter wr1 = null;
Capture cap1 = null;//摄像头r
private void cap1_ImageGrabbed(object sender, EventArgs e)
{
try
{
Mat tu1 = new Mat();
cap1.Retrieve(tu1);
CvInvoke.PutText(tu1, DateTime.Now.ToString(), new Point(50, 50), Emgu.CV.CvEnum.FontFace.HersheyPlain, 1, new MCvScalar(0, 0, 255));
wr1.Write(tu1);
imageBox1.Image = tu1;
}
catch
{
wr1.Dispose();
}
}