![](/img/trans.png)
[英]Changing Framerate & System.Threading Aforge.video C# ASP.NET
[英]Capture Frame Not Video AForge C# ASP.NET
我有以下代码,它可以非常快速地捕获视频并更新 jpg。
我需要的是将其更改为每 x 秒捕获一帧,以便我可以对其进行其他操作,例如解码条形码:
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();
}
}
首先将 videoCaptureDevice.desiredFrameRate 设置为 1。这应该使 NewFrameEventHandler 每秒运行一次。 然后让 NewFrameEventHandler 在 num 之后做一些事情。 您想要的秒数(跳过或帧)。
如果您的相机不支持设置帧速率。 您可以使用全局变量,并且仅在该值 = true 时才执行,您可以通过 Visual Studio 中的简单计时器事件来执行此操作。
void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
{ if(mytimedevent) {
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
video.Save("C:\\Users\\Wayneio\\Desktop\\image\\live.jpg");
}
mytimedevent!=mytimedevent // or set it simply to false.
}
您还可以根据其他计算更改 mytimedevent 的值:如果完成,将其启用为 true,并在运行时将其设置为 false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.