Код: Выделить всё
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YCamera
{
public class CameraRecoding
{
public static void run()
{
VideoCapture video = new VideoCapture(0);
string last_dstr = "";
VideoWriter videoWriter = null;
while (true)
{
string dstr = DateTime.Now.ToString("yyyyMMddHHmm");
string new_dir = Global_Vals.save_dir;
//record a file per 10 minutes
if (last_dstr==""||dstr.Substring(0,11) != last_dstr.Substring(0,11))
{
if(videoWriter != null)
{
videoWriter.Dispose();
videoWriter = null;
}
string new_file = System.IO.Path.Combine(new_dir, "video" + dstr + ".avi");
videoWriter = new VideoWriter(new_file,
VideoWriter.FourCC(@"XVID"), 20, new Size(640, 480), true);
if (!video.IsOpened())
{
Console.WriteLine("camera open failed");
return;
}
}
Mat Camera = new Mat();
video.Read(Camera);
if (Camera.Empty())//
{
break;
}
videoWriter.Write(Camera);
last_dstr = dstr;
}
}
}
}
Код: Выделить всё
video.Read(Camera);
Подробнее здесь: https://stackoverflow.com/questions/787 ... e-per-file