Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
my code without error but don't save any frame. when I pause the video I want to save the current frame.

What I have tried:

<pre>
<pre>namespace VideoCaptureApplication1
{
    public partial class Form2 : Form
    {
        private Capture _capture = null;
        Image<Bgr, Byte> frame;
        double FrameRate = 0;
        double TotalFrames = 0;
        double Framesno = 0;
        bool IsPlaying = false;
        
        public Form2()
        {
            InitializeComponent();
        }


private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
           
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                { 
                    _capture = null;
                    _capture = new Capture(openFileDialog1.FileName);

                    FrameRate = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS);
                    TotalFrames = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT);
                    Application.Idle += ProcessFrame ;
                    IsPlaying = true;
                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }
        }
private void ProcessFrame(object sender, EventArgs arg)
        {
            try
            {
                Framesno = _capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
                frame = _capture.QueryFrame();


                if (frame != null && IsPlaying==true)
                {
                    pictureBox1.Image = frame.ToBitmap();

                    
                        Thread.Sleep((int)(1000.0 / FrameRate));
                    }
                  
                }
                    catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
 private void button4_Click(object sender, EventArgs e)
        {
            
            frame.Save("D\\" + Frame.ToString()+".jpg");

           
        }
Posted
Updated 28-Feb-19 19:10pm

1 solution

If you didn't "step through the code" with the debugger to see what happened in every intermediate step, how do you expect someone else to?

Step through the code and come back when you have a better idea where the problem is because no one else can.

It's called "testing".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900