zoukankan      html  css  js  c++  java
  • 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();
    
            }
  • 相关阅读:
    [CF920E] Connected Components?
    [CF981E] Addition on Segments
    [BZOJ2152] 聪聪可可
    [CF1355E] Restorer Distance
    [CF1101D] GCD Counting
    [CF827C] DNA Evolution
    [HNOI2008] 明明的烦恼
    [CF712D] Memory and Scores
    [CF609E] Minimum spanning tree for each edge
    后缀自动机应用小结 I
  • 原文地址:https://www.cnblogs.com/noigel/p/10598030.html
Copyright © 2011-2022 走看看