当前位置: 首页>>代码示例>>C#>>正文


C# Mat.Empty方法代码示例

本文整理汇总了C#中Mat.Empty方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Empty方法的具体用法?C# Mat.Empty怎么用?C# Mat.Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat的用法示例。


在下文中一共展示了Mat.Empty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public void Run()
        {
            var capture = new VideoCapture();
            capture.Set(CaptureProperty.FrameWidth, 640);
            capture.Set(CaptureProperty.FrameHeight, 480);
            capture.Open(-1);
            if (!capture.IsOpened())
                throw new Exception("capture initialization failed");

            var fs = FrameSource.CreateCameraSource(-1);
            var sr = SuperResolution.CreateBTVL1();
            sr.SetInput(fs);

            using (var normalWindow = new Window("normal"))
            using (var srWindow = new Window("super resolution"))
            {
                var normalFrame = new Mat();
                var srFrame = new Mat();
                while (true)
                {
                    capture.Read(normalFrame);
                    sr.NextFrame(srFrame);
                    if (normalFrame.Empty() || srFrame.Empty())
                        break;
                    normalWindow.ShowImage(normalFrame);
                    srWindow.ShowImage(srFrame);
                    Cv2.WaitKey(100);
                }
            }
        }
开发者ID:0sv,项目名称:opencvsharp,代码行数:30,代码来源:SuperResolutionSample.cs

示例2: Run

        public void Run()
        {
            const string OutVideoFile = "out.avi";

            // Opens MP4 file (ffmpeg is probably needed)
            VideoCapture capture = new VideoCapture(FilePath.Bach);

            // Read movie frames and write them to VideoWriter 
            Size dsize = new Size(640, 480);
            using (VideoWriter writer = new VideoWriter(OutVideoFile, -1, capture.Fps, dsize))
            {
                Console.WriteLine("Converting each movie frames...");
                Mat frame = new Mat();
                while(true)
                {
                    // Read image
                    capture.Read(frame);
                    if(frame.Empty())
                        break;

                    Console.CursorLeft = 0;
                    Console.Write("{0} / {1}", capture.PosFrames, capture.FrameCount);

                    // grayscale -> canny -> resize
                    Mat gray = new Mat();
                    Mat canny = new Mat();
                    Mat dst = new Mat();
                    Cv2.CvtColor(frame, gray, ColorConversion.BgrToGray);
                    Cv2.Canny(gray, canny, 100, 180);
                    Cv2.Resize(canny, dst, dsize, 0, 0, Interpolation.Linear);
                    // Write mat to VideoWriter
                    writer.Write(dst);
                } 
                Console.WriteLine();
            }

            // Watch result movie
            using (VideoCapture capture2 = new VideoCapture(OutVideoFile))
            using (Window window = new Window("result"))
            {
                int sleepTime = (int)(1000 / capture.Fps);

                Mat frame = new Mat();
                while (true)
                {
                    capture2.Read(frame);
                    if(frame.Empty())
                        break;

                    window.ShowImage(frame);
                    Cv2.WaitKey(sleepTime);
                }
            }
        }
开发者ID:jorik041,项目名称:opencvsharp,代码行数:54,代码来源:VideoWriterSample.cs

示例3: CaptureCameraCallback

        private void CaptureCameraCallback()
        {
            while (Window.WaitKey(10) < 0)
            {
                using (var image = new Mat())
                {
                    cap.Read(image);
                    if (image.Empty())
                        break;

                    pictureBox1.Image = GetChannel(image).ToBitmap();
                }
            }
        }
开发者ID:mmcs-robotics,项目名称:mapping_2015,代码行数:14,代码来源:Form1.cs

示例4: Run

 public void Run()
 {
     using (var capture = new VideoCapture(FilePath.Bach))
     using (var mog = new BackgroundSubtractorMOG())
     using (var windowSrc = new Window("src"))
     using (var windowDst = new Window("dst"))
     {
         var frame = new Mat();
         var fg = new Mat();
         while (true)
         {
             capture.Read(frame);
             if(frame.Empty())
                 break;
             mog.Run(frame, fg, 0.01);
             
             windowSrc.Image = frame;
             windowDst.Image = fg;
             Cv2.WaitKey(50);
         }
     }
 }
开发者ID:healtech,项目名称:opencvsharp,代码行数:22,代码来源:BgSubtractorMOG.cs

示例5: Run

        public void Run()
        {
            // Opens MP4 file (ffmpeg is probably needed)
            VideoCapture capture = new VideoCapture(FilePath.Movie.Bach);

            int sleepTime = (int)Math.Round(1000 / capture.Fps);

            using (Window window = new Window("capture"))
            {
                // Frame image buffer
                Mat image = new Mat();

                // When the movie playback reaches end, Mat.data becomes NULL.
                while (true)
                {
                    capture.Read(image); // same as cvQueryFrame
                    if(image.Empty())
                        break;

                    window.ShowImage(image);
                    Cv2.WaitKey(sleepTime);
                } 
            }
        }
开发者ID:0sv,项目名称:opencvsharp,代码行数:24,代码来源:VideoCaptureSample.cs

示例6: StartStreaming

        public void StartStreaming()
        {
            var tFrame = new Mat();

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            while (true)
            {
                _capture.Read(tFrame);
                if (tFrame.Empty())
                    break;

                Cv2.Transpose(tFrame, tFrame);
                Cv2.Flip(tFrame, _frame, FlipMode.X);

                var fps = string.Format("FPS: {0:F1}", (double)1000 / stopwatch.ElapsedMilliseconds);
                AppGlobals.Form.SetStreamFrame(_frame, fps);

                stopwatch.Restart();

                Thread.Sleep(10);
            }
        }
开发者ID:mmcs-robotics,项目名称:mapping_2015,代码行数:24,代码来源:Camera.cs

示例7: PreviewCamera

        public static List<Mat> PreviewCamera(bool savePictureMode)
        {
            // Opens a camera device
            var capture = new VideoCapture(0);
            if (!capture.IsOpened())
                return null;
            var returnedMat = new List<Mat>();

            var frame = new Mat();
            var returnedframe = new Mat();

            while (true)
            {
                // Read image
                capture.Read(frame);
                if (frame.Empty())
                    return null;

                Cv2.ImShow("Camera", frame);
                var key = Cv2.WaitKey(30);

                if (key == 27) //wait for esc key
                {
                    Cv2.DestroyAllWindows();
                    return returnedMat;
                }
                if (key == 115) //wait for s
                {
                    returnedframe = frame.Clone();
                    returnedMat.Add(returnedframe);
                }
            }
        }
开发者ID:Muraad,项目名称:DynamoOpenCV,代码行数:33,代码来源:OpenCv.cs


注:本文中的Mat.Empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。