主要需要用到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));  写日期时间

实际效果:

利用Emgu cv3.4制作视频监控,自己做行车记录一样

重要代码如下:

如需定时更新,增加计时的功能,更改名字

 

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

        }

 

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2021-07-22
  • 2021-11-22
  • 2021-10-05
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
猜你喜欢
  • 2021-10-27
  • 2022-12-23
  • 2022-02-24
  • 2021-11-30
  • 2022-02-20
  • 2021-11-08
相关资源
相似解决方案