页首Html代码

Emgu 学习(2) 视频文件播放

播放AVI视频文件

        static void Main(string[] args)
        {
            CvInvoke.NamedWindow("TestVideo", NamedWindowType.AutoSize);
            VideoCapture cap=new VideoCapture("test.avi");
            Mat frame = new Mat();
            for (; ; )
            {
                cap.Read(frame);
                if (frame.IsEmpty) break;
                CvInvoke.Imshow("TestVideo", frame);
                if (CvInvoke.WaitKey(33) >= 0)
                    break;
            }
            return;
        }

 

读取摄像头

代码如上,修改VideoCapture的构造参数,0 表示第一个摄像头,1表示第二个。。

new VideoCapture(0);

 

 保存视频流为AVI文件到本地

        static void Main(String[] args)
        {
            CvInvoke.NamedWindow("bgr", NamedWindowType.AutoSize);
            CvInvoke.NamedWindow("polar", NamedWindowType.AutoSize);
            VideoCapture cap = new VideoCapture(0);
            double fps = cap.GetCaptureProperty(CapProp.Fps);
            Size size=new Size((int)cap.GetCaptureProperty(CapProp.FrameWidth),
                (int)cap.GetCaptureProperty(CapProp.FrameHeight));
            VideoWriter writer = new VideoWriter("Hello.avi", (int)fps, size,true);
            Mat logpolar = new Mat();
            Mat bgr = new Mat();
            for (; ; )
            {
                cap.Read(bgr);
                if (bgr.IsEmpty)
                    return;
                CvInvoke.Imshow("bgr", bgr);
                CvInvoke.LogPolar(
                    bgr, logpolar, new PointF(bgr.Cols / 2, bgr.Rows / 2), 40);
                CvInvoke.Imshow("polar", logpolar);
                writer.Write(logpolar);
                int c = CvInvoke.WaitKey(10);
                if (c == 27)
                    break;
            }
            cap.Dispose();

        }

 

posted @ 2019-03-26 08:45  noigel  阅读(607)  评论(0编辑  收藏  举报
js脚本