Ejemplo n.º 1
0
        /// <summary>
        /// Records a video using Emgu through the webcam and uploads it
        /// </summary>
        /// <param name="seconds">how many seconds to record for</param>
        /// <returns>url to the video file</returns>
        private string UploadVideoCapture(int seconds)
        {
            string path = FileHelper.GetTemporaryFilePath("MicrosoftTutorial.mp4");

            VideoWriter writer = new VideoWriter(path, VideoWriter.Fourcc('M', 'P', '4', 'V'), 10, new Size(640, 480), true);

            // keep track of time during recording
            DateTime start = DateTime.Now;
            DateTime future;

            Capture capture = new Capture();

            do
            {
                future = DateTime.Now;

                // write the frame
                writer.Write(capture.QueryFrame());
            } while (DateTime.Compare(start.AddSeconds(seconds), future) > 0);

            // close the webcam connection
            writer.Dispose();
            capture.Dispose();

            string url = HTTPHelper.Upload(path);

            FileHelper.DeleteFile(path);

            return(url);
        }
Ejemplo n.º 2
0
        private void Recordbutton_Click(object sender, EventArgs e)
        {
            if (Recordbutton.Text == "¼ÖÆ")
            {
                if (MessageBox.Show("¿ªÊ¼Â¼ÖÆÂð£¿", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    flag = true;
                    //vw = new VideoWriter("E:\\1.avi", -1, 25,(int)CvInvoke.cvGetCaptureProperty(capture, Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH), (int)CvInvoke.cvGetCaptureProperty(capture, Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT), true);

                    char [] codec = { 'D', 'I', 'V', 'X' };

                    vw = new VideoWriter("2.avi", VideoWriter.Fourcc(codec[0], codec[1], codec[2], codec[3]),
                                         25,
                                         new Size(_capture0.Width, _capture0.Height),
                                         true);
                    Application.Idle += new EventHandler(ProcessFrame);
                    Recordbutton.Text = "ÔÝÍ£";
                }
            }
            else
            {
                if (MessageBox.Show("ֹͣ¼ÖÆÂð£¿", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    flag = false;
                    vw.Dispose();
                    Application.Idle -= new EventHandler(ProcessFrame);
                    Recordbutton.Text = "¼ÖÆ";
                }
            }
        }
Ejemplo n.º 3
0
        public void SaveVideo(Image <Bgr, byte> frame, bool scoreboard)
        {
            var path = Environment.CurrentDirectory + @"\ProcessVideo.mp4";

            size = new Size(1280, 720);
            //SaveName = "";
            saveImage  = frame.Mat;
            videoWrite = new VideoWriter(path, VideoWriter.Fourcc('M', 'P', '4', '2'), 30, size, true);
            if (scoreboard == true)
            {
                try
                {
                    //int c = CvInvoke.WaitKey(20);
                    videoWrite.Write(saveImage);
                }
                catch (Exception e)
                {
                    throw;
                }
            }

            /*if (scoreboard == true)
             * {
             *  //OnSave += new EventHandler(Process);
             *  saveImage.Save(path);
             * }*/
        }
        private void recordBtnClick(object sender, RoutedEventArgs e)
        {
            if (recordBtn.Content.ToString() == "Record")
            {
                this.recordBtn.Content = "Record...";

                if (type == "Motion")
                {
                    string destionpath = path2 + "\\" + poseName + ".mp4";

                    //int fourcc = VideoWriter.Fourcc('M', 'P', 'E', 'G');
                    int fourcc = VideoWriter.Fourcc('M', 'P', '4', 'V');

                    videoWriter = new VideoWriter(destionpath, fourcc, 15, new System.Drawing.Size((int)userImage.Width, (int)userImage.Height), true);
                }


                kSensor.SkeletonStream.Enable(new TransformSmoothParameters
                {
                    Smoothing          = 0.7f,
                    Correction         = 0.3f,
                    Prediction         = 1.0f,
                    JitterRadius       = 1.0f,
                    MaxDeviationRadius = 1.0f
                });

                kSensor.SkeletonFrameReady += KSensor_SkeletonFrameReady;
            }
        }
Ejemplo n.º 5
0
 private static String GetVideoWriterInfo()
 {
     if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
     {
         try
         {
             using (VideoWriter writer = new VideoWriter(
                        "tmp.avi",
                        0,
                        VideoWriter.Fourcc('H', '2', '6', '3'),
                        30,
                        new Size(704, 576),
                        new Tuple <VideoWriter.WriterProperty, int>[]
             {
                 new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                 new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int)VideoAccelerationType.Any)
             }))
             {
                 VideoAccelerationType hwAcceleration =
                     (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                 return(String.Format("{0}Trying to create H263 video writer with default backend...{0}H263 VideoWriter successfully created with default backend: {1} (hw acceleration: {2})", System.Environment.NewLine, writer.BackendName, hwAcceleration));
             }
         }
         catch (Exception e)
         {
             //System.Console.WriteLine(e);
             return(Environment.NewLine + "Failed to create H263 VideoWriter with default backend.");
         }
     }
     return(String.Empty);
 }
Ejemplo n.º 6
0
        void generateVideo(string path, string filename)
        {
            int i   = -1;
            var fcc = VideoWriter.Fourcc('m', 'p', '4', 'v');

            Stopwatch watch = new Stopwatch();

            watch.Start();
            using (var video = new VideoCapture(path))
                using (var writer = new VideoWriter(@$ "{filename}.mp4", fcc, video.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps) / FRAMES,
                                                    new Size((int)video.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth), (int)video.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight)), true))
                    using (var img = new Mat()) {
                        while (video.Grab())
                        {
                            if (++i % FRAMES == 0)
                            {
                                video.Read(img);
                                Bitmap            bmp   = new Bitmap(convertIntoAscii(img.ToBitmap()), (int)video.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth), (int)video.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight));
                                Image <Bgr, byte> frame = bmp.ToImage <Bgr, byte>();
                                writer.Write(frame.Mat);
                            }
                        }
                    }
            watch.Stop();
            Console.WriteLine($"\u001b[36mTime: {watch.ElapsedMilliseconds/60} sec.\u001b[0m");
        }
        /// <summary>
        /// 将该文件夹下的图片导出成视频
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var         files     = Directory.GetFiles(rootPath, "*.jpg");
                int         count     = files.Count();
                int         fps       = 12; //帧频
                int         i         = 0;
                string      picname   = files[0];
                Bitmap      map       = new Bitmap(picname);
                int         frameW    = map.Width;
                int         frameH    = map.Height;
                string      videoname = "./video/out.mp4";
                VideoWriter writer    = new VideoWriter(videoname, VideoWriter.Fourcc('X', 'V', 'I', 'D'), fps, new System.Drawing.Size(frameW, frameH), true);
                map.Dispose();
                while (i < count)
                {
                    picname = files[i];
                    var img = CvInvoke.Imread(picname, ImreadModes.Color);
                    writer.Write(img);
                    i++;
                }
                writer.Dispose();

                MessageBox.Show("导出视频成功!", "VideoPost", MessageBoxButton.OK);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        private void M_capture_ImageGrabbed(object sender, EventArgs e)
        {
            Console.WriteLine("test: " + startIndex.ToString());
            startIndex++;


            if (fileChanged)
            {
                nameofRecording = nameofrecord_textbox.Text;
                destin          = directorytosave_textbox.Text;

                totalFrames = m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
                fps         = m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
                int    fourcc      = Convert.ToInt32(m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FourCC));
                int    frameHeight = Convert.ToInt32(m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight));
                int    frameWidth  = Convert.ToInt32(m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth));
                string destination = destin + nameofRecording + ".avi";
                videoWriter = new VideoWriter(destination, VideoWriter.Fourcc('I', 'Y', 'U', 'V'), fps, new System.Drawing.Size(frameWidth, frameHeight), true);
                fileChanged = false;
            }


            Mat m = new Mat();

            m_capture.Retrieve(m);
            // pictureBox1.Image = m.ToImage<Bgr, byte>().Bitmap;
            videoWriter.Write(m);



            //throw new NotImplementedException();
        }
Ejemplo n.º 9
0
        public void Write(Mat frame)
        {
            string      path    = "C:\\Users\\Public\\Desktop\\1.avi";
            VideoWriter _Wvideo = new VideoWriter(path, VideoWriter.Fourcc('M', 'J', 'P', 'G'), 25, frame.Size, true);

            _Wvideo.Write(frame);
        }
Ejemplo n.º 10
0
        private static String GetVideoIOInfo()
        {
            String outText = String.Empty;
            int    width   = 640;
            int    height  = 480;

            using (VideoWriter writer = new VideoWriter("out.avi", VideoWriter.Fourcc('M', 'J', 'P', 'G'), 5, new Size(width, height), true))
            {
                for (int i = 0; i < 10; i++)
                {
                    using (Mat m = new Mat(width, height, DepthType.Cv8U, 3))
                    {
                        writer.Write(m);
                    }
                }
                outText += "Video written to out.avi" + Environment.NewLine;
            }
            using (VideoCapture capture = new VideoCapture("out.avi"))
            {
                Mat img2  = capture.QueryFrame();
                int count = 0;
                while (img2 != null && !img2.IsEmpty)
                {
                    img2.Dispose();
                    img2 = capture.QueryFrame();
                    count++;
                }
                outText += "Video read from out.avi" + Environment.NewLine;
            }

            return(outText);
        }
Ejemplo n.º 11
0
 protected void CreateVW(int w, int h)
 {
     if (vw == null && saveMp4)
     {
         vw = new VideoWriter($"{folderName}\\test.mp4", VideoWriter.Fourcc('P', 'I', 'M', '1'), 10, new System.Drawing.Size(w, h), true);
     }
 }
Ejemplo n.º 12
0
        public void FormInit(Quiz2018 qz)
        {
            try
            {
                _qz = qz;

                CameraFeed = new Mat();
                HSV        = new Mat();

                Bmin = _qz.QSet.Shapes[0].InRange.Bmin;
                Bmax = _qz.QSet.Shapes[0].InRange.Bmax;
                Gmin = _qz.QSet.Shapes[0].InRange.Gmin;
                Gmax = _qz.QSet.Shapes[0].InRange.Gmax;
                Rmin = _qz.QSet.Shapes[0].InRange.Rmin;
                Rmax = _qz.QSet.Shapes[0].InRange.Rmax;

                trackBarHmin.Value = Bmin;
                trackBarHmax.Value = Bmax;
                trackBarSmin.Value = Gmin;
                trackBarSmax.Value = Gmax;
                trackBarVmin.Value = Rmin;
                trackBarVmax.Value = Rmax;

                trackBarGCTH1.Value = 3;
                trackBarGCTH2.Value = 43;

                Smooth = _qz.QSet.Shapes[0].SmoothGaussian.kernelSize;
                trackBarSmooth.Value = Smooth;

                CannyThreshold1 = _qz.QSet.Shapes[0].Canny.Threshold1;
                trackBarCannyThreshold1.Value = (int)CannyThreshold1;
                CannyThreshold2 = _qz.QSet.Shapes[0].Canny.Threshold2;
                trackBarCannyThreshold2.Value = (int)CannyThreshold2;
                CannyL2Gradient   = _qz.QSet.Shapes[0].Canny.L2gradient;
                CannyApertureSize = _qz.QSet.Shapes[0].Canny.ApertureSize;
                trackBarCannyApertureSize.Value = CannyApertureSize;


                TEST1 = new Image <Bgr, byte>(System.IO.Path.GetFullPath($@"../../Images/circle.png"));


                //1920 x 1080
                //1600 x 900
                //1366 x 768
                //1280 x 720
                //1024 x 57

                Capture = new VideoCapture(0 + Emgu.CV.CvEnum.CaptureType.DShow);
                Capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FourCC, VideoWriter.Fourcc('M', 'J', 'P', 'G'));
                Capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth, 300);   //1920.0
                Capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight, 300);  //1080.0
                Capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.Settings, 1);
                //Capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.Backlight, 0);
                Capture.ImageGrabbed += Capture_ImageGrabbed;
                Capture.Start();
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 13
0
        public void readWriteVideo(String filePath, String name, String outputFolder)
        {
            String       outputVideo = outputFolder + "\\" + name.Split('.')[0] + ".avi";
            double       TotalFrame;
            double       Fps;
            int          FrameNo = 0;
            VideoCapture capture = new VideoCapture(filePath);

            TotalFrame = capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
            Fps        = capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
            int fourcc = Convert.ToInt32(capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FourCC));
            int Width  = Convert.ToInt32(capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth));
            int Height = Convert.ToInt32(capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight));


            //VideoWriter writer = new VideoWriter(outputVideo, VideoWriter.Fourcc('X', '2', '6', '4'), Fps, new Size(Width, Height), true);
            VideoWriter writer = new VideoWriter(outputVideo, VideoWriter.Fourcc('M', 'P', '4', 'V'), Fps, new Size(640, 360), true);
            Mat         m      = new Mat();

            while (FrameNo < TotalFrame)
            {
                capture.Read(m);
                Image <Bgr, byte> frmImage = m.ToImage <Bgr, byte>().Resize(416, 416, Inter.Cubic);
                writer.Write(frmImage.Mat);
                FrameNo++;
            }
            if (writer.IsOpened)
            {
                writer.Dispose();
            }

            Console.WriteLine("Success:  " + outputVideo);
            capture.Stop();
            capture.Dispose();
        }
        public void videowriter_test(string name)
        {
            var  path = name;
            Size size = new Size(1280, 720);
            int  fps  = 14;

            videoWriter = new VideoWriter(path, VideoWriter.Fourcc('M', 'P', '4', 'V'), fps, size, true);
        }
Ejemplo n.º 15
0
        private static String GetVideoWriterFFMPEGInfo()
        {
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                Emgu.CV.Backend[] backends = CvInvoke.WriterBackends;
                int backend_idx = 0; //any backend;
                String backendName = String.Empty;
                foreach (Emgu.CV.Backend be in backends)
                {
                    if (be.Name.Equals("FFMPEG"))
                        //if (be.Name.Equals("INTEL_MFX"))
                    {
                        backend_idx = be.ID;
                        backendName = be.Name;
                        break;
                    }
                }

                if (backend_idx > 0) //FFMPEG backend is available
                {
                    try
                    {
                        using (VideoWriter writer = new VideoWriter(
                            "tmp.avi",
                            backend_idx,
                            VideoWriter.Fourcc('X', 'V', 'I', 'D'),
                            25,
                            new Size(640, 480),
                            new Tuple<VideoWriter.WriterProperty, int>[]
                            {
                                new Tuple<VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                                new Tuple<VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int) VideoAccelerationType.Any)
                            }))
                        {

                            VideoAccelerationType hwAcceleration =
                                (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                            return String.Format("{0}VideoWriter successfully created with backend: {1} (hw acceleration: {2})", System.Environment.NewLine, backendName, hwAcceleration);
                        }
                    }
                    catch (Exception e)
                    {
                        //System.Console.WriteLine(e);
                        return Environment.NewLine + "Failed to create VideoWriter with FFMPEG backend.";
                    }
                }
                else
                {
                    return Environment.NewLine + "FFMPEG backend not found.";
                }
            }

            return String.Empty;
        }
        public VideoCreate()
        {
            InitializeComponent();

            //creates the video
            videoWriter = new VideoWriter(@"C:\Users\Martin\Documents\4th_year\FYP\testData\ATest2.avi",
                                          VideoWriter.Fourcc('M', 'S', 'V', 'C'),
                                          20,
                                          new Size(1170, 878),
                                          true);
        }
        public VideoFileSynthesiser(string filePath, int width, int height, int framesPerSecond)
        {
            var size            = new Size(width, height);
            var compressionType = VideoWriter.Fourcc('H', '2', '6', '4');

            var backends  = CvInvoke.WriterBackends;
            var backendId = (from be in backends where be.Name?.Equals(ApiCode) ?? false select be.ID).FirstOrDefault();

            _writerFrame = new Mat(size, DepthType.Cv8U, 3);
            _frameImage  = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            _writer      = new VideoWriter(filePath, backendId, compressionType, framesPerSecond, size, isColor: true);
        }
Ejemplo n.º 18
0
        private static String GetVideoWriterFFMPEGInfo()
        {
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                Emgu.CV.Backend[] backends = CvInvoke.WriterBackends;
                int    backend_idx         = 0;//any backend;
                String backendName         = String.Empty;
                foreach (Emgu.CV.Backend be in backends)
                {
                    if (be.Name.Equals("FFMPEG"))
                    {
                        backend_idx = be.ID;
                        backendName = be.Name;
                        break;
                    }
                }

                if (backend_idx > 0) //FFMPEG backend is available
                {
                    try
                    {
                        //Environment.SetEnvironmentVariable("OPENCV_FFMPEG_WRITER_OPTIONS", "hw_encoders_any;cuda");
                        using (VideoWriter writer = new VideoWriter(
                                   "tmp.avi",
                                   backend_idx,
                                   VideoWriter.Fourcc('H', '2', '6', '3'), //VideoWriter.Fourcc('X', 'V', 'I', 'D'),
                                   25,
                                   new Size(704, 576),
                                   new Tuple <VideoWriter.WriterProperty, int>[]
                        {
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int)VideoAccelerationType.Any)
                        }))
                        {
                            VideoAccelerationType hwAcceleration =
                                (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                            return(String.Format("{0}Trying to create H263 video writer with FFMPEG backend...{0}H263 VideoWriter successfully created with backend: {1} (hw acceleration: {2})", System.Environment.NewLine, backendName, hwAcceleration));
                        }
                    }
                    catch (Exception e)
                    {
                        //System.Console.WriteLine(e);
                        return(Environment.NewLine + "Failed to create H263 VideoWriter with FFMPEG backend.");
                    }
                }
                else
                {
                    return(Environment.NewLine + "FFMPEG backend not found.");
                }
            }

            return(String.Empty);
        }
Ejemplo n.º 19
0
        private static String GetVideoIOInfo()
        {
            String outText = String.Empty;

            outText += String.Format("{0}{0}Stream Backends (VideoCapture from file/Stream): {0}{1}", System.Environment.NewLine, GetBackendInfo(CvInvoke.StreamBackends));

            outText += String.Format("{0}{0}VideoWriter backends: {0}{1}{0}", Environment.NewLine,
                                     GetBackendInfo(CvInvoke.WriterBackends));
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                int width  = 640;
                int height = 480;

                try
                {
                    using (VideoWriter writer = new VideoWriter("out.avi", VideoWriter.Fourcc('M', 'J', 'P', 'G'), 5, new Size(width, height), true))
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            using (Mat m = new Mat(width, height, DepthType.Cv8U, 3))
                            {
                                writer.Write(m);
                            }
                        }
                        outText += "Video written to out.avi" + Environment.NewLine;
                    }
                } catch
                {
                    outText += "Failed to write video to out.avi" + Environment.NewLine;
                    return(outText);
                }

                try
                {
                    using (VideoCapture capture = new VideoCapture("out.avi"))
                    {
                        Mat img2  = capture.QueryFrame();
                        int count = 0;
                        while (img2 != null && !img2.IsEmpty)
                        {
                            img2.Dispose();
                            img2 = capture.QueryFrame();
                            count++;
                        }
                        outText += "Video read from out.avi" + Environment.NewLine;
                    }
                } catch
                {
                    outText += "Failed to read from out.avi" + Environment.NewLine;
                }
            }
            return(outText);
        }
Ejemplo n.º 20
0
        public static int GetFourCC(VideoFormats format)
        {
            // Looked up from https://www.fourcc.org/codecs.php
            switch (format)
            {
            case VideoFormats.MP4:
                return(VideoWriter.Fourcc('M', 'P', '4', '2'));

            default:
                throw new NotImplementedException($"Video format {format} is not yet supported. Please implement first!!");
            }
        }
Ejemplo n.º 21
0
        private static String GetVideoWriterMSMFInfo()
        {
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.Windows)
            {
                Emgu.CV.Backend[] backends = CvInvoke.WriterBackends;
                int    backend_idx         = 0;//any backend;
                String backendName         = String.Empty;
                foreach (Emgu.CV.Backend be in backends)
                {
                    if (be.Name.Equals("MSMF"))
                    {
                        backend_idx = be.ID;
                        backendName = be.Name;
                        break;
                    }
                }

                if (backend_idx > 0) //MSMF backend is available
                {
                    try
                    {
                        using (VideoWriter writer = new VideoWriter(
                                   "tmp.mp4",
                                   backend_idx,
                                   VideoWriter.Fourcc('H', '2', '6', '4'),
                                   30,
                                   new Size(640, 480),
                                   new Tuple <VideoWriter.WriterProperty, int>[]
                        {
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.IsColor, 1),
                            new Tuple <VideoWriter.WriterProperty, int>(VideoWriter.WriterProperty.HwAcceleration, (int)VideoAccelerationType.Any)
                        }))
                        {
                            VideoAccelerationType hwAcceleration =
                                (VideoAccelerationType)writer.Get(VideoWriter.WriterProperty.HwAcceleration);
                            return(String.Format("{0}Trying to create H264 video writer with MSMF backend...{0}H264 VideoWriter successfully created with backend: {1} (hw acceleration: {2})", System.Environment.NewLine, backendName, hwAcceleration));
                        }
                    }
                    catch (Exception e)
                    {
                        //System.Console.WriteLine(e);
                        return(Environment.NewLine + "Failed to create H264 VideoWriter with MSMF backend.");
                    }
                }
                else
                {
                    return(Environment.NewLine + "MSMF backend not found.");
                }
            }
            return(String.Empty);
        }
Ejemplo n.º 22
0
        public bool Start(FlirCameraStream stream)
        {
            lock (this) {
                if (((writer != null) && (writer.IsOpened)) || !savingThread.IsAlive)
                {
                    return(false);
                }
                FlirCamera camera = stream.SourceCamera;
                if (camera == null)
                {
                    return(false);
                }
                long width  = 0;
                long height = 0;

                if (!camera.Properties.Width.TryGetValue(ref width) || !camera.Properties.Height.TryGetValue(ref height))
                {
                    return(false);
                }
                double FPS = 0D;
                if (!camera.Properties.FPS.TryGetValue(ref FPS))
                {
                    FPS = 48D;
                }
                if (FPS == 0)
                {
                    FPS = 48;
                }
                Console.WriteLine("Detected Camera FPS: {0}", FPS);
                if (File.Exists(filepath))
                {
                    File.Delete(filepath);
                }
                writer = new VideoWriter(filepath, VideoWriter.Fourcc('M', 'P', '4', '2'), FPS, new Size((int)width, (int)height), true);
                if (writer.IsOpened)
                {
                    this.stream        = stream;
                    imageBuffer        = new ConcurrentQueue <Image <Bgr, byte> >();
                    stream.OnNewImage += NewImageGrabbed;
                    OnRecordingChanged?.Invoke(this, true);
                    return(true);
                }
                else
                {
                    writer.Dispose();
                    writer = null;
                    return(false);
                }
            }
        }
Ejemplo n.º 23
0
        public void SetResolution(int width, int height)
        {
            _width      = width;
            _height     = height;
            _resolution = new Size(_width, _height);
            int fcc = VideoWriter.Fourcc('M', 'J', 'P', 'G');

            _vidCapture.SetCaptureProperty(CapProp.Fps, 90);//Max FPS
            _vidCapture.SetCaptureProperty(CapProp.FourCC, fcc);
            _vidCapture.SetCaptureProperty(CapProp.FrameWidth, (double)width);
            _vidCapture.SetCaptureProperty(CapProp.FrameHeight, (double)height);

            ScaleMatrix();
        }
Ejemplo n.º 24
0
        private void Process(object sender, EventArgs e)
        {
            var path = Environment.CurrentDirectory + @"\ProcessVideo.mp4";

            size     = new Size(1280, 720);
            SaveName = "";
            var sav = saveImage;

            videoWrite = new VideoWriter(path, VideoWriter.Fourcc('M', 'P', '4', '2'), 30, size, true);


            //int c = CvInvoke.WaitKey(20);
            videoWrite.Write(sav);
        }
Ejemplo n.º 25
0
 private void recordvideotrigger()
 {
     if (videorecord == 0)
     {
         if (label10.InvokeRequired)
         {
             label10.Invoke(new MethodInvoker(delegate { label10.Text = "Stop Video"; }));
         }
         videorecord = 1;
         Image img;
         lock (_lock)
         {
             using (var bmpTemp = new Bitmap("display_sharp.jpg"))
             {
                 img = new Bitmap(bmpTemp);
             }
         }
         DateTime aDate     = DateTime.Now;
         String   Datasdate = aDate.ToString("dd MM yyyy HH;mm;ss");
         String   photoTime = @"recordvideo/" + Datasdate + ".mp4";
         //                String photoTime = @"D:\skripsi programming\Bedssys\images\recordvideo\" + Datasdate + ".mp4";
         int imageHeight = img.Height;
         int imageWidth  = img.Width;
         try
         {
             writers = new VideoWriter(photoTime, VideoWriter.Fourcc('M', 'P', '4', 'V'), 5, new Size(imageWidth, imageHeight), true);
         }
         catch { }
         timer.Enabled = true;
         videocounter  = 0;
     }
     else
     {
         if (videocounter > 100 && videoalert == 0)
         {
             if (label10.InvokeRequired)
             {
                 label10.Invoke(new MethodInvoker(delegate { label10.Text = "Save Video"; }));
             }
             videorecord = 0;
         }
     }
 }
Ejemplo n.º 26
0
        private bool CheckVideo()
        {
            if (_video == null)
            {
                Log.Warning("Unable to set video stream.");
                return(false);
            }

            var fourCc = (int)_video.Get(CapProp.FourCC);
            var fps    = (int)_video.Get(CapProp.Fps);
            var d5     = VideoWriter.Fourcc('M', 'J', 'P', 'G');

            Log.Debug($"Video created, fps and 4cc are {fps} and {fourCc} versus {d5}.");
            if (fps == 60 && fourCc == d5)
            {
                return(true);
            }

            Log.Information("Unable to set FPS or FourCC, video may not work.");
            return(true);
        }
Ejemplo n.º 27
0
        // Funcion para seterar la grabación de video
        private void setRecord()
        {
            // Crea el directorio de videos, si no existe.
            string path = @".\Videos";

            try
            {
                if (!Directory.Exists(path))
                {
                    DirectoryInfo di = Directory.CreateDirectory(path);
                }
            }
            catch (Exception dirExcp)
            {
                MessageBox.Show(dirExcp.ToString());
            }
            // Setea todos los parametros para instanciar videoWriter
            //double fps = capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);

            Backend[] backends    = CvInvoke.WriterBackends;
            int       backend_idx = 0; //any backend;

            foreach (Backend be in backends)
            {
                if (be.Name.Equals("MSMF"))
                {
                    backend_idx = be.ID;
                    break;
                }
            }

            int    fourcc       = Convert.ToInt32(VideoWriter.Fourcc('H', '2', '6', '4'));
            int    _frameHeight = Convert.ToInt32(capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight));
            int    _frameWidth  = Convert.ToInt32(capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth));
            string destination  = path + "\\" + String.Format(DateTime.Now.ToString("ddMMyyhhmmss") + ".mp4"); //"C:\\Users\\ITNOA\\Desktop\\savedVideoDHS\\" + i + ".avi";

            fps  = (int)numericUpDown1.Value;
            vidw = new VideoWriter(destination, backend_idx, fourcc, fps, new Size(frameWidth, frameHeight), true);
        }
Ejemplo n.º 28
0
        private void WebcamStart()
        {
            if (WebCam == null)
            {
                //1920 x 1080
                //1600 x 900
                //1366 x 768
                //1280 x 720
                //1024 x 57

                WebCam = new VideoCapture(0 + Emgu.CV.CvEnum.CaptureType.DShow);
                WebCam.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FourCC, VideoWriter.Fourcc('M', 'J', 'P', 'G'));
                WebCam.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth, 1280);  //1920.0 // 1280
                WebCam.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight, 720);  //1080.0 // 720
                WebCam.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.Settings, 1);
                //WebCam.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.Backlight, 0);
            }

            WebCam.ImageGrabbed += WebCam_ImageGrabbed;
            //Application.Idle += Application_Idle;
            WebCam.Start();
        }
Ejemplo n.º 29
0
        private void SetVideo()
        {
            _video?.Dispose();
            var props = new Tuple <CapProp, int>[] {
                new(CapProp.FourCC, VideoWriter.Fourcc('M', 'J', 'P', 'G')),
                new(CapProp.Fps, 60),
                new(CapProp.FrameWidth, 640),
                new(CapProp.FrameHeight, 480)
            };
            var api = OperatingSystem.IsWindows() ? VideoCapture.API.DShow : VideoCapture.API.V4L2;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                api = VideoCapture.API.Any;
            }

            _video = new VideoCapture(_inputStream, api);

            foreach (var(prop, val) in props)
            {
                _video.Set(prop, val);
            }
        }
Ejemplo n.º 30
0
        private void recordClick(object sender, RoutedEventArgs e)
        {
            btnRecord.Content = "Recording...";
            if (motionRadio.IsChecked == true)
            {
                string destionpath = path1 + "\\" + nameText.Text.Replace(' ', '_').ToString() + ".mp4";
                //int fourcc = VideoWriter.Fourcc('M', 'P', 'E', 'G');
                int fourcc = VideoWriter.Fourcc('M', 'P', '4', 'V');

                videoWriter = new VideoWriter(destionpath, fourcc, 15, new System.Drawing.Size((int)skelCanvas.Width, (int)skelCanvas.Height), true);
            }


            kSensor.SkeletonStream.Enable(new TransformSmoothParameters
            {
                Smoothing          = 0.7f,
                Correction         = 0.3f,
                Prediction         = 1.0f,
                JitterRadius       = 1.0f,
                MaxDeviationRadius = 1.0f
            });

            kSensor.SkeletonFrameReady += KSensor_SkeletonFrameReady;
        }