我有以下代码,它可以非常快速地捕获视频并更新 jpg。
我需要将其更改为每 x seconds 捕获一帧,以便我可以对其执行其他操作,例如解码条形码:
using AForge.Video;
using AForge.Video.DirectShow;
namespace BAMSystem
{
public partial class WebForm1 : System.Web.UI.Page
{
public int FrameRate { get; set; }
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideo;
protected void Page_Load(object sender, EventArgs e)
{
inputDevices.Items.Clear();
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
{
inputDevices.Items.Add(VideoCaptureDevice.Name);
}
inputDevices.SelectedIndex = 0;
FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[inputDevices.SelectedIndex].MonikerString);
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
}
public void Start_OnClick(object sender, EventArgs e)
{
FinalVideo.Start();
}
void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
video.Save("C:\\Users\\Wayneio\\Desktop\\image\\live.jpg");
}
public void Stop_OnClick(object sender, EventArgs e)
{
if (FinalVideo.IsRunning)
{
FinalVideo.SignalToStop();
FinalVideo.Stop();
}
}