예제 #1
0
        public void WriteAndCapture()
        {
            using var image = Image("lenna.png");

            {
                using var writer = new VideoWriter("dummy1.avi", FourCCValues.MJPG, 10, image.Size());
                Assert.True(writer.IsOpened());
                writer.Write(image);
                writer.Write(image);
                writer.Write(image);
            }

            using var capture = new VideoCapture("dummy1.avi");
            Assert.True(capture.IsOpened());
            Assert.Equal("CV_MJPEG", capture.GetBackendName());
            Assert.Equal(3, capture.FrameCount);

            using var frame1 = new Mat();
            using var frame2 = new Mat();
            using var frame3 = new Mat();
            using var frame4 = new Mat();
            Assert.True(capture.Read(frame1));
            Assert.True(capture.Read(frame2));
            Assert.True(capture.Read(frame3));
            Assert.False(capture.Read(frame4));
            Assert.False(frame1.Empty());
            Assert.False(frame2.Empty());
            Assert.False(frame3.Empty());
            Assert.True(frame4.Empty());

            Assert.Equal(image.Size(), frame1.Size());
        }
예제 #2
0
        public void WriteAndCapture()
        {
            const string fileName = "dummy1.avi";

            try
            {
                using var image = Image("lenna.png");

                {
                    using var writer = new VideoWriter(fileName, VideoCaptureAPIs.OPENCV_MJPEG, FourCC.MJPG, 10, image.Size());
                    Assert.True(writer.IsOpened());
                    writer.Write(image);
                    writer.Write(image);
                    writer.Write(image);
                }

                using var capture = new VideoCapture(fileName);
                Assert.True(capture.IsOpened());

                var backendName = capture.GetBackendName();
                testOutputHelper.WriteLine($"[{nameof(WriteAndCapture)}] BackendName: {backendName}");
                Assert.True(backendName == "MSMF" || backendName == "CV_MJPEG" || backendName == "FFMPEG",
                            $"Unexpected VideoWriter backend: {backendName}");

                Assert.Equal(3, capture.FrameCount);

                using var frame1 = new Mat();
                using var frame2 = new Mat();
                using var frame3 = new Mat();
                using var frame4 = new Mat();
                Assert.True(capture.Read(frame1));
                Assert.True(capture.Read(frame2));
                Assert.True(capture.Read(frame3));
                Assert.False(capture.Read(frame4));
                Assert.False(frame1.Empty());
                Assert.False(frame2.Empty());
                Assert.False(frame3.Empty());
                Assert.True(frame4.Empty());

                Assert.Equal(image.Size(), frame1.Size());
            }
            finally
            {
                DeleteFile(fileName);
            }
        }
예제 #3
0
        public void GrabAndRetrieveImageSequence()
        {
            using var capture = new VideoCapture("_data/image/blob/shapes%d.png");
            using var image1  = new Mat("_data/image/blob/shapes1.png", ImreadModes.Color);
            using var image2  = new Mat("_data/image/blob/shapes2.png", ImreadModes.Color);
            using var image3  = new Mat("_data/image/blob/shapes3.png", ImreadModes.Color);

            Assert.True(capture.IsOpened());
            Assert.Equal("CV_IMAGES", capture.GetBackendName());
            Assert.Equal(3, capture.FrameCount);

            using var frame1 = new Mat();
            using var frame2 = new Mat();
            using var frame3 = new Mat();
            using var frame4 = new Mat();
            Assert.True(capture.Grab());
            Assert.True(capture.Retrieve(frame1));
            Assert.True(capture.Grab());
            Assert.True(capture.Retrieve(frame2));
            Assert.True(capture.Grab());
            Assert.True(capture.Retrieve(frame3));
            Assert.False(capture.Grab());
            Assert.False(capture.Retrieve(frame4));

            Assert.False(frame1.Empty());
            Assert.False(frame2.Empty());
            Assert.False(frame3.Empty());
            Assert.True(frame4.Empty());

            Cv2.CvtColor(frame1, frame1, ColorConversionCodes.BGRA2BGR);
            Cv2.CvtColor(frame2, frame2, ColorConversionCodes.BGRA2BGR);
            Cv2.CvtColor(frame3, frame3, ColorConversionCodes.BGRA2BGR);
            ImageEquals(image1, frame1);
            ImageEquals(image2, frame2);
            ImageEquals(image3, frame3);

            if (Debugger.IsAttached)
            {
                Window.ShowImages(frame1, frame2, frame3, frame4);
            }
        }
예제 #4
0
        public void StartWebcam()
        {
            Log.Debug("Starting Camera... {0}", "Channel 0");

            frame   = new Mat();
            capture = new VideoCapture();

            try
            {
                capture.Open(0);

                Log.Debug("GetBackendName {0}", capture.GetBackendName());
                Log.Debug("Channel  {0}", capture.Get(VideoCaptureProperties.Channel));
                Log.Debug("IsOpened  {0}", capture.IsOpened());
            }
            catch (Exception e)
            {
                Log.Fatal("Failed to find cam {0} ", e.Message);
                return;
            }
        }