[英]Why does RetrieveBgrFrame() return null?
你調用的對象是空的
我的問題是,我嘗試在視頻文件上使用CV(以模擬攝像機),但無法處理幀,因為RetrieveBgrFrame()不會返回圖像。 相反,它給出了以上錯誤。 我的代碼是:
如果您需要其他詳細信息,請告訴我。
您的問題是字段捕獲為空,因為它從未初始化。 代碼應如下所示:
public partial class Form1 : Form
{
private Image<Bgr, Byte> imgStat = null;
private Capture capture = null;
private bool _captureInProgress = false;
// private bool captureInProgress;
public Form1()
{
InitializeComponent();
imgStat = null;
}
public string selectFile()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
String s = ofd.FileName.Normalize();
return s;
}
private void button2_Click(object sender, EventArgs e)
{
this.capture = new Capture(selectFile());
capture.ImageGrabbed += ProcessFrame;
capture.Start();
}
private void ProcessFrame(object sender, EventArgs e)
{
try
{
//capture.Grab(); //doesnt help
// Image<Bgr, byte> beeldje = capture.QueryFrame(); //doesnt work as well
Image<Bgr, byte> beeldje = capture.RetrieveBgrFrame();
DisplayImage(beeldje.ToBitmap());
}
catch (Exception er)
{
Console.WriteLine(er.Message);
}
}
private delegate void DisplayImageDelegate(Bitmap Image);
private void DisplayImage(Bitmap Image)
{
if (pictureBox1.InvokeRequired)
{
try
{
DisplayImageDelegate DI = new DisplayImageDelegate(DisplayImage);
this.BeginInvoke(DI, new object[] {Image});
}
catch (Exception ex)
{
}
}
else
{
pictureBox1.Image = Image;
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.