【发布时间】:2019-02-04 22:20:48
【问题描述】:
我正在开发类似于监控系统的 Windows Form App,并尝试同时捕获和保存视频。我可以从相机查看视频,但尝试保存视频时。生成一个空的视频文件。
由于我是 emguCV 的新手,所以我被卡住了,无法解决。
这是我尝试过的
VideoCapture videoCapture;
double totalFrames;
double fps;
VideoWriter videoWriter;
DateTime dateTime;
int i;
public Body()
{
InitializeComponent();
i = 0;
if (videoCapture == null)
{
dateTime = new DateTime();
dateTime = DateTime.Now;
videoCapture = new Emgu.CV.VideoCapture(0);
}
videoCapture.ImageGrabbed += VideoCapture_ImageGrabbed;
videoCapture.Start();
}
private void VideoCapture_ImageGrabbed(object sender, EventArgs e)
{
Mat m = new Mat();
videoCapture.Retrieve(m);
pictureBox1.Image = m.ToImage<Bgr, byte>().Bitmap;
totalFrames = videoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
fps = videoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
if (videoCapture == null)
{
return;
}
else
{
int fourcc = Convert.ToInt32(videoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FourCC));
int frameHeight = Convert.ToInt32(videoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight));
int frameWidth = Convert.ToInt32(videoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth));
string destination = "C:\\Users\\ITNOA\\Desktop\\savedVideoDHS\\" + i+".mp4";
videoWriter = new VideoWriter(destination, fourcc, fps, new Size(frameWidth, frameHeight), true);
videoWriter.Write(m);
}
}
private void videoSavingtimer_Tick(object sender, EventArgs e)
{
videoCapture = null;
i++;
if (videoWriter.IsOpened)
{
videoWriter.Dispose();
}
}
有什么帮助吗?
谢谢。
【问题讨论】:
标签: c# video save video-capture emgucv