0
我有一个简单的Winforms应用程序,允许用户同时选择多个视频(文件)并运行后台工作线程以循环访问BW中的每个视频。下面有粘贴代码,我得到一个NullReferenceException为“无法创建......捕获”在这一行在多个后台工作线程中捕获类(Emgu)问题
Capture _capture = new Capture(videoFileName)
在processVideo方法。
N.B:如果我选择单个视频,相同的代码工作正常。所以有一些与Capture类的多个实例有关的问题。
我期望ProcessVideo方法拥有Capture的新实例并单独打开它。关于我可能做错什么的想法?
private void openVideoToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Video | *.AVI;*.MPEG;*.WMV;*.MP4;*.MOV;*.MPG;*.MPEG;*.MTS;*.FLV";
ofd.Multiselect = true;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] videos = ofd.FileNames;
if (videos != null)
{
BackgroundWorker[] bw = new BackgroundWorker[videos.GetLength(0)];
int n = 0;
foreach (string video in videos)
{
bw[n] = new BackgroundWorker();
bw[n].DoWork += new DoWorkEventHandler(bw_DoWork);
bw[n++].RunWorkerAsync(video);
}
}
}
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
string filename = (string)e.Argument;
ProcessVideo(filename);
}
private void ProcessVideo(string videoFileName)
{
Capture _capture = new Capture(videoFileName);
UInt64 TOTAL_FRAMES = Convert.ToUInt64(_capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT));
for (UInt64 n = 0; n < TOTAL_FRAMES; n++)
{
using (Image<Bgr, Byte> img1 = _capture.QueryFrame())
{
//do something with the frame
}
}
}
编辑该问题以显示位置。谢谢。 – Mikos 2012-04-17 08:27:11
谢谢。但是不能是文件格式或CODEC的问题,因为当选择单个文件时相同的文件可以正常工作。多选时出现错误。 – Mikos 2012-04-17 13:08:02
顺便说一句,什么是sourceafe服务包?它是来自Microsoft的SCM工具吗?或者是其他东西?这与这个问题有什么关系? – Mikos 2012-04-17 13:09:02