OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 3984|回复: 0

emgu 2.0 保存視頻

[复制链接]
发表于 2010-3-21 03:32:48 | 显示全部楼层 |阅读模式
因為 emgu 2.0的某個 bug  必須改寫cvCreateVideoWriter  
存檔若有問題可參考我的範例如下:
string today;
        double fourcc ;
        private bool RecordInProgress;
        public double GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP index)
        {
            return CvInvoke.cvGetCaptureProperty(_ptr, index);
        }
        private void Recordbutton_Click(object sender, EventArgs e)
        {//("試用版不提供錄影功能,請電****-393*32 *茂松")--PMC精密機械研發中心
            if (_captureInProgress)
            {
                DateTime savetoday = DateTime.Now;
                today = string.Format("{0:yyyyMMdd}", savetoday);
                saveFileDialog1.FileName  = "切削錄影"+ today;
                fourcc = GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FOURCC);
                saveFileDialog1.ShowDialog();
            }
        }
        VideoWriter Videowriter;         
        [DllImport("highgui200.dll")]
        public static extern IntPtr cvCreateVideoWriter(
            [MarshalAs(UnmanagedType.LPStr)] String filename,
            int fourcc,
            double fps,
            int frame_size,
            [MarshalAs(UnmanagedType.I1)] bool is_color);        
        private delegate void del_ProcessFileFram(object sender, EventArgs e);
        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            RecordInProgress = true;
            captureButton.Enabled = false;
            Recordbutton.Enabled = false ;
            STOP_button.Enabled = true;
            IntPtr ptr_capture = cvCreateVideoWriter(saveFileDialog1.FileName,(int) fourcc, 20, 640 * 480, true);
            Videowriter = new VideoWriter(saveFileDialog1.FileName, 20, captureImageBox.Size.Width, captureImageBox.Size.Height, true);
            IntPtr writer = Videowriter;
            del_ProcessFileFram P_F_R=ProcessFileFrame;            
            Application.Idle += new EventHandler(P_F_R);            
        }
        private void ProcessFileFrame(object sender, EventArgs arg)
        {
            if (RecordInProgress == false) return;
            frame = _capture.QueryFrame();
            captureImageBox.Image = frame;
            Videowriter.WriteFrame(frame);
        }
        private void STOP_button_Click(object sender, EventArgs e)
        {
            RecordInProgress = false;
            captureButton.Enabled = true;
            STOP_button.Enabled = false;            
            del_ProcessFileFram P_F_R = ProcessFileFrame;
            Application.Idle -= new EventHandler(P_F_R);
            Videowriter.Dispose();
            
        }

        private void btn_flip_Click(object sender, EventArgs e)
        {
            _capture_flip = !_capture_flip;
            if (_capture_flip)
            {  //stop the capture
                _capture.FlipHorizontal = true;
            }
            else
            {   //start the capture
                _capture.FlipHorizontal = false ;
            }
            
        }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-5-3 07:23 , Processed in 0.008544 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表