- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试了以下方法以每秒 25 帧速率从网络摄像头录制视频,持续 10 秒,但是当我得到输出视频时,它是 2 秒,并且与视频流相比,帧的播放速度更快。
代码如下。
using System;
using System.Drawing;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
using System.Threading;
using AForge.Video.FFMPEG;
namespace AforgeTutorial
{
public partial class Form1 : Form
{
private FilterInfoCollection ListOfCams;
private VideoCaptureDevice SelectedCam; //From where we will take image
System.Timers.Timer tim;
Thread t;
bool isNewFrame = false;
VideoFileWriter writer;
public Form1()
{
InitializeComponent();
tim = new System.Timers.Timer(10000);
tim.Elapsed += new System.Timers.ElapsedEventHandler(tim_Elapsed);
t = new Thread(saveVideo);
}
void tim_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (isRecord)
{
writer.Close();
isRecord = false;
}
}
private void Form1_Load(object sender, EventArgs e)
{
ListOfCams = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (ListOfCams.Count == 0)
return;
comboBox1.Items.Clear();
foreach (FilterInfo Cam in ListOfCams)
{
comboBox1.Items.Add(Cam.Name);
}
}
private void StopCamera()
{
SelectedCam.SignalToStop();
SelectedCam.Stop();
}
bool isRecord = false;
private void Start_Click(object sender, EventArgs e)
{
if (comboBox1.Text == string.Empty)
return;
SelectedCam = new VideoCaptureDevice(ListOfCams[comboBox1.SelectedIndex].MonikerString);
SelectedCam.NewFrame += new NewFrameEventHandler(SelectedCam_NewFrame);
SelectedCam.Start();
}
Bitmap image;
void SelectedCam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
image = (Bitmap)eventArgs.Frame.Clone();
isNewFrame = true;
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
StopCamera();
}
private void Stop_Click(object sender, EventArgs e)
{
StopCamera();
}
private void btnRecord_Click(object sender, EventArgs e)
{
tim.Start();
if (!isRecord)
{
writer = new VideoFileWriter();
writer.Open(@"C:/code-bude_test_video.mp4", 640, 480, 25, VideoCodec.MPEG4,10000);
}
isRecord = !isRecord;
if (isRecord)
t.Start();
}
void saveVideo()
{
while (isRecord)
{
if (isNewFrame)
{
writer.WriteVideoFrame(image);
isNewFrame = false;
}
}
}
}
}
最佳答案
您的代码中存在多线程问题。您不能像那样写入共享变量并期望它同步。
您有三个线程:用户界面、流式传输和保存。 (SelectedCam_NewFrame 在 AForge 流线程中运行)。列出至少在两个线程(isRecord、isNewFrame 等)中访问的所有变量并添加适当的同步。
您可以在 threading in C# 上查看这个非常好的引用资料.
请注意,即使使用同步,如果您的编写器线程在多个图像到达时很忙,您也可能会丢失帧。您可能想要做的是将相机产生的帧收集到一个队列中,并在写入线程中使用该队列。检查生产者/消费者模式。
关于c# - c#中使用AFORGE录制视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25158542/
我目前正在做一个“自动车牌检测和识别”,我正在使用 AForge.Net;我使用了一个简单的算法; 虽然它不是很有效,但它会满足我的要求。我已经计算出高度、宽度和高度与宽度(高度/宽度)的比率超过40
我的 WinForms .NET 4 C# 应用程序在用户与其交互时记录桌面。 它根据系统的速度使用 AForge FFMPEG 或 VFW 包装器。当然,捕获是在后台线程中完成的。 无论哪种情况,包
我已经编写了一些需要处理大约 3000 张图像的 C# 代码,但是到第 500 张图像时,任务管理器显示该程序使用了 1.5GB 的内存。下面的功能似乎是罪魁祸首之一。我可以在这里做得更好吗?任何帮助
我正在使用 Aforge .NET 框架在我的应用程序中获取网络摄像头,但我总是得到一个全灰色的图像框架。 this.videoSource = new VideoCaptur
我正在玩 AForge。我从 AForge 网站复制粘贴了示例。 using System; using System.Collections.Generic; using System.Linq;
我正在尝试在 Unity 中使用 AForge,但在转换输入数据时遇到了问题。我有一个二维数组,用于存储需要转换为 UnmanagedImage 的像素值。我想出了以下代码,但我不确定它是否是最有效的
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我正在尝试学习 Aforge.net。我写了 o 代码,它工作正常,但我只想在我的图像上检测到紫色,但我找不到它是怎么回事。所以任何人都可以帮助我吗?这是我的代码 Bitmap resim = new
有人可以给我一个完整的例子,使用这个用 VB.NET 或 C# 编写的库在 picturebox 中显示流的图像 最佳答案 这是一个非常非常简单的表单,它使用了 AForge.Video.MJPEGS
如何使用此方法: public static void DFT (Complex[] data, Direction direction) 如果我的输入数组是short[] samples?我可以轻松
我正在尝试使用 Aforge.net 开发一个 LPR 系统,我想在我的图像上应用一个过滤器,正如您在此处看到的: Bitmap a = new Bitmap(@"C:\Use
我需要一些帮助将视频从笔记本电脑相机保存到文件。现在我使用代码来搜索图片框上的视频设备和以前的视频。 我试过 AVIFileWrite 但我失败了。 如何使用 VideoFileWriter 来实现我
我正在尝试从视频文件中提取特定帧。当我使用 aforge 库播放视频文件时,我有一个想要的帧。我调用了一个新帧事件,如果新帧与我的特定帧匹配,那么它会显示一条消息:“帧匹配”。此特定帧随机出现在视频文
我尝试使用 AForge 在 C# 中使用 IP 摄像机做一个录制功能,但我无法真正理解编码,因为我是一个新学习者。录制的视频将保存在我的电脑中。 据我所知,此功能是编写/创建视频并将其保存在我的存储
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我正在尝试检测这张图片上的矩形: 使用此代码: static void Main(string[] args) { // Open your image string path = "
我正在使用 AForge 进行运动检测,并且我知道可以设置运动区域。是否可以让它仅在所有定义区域中有运动时触发?如果上面的功能不是现成的,我正在考虑编写它。 目前,我的理解是区域设置为视觉库中 Mot
我需要在图像上查找对象,因此我尝试使用 AForge 库来完成。我从非常简单的图案和图片开始,但识别准确度已经很糟糕了。我正在使用 ExhaustiveTemplateMatching: Exhaus
如何检测视频中的非移动 Blob ? 假设我有一个视频和一个初始背景帧位图。是否有可能检测到不移动的 Blob /对象?并围绕该对象绘制一个矩形? 最佳答案 这让我想起了一种检测地铁上遗忘元素的算法。
我正在尝试在 AForge 中检测矩形内的圆。我已成功确定 Rectangles,但无法在 Rectangle 中找到 circles。如何在 AForge 中找到另一个形状内的形状。 string
我是一名优秀的程序员,十分优秀!