Reputation: 3
I'm trying to get frames from a video file but while reading frames, OpenCv:u!=0 exception is being thrown. I'm using Emgu.Cv dll. I have written the code as follows:
private void GetVideoFrames(String Filename)
{
try
{
captureFrame = new Capture(Filename);
bool Reading = true;
while (Reading)
{
using (frame = captureFrame.QueryFrame().ToImage<Bgr, Byte>())
{
if
if (frame != null)
{
imageBox1.Image = frame;
frameCount++;
}
else
{
Reading = false;
}
}
}
}
Could anyone please provide some help.
Upvotes: 0
Views: 2903
Reputation: 514
according to me, you should make a copy of frame grabbed from camera. You could you the following code. It is tested and error free.
Capture captureFrame = new Capture(Filename);
Mat frame = new Mat();
Mat frame_copy = new Mat();
//Capture Image from file
private void GetVideoFrames(String Filename)
{
try
{
captureFrame = new Capture(Filename);
captureFrame.ImageGrabbed += ShowFrame;
captureFrame.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
//Show in ImageBox
private void ShowFrame(object sender, EventArgs e)
{
captureFrame.Retrieve(frame);
frame_copy = frame;
imageBox1.Image = frame_copy ;
}
Upvotes: 0