我正在尝试编写一个应用程序,它可以访问连接到PC的摄像机,录制视频并从视频中获取图像.我使用AForge.NET库来访问摄像头:http://www.aforgenet.com/framework/
我不知道名为AForge.Video.NewFrameEventHandler的事件是如何工作的.在此代码中,事件将null返回到位图而不是视频中的新帧,或者不调用该事件.我希望每次都能从视频中获取帧到一个图片框,以制作类似于视频流的内容,点击停止按钮后,我希望最后一个图像保持显示在图片框中.有谁知道怎么样?为什么我的代码不起作用?
码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AForge.Video.DirectShow;
using System.Drawing;
using AForge.Video;
namespace CameraDevice
{
public class CameraImaging
{
// enumerate video devices
public FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice );
//camera
public VideoCaptureDevice videoSource;
//screen shot
public Bitmap bitmap;
public CameraImaging()
{
// create video source
VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString );
// set NewFrame event handler
videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
}
public void StartVideo(VideoCaptureDevice videoSource)
{
// start the video …Run Code Online (Sandbox Code Playgroud) 我正在写一个WPF应用程序,我需要显示一个Webcam feed.我能够使用AForge框架轻松完成这项工作.但是当我从计算机更改为另一台计算机时,相同的代码不能以相同的方式工作.
在第一个网络摄像头提供完美的工作,但在另一个,这不会发生,饲料有很多延迟,应用程序无法正常工作.
这是代码:
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, (SendOrPostCallback)delegate
{
IntPtr hBitmap = img.GetHbitmap();
System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(hBitmap);
img.Dispose();
GC.Collect();
image1.Source = bitmapSource;
}, null);
}
Run Code Online (Sandbox Code Playgroud)
这段代码非常简单,它以一种形式从网络摄像头获取一个new_frame Bitmap,我需要做的是将它转换为一个BitmapSource,所以我可以在WPF的图像框架中显示.我认为这种转换是造成这种混乱的原因,但我不明白为什么它在计算机中起作用而在另一种情况下却不起作用.
计算机规格几乎相同,处理器是相同的,以及系统内存.
我的问题是关于性能,这个代码在一台计算机上运行顺畅,网络摄像头提供应该呈现,当我将它移植到另一台PC时,这不会发生.
我在XNA上使用Kinect(Microsoft SDK).我想用GRATF进行标记识别
如何将Kinect的数据转换ColorImageFrame为System.Drawing.Bitmap或者AForge.Imaging.UnmanagedImage我可以使用GRATF处理它们?
void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
Bitmap bitmap = null;
ColorImageFrame frame = e.OpenColorImageFrame();
byte[] buffer = new byte[frame.PixelDataLength];
frame.CopyPixelData(buffer);
// how to convert the data in buffer to a bitmap?
var glyphs = recognizer.FindGlyphs(bitmap);
...
}
Run Code Online (Sandbox Code Playgroud) 好的,我一直在尝试通过网络摄像头做一些特定的视频.我有一个Lumenera Infinity 2显微镜,我试图从中提取饲料,并希望能够在进入时修改饲料.由于我找不到使用Video Source Player的方法,我决定改为拉动每个帧(相机的最大15fps)作为位图,以便我可以在那里进行修改.
问题是:我有一个巨大的内存泄漏.当我使用videoSourcePlayer运行视频时,它使用大约30兆的徘徊.当我将帧拉动为位图时,它会在几秒钟内打破1 gig的内存.
我错过了什么,这里?我认为自动垃圾收集会在旧框架无法访问时挖出旧框架.我应该尝试强制在位图上进行垃圾回收吗?或者它完全是另一回事,而且我还是错过了它.
FilterInfoCollection captureDevices;
VideoCaptureDevice cam;
Bitmap bitmap;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
captureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (captureDevices.Count == 0)
throw new ApplicationException();
CameraSelectComboBox.Items.Clear();
foreach (FilterInfo device in captureDevices)
{
CameraSelectComboBox.Items.Add(device.Name);
}
CameraSelectComboBox.SelectedIndex = 0;
CameraSelectComboBox.Enabled = true;
}
catch (ApplicationException)
{
CameraSelectComboBox.Enabled = false;
}
}
private void connectButton_Click(object sender, EventArgs e)
{
cam = new VideoCaptureDevice(captureDevices[CameraSelectComboBox.SelectedIndex].MonikerString);
cam.NewFrame -= Handle_New_Frame; //Just to avoid …Run Code Online (Sandbox Code Playgroud) 我目前正在与AForge合作,并有一个新的帧事件,将帧作为位图发布到图片框中.它有90%的时间很棒......除非我在winform上捣乱.更改组合框,移动窗口或任何类似的风险会导致Picturebox从视频切换到大红色X.下面的代码示例:
private void connectButton_Click(object sender, EventArgs e)
{
try
{
cam = new VideoCaptureDevice(captureDevices[CameraSelectComboBox.SelectedIndex].MonikerString);
cam.NewFrame -= Handle_New_Frame; //Just to avoid the possibility of a second event handler being put on
cam.NewFrame += new AForge.Video.NewFrameEventHandler(Handle_New_Frame);
cam.Start();
}
catch
{
MessageBox.Show("An error has occured with connecting to the specified webcam. The application will now close!");
Application.Exit();
}
}
private void Handle_New_Frame(object sender, NewFrameEventArgs eventArgs)
{
try
{
if (bitmap != null)
bitmap.Dispose(); //Without this, memory goes nuts
bitmap = new Bitmap(eventArgs.Frame);
} …Run Code Online (Sandbox Code Playgroud) 我有一个项目,我需要使用USB相机处理在非常近的范围(5毫米以下)获得的图像.由于可用空间很短,我不能使用辅助镜头.
我知道我可以在位图级别进行一些后期处理,但我希望能够在相机级别访问自动对焦或白平衡等属性.
我正在用AForge开发C#进行图像采集和后期处理,但在图像采集发生之前我似乎无法找到控制相机的方法.
你能帮助我吗?
我有跟踪扫描文档,上面有徽标,我有另一张黑白图像,标识和样式相同(下面以黑白色显示).
如何确保此图像上是否存在徽标?

通常我会有很多扫描文件,OCR会拾取MTNL,但有时这些徽标只是由OCR无法识别的符号组成.
徽标的大小和位置发生变化,它们不会多次修复.它们可以放在文档的任何位置.
我想根据存在的徽标和符号组织和编目扫描图像.大多数文件可能是也可能不是英文,可能包含也可能不包含任何条形码,在这种情况下,徽标匹配会有所帮助.
我见过Aforge.NET库,但我不太确定要将哪些方法组合起来进行搜索.如果源目标具有不同的大小,则像素搜索非常慢并且失败.
我听说YouTube会进行某种直方图或热门签名匹配,以查看该视频是否包含任何受版权保护的内容.如果有人能在这种情况下指导我,我会很有帮助.
我理想的选择是C#和Aforge.NET,否则一些命令行工具将不胜感激.
c# pattern-recognition image-processing pattern-matching aforge
我试图用C#中的Aforge.Net通过感知器进行OCR.我用九个30*30二进制图片学习了我的网络.但在结果中,它将所有内容都识别为"C".这是代码:
private void button1_Click(object sender, EventArgs e)
{
AForge.Neuro.ActivationNetwork network = new AForge.Neuro.ActivationNetwork(new AForge.Neuro.BipolarSigmoidFunction(2), 900, 3);
network.Randomize();
AForge.Neuro.Learning.PerceptronLearning learning = new AForge.Neuro.Learning.PerceptronLearning(network);
learning.LearningRate =1 ;
double[][] input = new double[9][];
for (int i = 0; i < 9; i++)
{
input[i] = new double[900];
}
//Reading A images
for (int i = 1; i <= 3; i++)
{
Bitmap a = AForge.Imaging.Image.FromFile(path + "\\a" + i + ".bmp");
for (int j = 0; j < 30; j++)
for (int k …Run Code Online (Sandbox Code Playgroud) 我正在开发一种用于微米级定位的自动对焦程序,因此我需要在图像之间找到非常小的聚焦/模糊差异.幸运的是,图像模式将始终相同(这些是原始2 MP图像的256x256中心裁剪):

Perfect focus | 50 µm off
Run Code Online (Sandbox Code Playgroud)
找到上面两个更好的聚焦图像不是问题,我想大多数算法都可以.但我真的需要比较焦点差异很小的图像,如下所示:

5 µm off | 10 µm off
Run Code Online (Sandbox Code Playgroud)
步进越来越接近最佳焦点的替代方案是找到在焦平面的相对侧具有相同量模糊的两个图像.例如,可以从-50μm保存图像,然后尝试在+50μm附近找到模糊相等的图像.假设图像在+58μm处发现,则焦平面应位于+4μm处.
有合适算法的想法吗?
我尝试创建一个文本视频,其中文本通过文本到语音进行叙述.
要创建的视频文件,我用VideoFileWriter的Aforge.Net是以下几点:
VideoWriter = new VideoFileWriter();
VideoWriter.Open(CurVideoFile, (int)(Properties.Settings.Default.VideoWidth),
(int)(Properties.Settings.Default.VideoHeight), 25, VideoCodec.MPEG4, 800000);
Run Code Online (Sandbox Code Playgroud)
要大声朗读文本,我使用SpeechSynthesizer类并将输出写入波流
AudioStream = new FileStream(CurAudioFile, FileMode.Create);
synth.SetOutputToWaveStream(AudioStream);
Run Code Online (Sandbox Code Playgroud)
我想突出显示视频中的单词,所以我通过SpeakProgress事件同步它们:
void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
{
curAuidoPosition = e.AudioPosition;
using (Graphics g = Graphics.FromImage(Screen))
{
g.DrawString(e.Text,....);
}
VideoWriter.WriteVideoFrame(Screen, curAuidoPosition);
}
Run Code Online (Sandbox Code Playgroud)
最后,我使用合并视频和音频 ffmpeg
using (Process process = new Process())
{
process.StartInfo.FileName = exe_path;
process.StartInfo.Arguments =
string.Format(@"-i ""{0}"" -i ""{1}"" -y -acodec copy -vcodec copy ""{2}""", avi_path, mp3_path, output_file);
// ...
}
Run Code Online (Sandbox Code Playgroud)
问题是,对于像微软Hazel,Zira和David这样的声音,在Windows 8.1中,视频与音频不同步,音频比显示的字幕快得多.但是,对于Windows …