我正在使用Windows Form App,它类似于监视系统,并试图同时捕获和保存视频。我可以从摄像机查看视频,但是尝试保存视频时。生成了一个空的视频文件。
由于我是emguCV的新手,所以我陷入了困境,无法解决它。
这是我尝试过的
mapPostFromJson(data: any) : PostModel {
return map((post: PostModel) => {
return {
id: post.id,
created: new Date(post.created),
published: post.published,
title: post.title
};
});
}
有帮助吗?
谢谢。
答案 0 :(得分:0)
以下是使用emgu cv可以同时查看和保存视频的方式。
public Body()
{
InitializeComponent();
if (videoCapture == null)
{
videoCapture = new Emgu.CV.VideoCapture(0);
}
videoCapture.ImageGrabbed += VideoCapture_ImageGrabbed;
videoCapture.Start();
}
private void VideoCapture_ImageGrabbed(object sender, EventArgs e)
{
if (fileChanged)
{
totalFrames = videoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
fps = videoCapture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
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 + ".avi";
videoWriter = new VideoWriter(destination, VideoWriter.Fourcc('I', 'Y', 'U', 'V'), fps, new Size(frameWidth, frameHeight), true);
fileChanged = false;
}
Mat m = new Mat();
videoCapture.Retrieve(m);
pictureBox1.Image = m.ToImage<Bgr, byte>().Bitmap;
videoWriter.Write(m);
}
在上面的代码中,我需要将视频保存到多个文件中,正在重新初始化视频编写器。对于单个文件,应将其初始化一次。
我尝试了多种压缩代码,但以下内容对我有用
压缩代码VideoWriter.Fourcc('I','Y','U','V')
videoWriter =新的VideoWriter(目标,VideoWriter.Fourcc('I','Y','U','V'), fps,新的Size(frameWidth,frameHeight),true);
希望有帮助