public void write() {
            int codec = Emgu.CV.CvInvoke.CV_FOURCC('P', 'I', 'M', '1');

            int fps = 25;
            if (list_timestamps.Count > 0)
            {
                String tempvideopath = Program.getConfiguration().Mediafolderpath + @"\" + list_timestamps[0].ToString() + ".mpg";
                Capture tempcapture = new Capture(tempvideopath);
                fps = (int)tempcapture.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS);
                tempcapture.Dispose();
            }

            VideoWriter videowriter = new VideoWriter(videopath, codec, fps, 640, 480, true);
            

            for (int i = 0; i < list_timestamps.Count; i++)
            {
                videopath = Program.getConfiguration().Mediafolderpath + @"\" + list_timestamps[i].ToString() + ".mpg";
                try
                {
                    Capture joincapture = new Capture(videopath);
                    Image<Bgr, byte> frame = joincapture.QueryFrame();
                    for (int n = 1; n < 15; n++)
                        joincapture.QueryFrame();

                    while (frame != null)
                    {
                        videowriter.WriteFrame(frame);
                        frame = joincapture.QueryFrame();
                    }
                    joincapture.Dispose();

                    // Notify main frame to update its progressbar
                    ExportVideoProgressEventArgs e = new ExportVideoProgressEventArgs(i);
                    DoneAppendingRallyVideoEvent(this, e);
                }
                catch (NullReferenceException) { Console.WriteLine("unreadable video file"); }
            }
            videowriter.Dispose();
        
        }
        private void previewBtn_Click(object sender, RoutedEventArgs e)
        {
            if (previewBtn.Content.ToString() == "Preview Stream")
            {
                if (kinect_sensor != null)
                {
                    // disable all other buttons
                    DeactivateReplay();
                    gestureCaptureBtn.IsEnabled = false;
                    gestureRecognitionBtn.IsEnabled = false;
                    gestureReplayBtn.IsEnabled = false;
                    previewBtn.Content = "Stop Stream";
                    isStreaming = true;
                    kinect_data_manager.ifShowJointStatus = true;

                    frame_rec_buffer.Clear();

                    kinect_sensor.Start();
                }
            }
            else
            {
                if(kinect_sensor != null)
                {
                    kinect_sensor.Stop();

                    gestureCaptureBtn.IsEnabled = true;
                    gestureReplayBtn.IsEnabled = true;
                    gestureRecognitionBtn.IsEnabled = true;

                    isStreaming = false;
                    kinect_data_manager.ifShowJointStatus = false;

                    // save recorded frame to disk
                    if (frame_rec_buffer != null && saveVideoCheckBox.IsChecked.Value)
                    {
                        // create video writer
                        int fwidth = (int)groupBox3.Width + 20;
                        int fheight = (int)groupBox3.Height + 20;

                        SaveFileDialog saveDialog = new SaveFileDialog();
                        saveDialog.Filter = "avi files (*.avi)|*.avi";
                        saveDialog.FilterIndex = 2;
                        saveDialog.RestoreDirectory = true;

                        if (saveDialog.ShowDialog().Value)
                        {
                            statusbarLabel.Content = "Saving video...";

                            string videofile = saveDialog.FileName.ToString();
                            VideoWriter videoWriter = new VideoWriter(videofile, CvInvoke.CV_FOURCC('M', 'J', 'P', 'G'), 15,
                                fwidth, fheight, true);

                            if (videoWriter == null)
                                MessageBox.Show("Fail to save video. Check if codec has been installed.");
                            else
                            {
                                for (int i = 0; i < frame_rec_buffer.Count; i++)
                                {
                                    // write to video file
                                    Emgu.CV.Image<Bgr, byte> cvImg =
                                        new Emgu.CV.Image<Bgr, byte>(frame_rec_buffer[i] as Bitmap);

                                    videoWriter.WriteFrame<Bgr, byte>(cvImg);
                                }

                                videoWriter.Dispose();

                                statusbarLabel.Content = "Video saved to " + videofile;
                            }
                        }

                    }

                    frame_rec_buffer.Clear();

                    previewBtn.Content = "Preview Stream";

                    // save tracked elbow speed
                    //FileStream file = File.Open("d:\\temp\\test.txt", FileMode.Create);
                    //StreamWriter writer = new StreamWriter(file);
                    //for (int i = 0; i < motion_assessor.jointStatusSeq.Count; i++)
                    //    writer.WriteLine(motion_assessor.jointStatusSeq[i][JointType.HandRight].abs_speed);
                    //writer.Close();
                }
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: oogg06/TimeLapser
        private void generarVideo()
        {
            Emgu.CV.VideoWriter escritor = new Emgu.CV.VideoWriter(rutaAlmacenamiento+"\\Out.avi", 30,
                ancho, alto, true);
            //Recuperamos los nombres de los archivos JPG
            string[] listaImagenes = Directory.GetFiles(rutaAlmacenamiento, "*.jpg");
            barraProgresoGeneracion.Maximum = listaImagenes.Length;
            int posFrame = 0;
            int total=listaImagenes.Length;

            foreach (string imagen in listaImagenes)
            {

                barraProgresoGeneracion.Value = posFrame;

                Image<Bgr, Byte> imagenCargada = new Image<Bgr, byte>(imagen);
                escritor.WriteFrame<Bgr, byte>(imagenCargada);
                //imagenCargada.Dispose();
                posFrame=posFrame+1;
            }

            Thread.Sleep(5000);
            escritor.Dispose();
            GC.Collect();

            MessageBox.Show("Video generado");
        }