public void TakePictureRawSensor(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat)
        {
            TestHelper.BeginTest("TakePictureRawSensor", encodingType.EncodingName, pixelFormat.EncodingName);
            TestHelper.SetConfigurationDefaults();

            AsyncContext.Run(async() =>
            {
                using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", extension))
                {
                    TestHelper.CleanDirectory("/home/pi/images/tests");

                    await _fixture.MMALCamera.TakeRawPicture(imgCaptureHandler);

                    var encodings = _fixture.MMALCamera.Camera.StillPort.GetSupportedEncodings();

                    if (System.IO.File.Exists(imgCaptureHandler.GetFilepath()))
                    {
                        var length = new System.IO.FileInfo(imgCaptureHandler.GetFilepath()).Length;

                        if (encodings.Contains(encodingType.EncodingVal))
                        {
                            Assert.True(length > 1);
                        }
                    }
                    else
                    {
                        Assert.True(false, $"File {imgCaptureHandler.GetFilepath()} was not created");
                    }
                }
            });
        }
        public void TakePictureRawBayer(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat)
        {
            AsyncContext.Run(async() =>
            {
                var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", extension);

                TestHelper.CleanDirectory("/home/pi/images/tests");

                using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler, true))
                {
                    imgEncoder.ConfigureOutputPort(0, encodingType, pixelFormat, 90);

                    //Create our component pipeline.
                    fixture.MMALCamera.Camera.StillPort
                    .ConnectTo(imgEncoder);
                    fixture.MMALCamera.Camera.PreviewPort
                    .ConnectTo(new MMALNullSinkComponent());

                    fixture.MMALCamera.ConfigureCameraSettings();

                    await fixture.MMALCamera.BeginProcessing(fixture.MMALCamera.Camera.StillPort, imgEncoder);
                }

                if (System.IO.File.Exists(imgCaptureHandler.GetFilepath()))
                {
                    var length = new System.IO.FileInfo(imgCaptureHandler.GetFilepath()).Length;
                    Assert.True(length > 0);
                }
                else
                {
                    Assert.True(false, $"File {imgCaptureHandler.GetFilepath()} was not created");
                }
            });
        }
        public async Task TakePictureRawBayer(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat)
        {
            TestHelper.BeginTest("TakePictureRawBayer", encodingType.EncodingName, pixelFormat.EncodingName);
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", extension))
                using (var preview = new MMALNullSinkComponent())
                    using (var imgEncoder = new MMALImageEncoder(true))
                    {
                        Fixture.MMALCamera.ConfigureCameraSettings();

                        var portConfig = new MMALPortConfig(encodingType, pixelFormat, quality: 90);

                        imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);

                        // Create our component pipeline.
                        Fixture.MMALCamera.Camera.StillPort
                        .ConnectTo(imgEncoder);
                        Fixture.MMALCamera.Camera.PreviewPort
                        .ConnectTo(preview);

                        // Camera warm up time
                        await Task.Delay(2000);

                        await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                        Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                    }
        }
        public async Task UserProvidedBufferNumAndSize()
        {
            TestHelper.BeginTest("UserProvidedBufferNumAndSize");
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            MMALCameraConfig.UserBufferNum  = 10;
            MMALCameraConfig.UserBufferSize = 20000;

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                using (var preview = new MMALNullSinkComponent())
                    using (var imgEncoder = new MMALImageEncoder())
                    {
                        Fixture.MMALCamera.ConfigureCameraSettings();

                        var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90);

                        imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);

                        // Create our component pipeline.
                        Fixture.MMALCamera.Camera.StillPort
                        .ConnectTo(imgEncoder);
                        Fixture.MMALCamera.Camera.PreviewPort
                        .ConnectTo(preview);

                        // Camera warm up time
                        await Task.Delay(2000);

                        await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                        Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                    }
        }
        public async Task TakePictureWithCustomConnectionCallbackHandler()
        {
            TestHelper.BeginTest("TakePictureWithCustomConnectionCallbackHandler");
            TestHelper.SetConfigurationDefaults();

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                using (var preview = new MMALNullSinkComponent())
                    using (var imgEncoder = new MMALImageEncoder())
                    {
                        Fixture.MMALCamera.ConfigureCameraSettings();

                        var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90);

                        imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);

                        // Create our component pipeline.
                        var connection = Fixture.MMALCamera.Camera.StillPort
                                         .ConnectTo(imgEncoder, 0, true);

                        Fixture.MMALCamera.Camera.PreviewPort
                        .ConnectTo(preview);

                        // Register our custom connection callback handler.
                        connection.RegisterCallbackHandler(new CustomConnectionCallbackHandler(connection));

                        // Camera warm up time
                        await Task.Delay(2000);

                        await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                        Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                    }
        }
        public async Task EdgeDetectionKernelProcessor(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat)
        {
            TestHelper.BeginTest("EdgeDetectionKernelProcessor", encodingType.EncodingName, pixelFormat.EncodingName);
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", extension))
                using (var preview = new MMALNullSinkComponent())
                    using (var imgEncoder = new MMALImageEncoder())
                    {
                        Fixture.MMALCamera.ConfigureCameraSettings();

                        var portConfig = new MMALPortConfig(encodingType, pixelFormat, 90);

                        imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);

                        // Create our component pipeline.
                        Fixture.MMALCamera.Camera.StillPort
                        .ConnectTo(imgEncoder);
                        Fixture.MMALCamera.Camera.PreviewPort
                        .ConnectTo(preview);

                        imgCaptureHandler.Manipulate(context =>
                        {
                            context.Apply(new EdgeDetection(EDStrength.High));
                        }, ImageFormat.Jpeg);

                        // Camera warm up time
                        await Task.Delay(2000);

                        await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                        Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                    }
        }
        public void TakePictureTimelapse()
        {
            TestHelper.BeginTest("TakePictureTimelapse");
            TestHelper.SetConfigurationDefaults();

            AsyncContext.Run(async() =>
            {
                TestHelper.CleanDirectory("/home/pi/images/tests/split_tests");

                using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests/split_tests", "jpg"))
                    using (var preview = new MMALNullSinkComponent())
                        using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                        {
                            _fixture.MMALCamera.ConfigureCameraSettings();

                            imgEncoder.ConfigureOutputPort(0, MMALEncoding.JPEG, MMALEncoding.I420, 90);

                            // Create our component pipeline.
                            _fixture.MMALCamera.Camera.StillPort
                            .ConnectTo(imgEncoder);
                            _fixture.MMALCamera.Camera.PreviewPort
                            .ConnectTo(preview);

                            CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
                            Timelapse tl = new Timelapse
                            {
                                Mode = TimelapseMode.Second,
                                CancellationToken = cts.Token,
                                Value             = 5
                            };

                            // Camera warm up time
                            await Task.Delay(2000);

                            while (!tl.CancellationToken.IsCancellationRequested)
                            {
                                int interval = tl.Value * 1000;

                                await Task.Delay(interval);

                                await _fixture.MMALCamera.ProcessAsync(_fixture.MMALCamera.Camera.StillPort);
                            }

                            DirectoryInfo info = new DirectoryInfo(imgCaptureHandler.Directory);

                            if (info.Exists)
                            {
                                var files = info.EnumerateFiles();

                                Assert.True(files != null && files.Count() == 6);
                            }
                            else
                            {
                                Assert.True(false, $"File {imgCaptureHandler.GetFilepath()} was not created");
                            }
                        }
            });
        }
        public void TakePicture(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat)
        {
            TestHelper.BeginTest("TakePicture", encodingType.EncodingName, pixelFormat.EncodingName);
            TestHelper.SetConfigurationDefaults();

            AsyncContext.Run(async() =>
            {
                TestHelper.CleanDirectory("/home/pi/images/tests");

                using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", extension))
                    using (var preview = new MMALNullSinkComponent())
                        using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                        {
                            _fixture.MMALCamera.ConfigureCameraSettings();

                            imgEncoder.ConfigureOutputPort(encodingType, pixelFormat, 90);

                            // Create our component pipeline.
                            _fixture.MMALCamera.Camera.StillPort
                            .ConnectTo(imgEncoder);
                            _fixture.MMALCamera.Camera.PreviewPort
                            .ConnectTo(preview);

                            // Camera warm up time
                            await Task.Delay(2000);

                            await _fixture.MMALCamera.ProcessAsync(_fixture.MMALCamera.Camera.StillPort);

                            if (System.IO.File.Exists(imgCaptureHandler.GetFilepath()))
                            {
                                var length = new System.IO.FileInfo(imgCaptureHandler.GetFilepath()).Length;
                                Assert.True(length > 0);
                            }
                            else
                            {
                                Assert.True(false, $"File {imgCaptureHandler.GetFilepath()} was not created");
                            }
                        }
            });
        }
        public void ChangeEncodingType()
        {
            TestHelper.BeginTest("Image - ChangeEncodingType");
            TestHelper.SetConfigurationDefaults();

            AsyncContext.Run(async() =>
            {
                TestHelper.CleanDirectory("/home/pi/images/tests");

                using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                    using (var preview = new MMALNullSinkComponent())
                        using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                        {
                            _fixture.MMALCamera.ConfigureCameraSettings();

                            imgEncoder.ConfigureOutputPort(MMALEncoding.JPEG, MMALEncoding.I420, 90);

                            // Create our component pipeline.
                            _fixture.MMALCamera.Camera.StillPort
                            .ConnectTo(imgEncoder);
                            _fixture.MMALCamera.Camera.PreviewPort
                            .ConnectTo(preview);

                            // Camera warm up time
                            await Task.Delay(2000);

                            await _fixture.MMALCamera.ProcessAsync(_fixture.MMALCamera.Camera.StillPort);

                            _fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                        }

                using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "bmp"))
                    using (var preview = new MMALNullSinkComponent())
                        using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                        {
                            imgEncoder.ConfigureOutputPort(MMALEncoding.BMP, MMALEncoding.I420, 90);

                            // Create our component pipeline.
                            _fixture.MMALCamera.Camera.StillPort
                            .ConnectTo(imgEncoder);
                            _fixture.MMALCamera.Camera.PreviewPort
                            .ConnectTo(preview);

                            await _fixture.MMALCamera.ProcessAsync(_fixture.MMALCamera.Camera.StillPort);

                            _fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                        }
            });
        }
        public async Task StripBayerData()
        {
            TestHelper.BeginTest("Image - StripBayerData");
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            string filepath = string.Empty;

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "raw"))
                using (var preview = new MMALNullSinkComponent())
                    using (var imgEncoder = new MMALImageEncoder(true))
                    {
                        Fixture.MMALCamera.ConfigureCameraSettings();

                        var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, 90);

                        imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);

                        // Create our component pipeline.
                        Fixture.MMALCamera.Camera.StillPort
                        .ConnectTo(imgEncoder);
                        Fixture.MMALCamera.Camera.PreviewPort
                        .ConnectTo(preview);

                        imgCaptureHandler.Manipulate(context =>
                        {
                            context.StripBayerMetadata(CameraVersion.OV5647);
                        }, ImageFormat.Jpeg);

                        // Camera warm up time
                        await Task.Delay(2000);

                        await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                        filepath = imgCaptureHandler.GetFilepath();
                    }

            byte[] meta = new byte[4];

            var array = File.ReadAllBytes(filepath);

            // Uncomment depending on which version of the camera you're using.

            // Array.Copy(array, array.Length - BayerMetaProcessor.BayerMetaLengthV1, meta, 0, 4);
            Array.Copy(array, array.Length - BayerMetaProcessor.BayerMetaLengthV2, meta, 0, 4);

            Assert.True(Encoding.ASCII.GetString(meta) == "BRCM");
        }
Esempio n. 11
0
        public async Task ImageFxComponentFromCameraStillPort(MMAL_PARAM_IMAGEFX_T effect, bool throwsException)
        {
            TestHelper.BeginTest($"Image - ImageFxComponentFromCameraStillPort - {effect}");
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                using (var preview = new MMALNullSinkComponent())
                    using (var imageFx = new MMALImageFxComponent())
                        using (var imgEncoder = new MMALImageEncoder())
                        {
                            Fixture.MMALCamera.ConfigureCameraSettings();

                            var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90);
                            var fxConfig   = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420);

                            imageFx.ConfigureOutputPort(fxConfig, null);
                            imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);

                            if (throwsException)
                            {
                                Assert.Throws <MMALInvalidException>(() =>
                                {
                                    imageFx.ImageEffect = effect;
                                });
                            }
                            else
                            {
                                imageFx.ImageEffect = effect;
                            }

                            // Create our component pipeline.
                            Fixture.MMALCamera.Camera.StillPort
                            .ConnectTo(imageFx);
                            Fixture.MMALCamera.Camera.PreviewPort
                            .ConnectTo(preview);

                            imageFx.Outputs[0].ConnectTo(imgEncoder);

                            // Camera warm up time
                            await Task.Delay(2000);

                            await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                            Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                        }
        }
Esempio n. 12
0
        public async Task TakePicturesDirectlyFromSplitterComponent()
        {
            TestHelper.BeginTest("TakePicturesDirectlyFromSplitterComponent");
            TestHelper.SetConfigurationDefaults();

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "raw"))
                using (var imgCaptureHandler2 = new ImageStreamCaptureHandler("/home/pi/images/tests", "raw"))
                    using (var imgCaptureHandler3 = new ImageStreamCaptureHandler("/home/pi/images/tests", "raw"))
                        using (var imgCaptureHandler4 = new ImageStreamCaptureHandler("/home/pi/images/tests", "raw"))
                            using (var splitter = new MMALSplitterComponent())
                                using (var nullSink = new MMALNullSinkComponent())
                                {
                                    Fixture.MMALCamera.ConfigureCameraSettings();

                                    var splitterConfig = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420);

                                    // Create our component pipeline.
                                    splitter.ConfigureOutputPort <SplitterStillPort>(0, splitterConfig, imgCaptureHandler);
                                    splitter.ConfigureOutputPort <SplitterStillPort>(1, splitterConfig, imgCaptureHandler2);
                                    splitter.ConfigureOutputPort <SplitterStillPort>(2, splitterConfig, imgCaptureHandler3);
                                    splitter.ConfigureOutputPort <SplitterStillPort>(3, splitterConfig, imgCaptureHandler4);

                                    Fixture.MMALCamera.Camera.StillPort.ConnectTo(splitter);
                                    Fixture.MMALCamera.Camera.PreviewPort.ConnectTo(nullSink);

                                    // Camera warm up time
                                    await Task.Delay(2000);

                                    await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler2.GetFilepath());
                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler3.GetFilepath());
                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler4.GetFilepath());
                                }
        }
Esempio n. 13
0
        public void StaticOverlay()
        {
            TestHelper.BeginTest("StaticOverlay");
            TestHelper.SetConfigurationDefaults();

            MMALCameraConfig.StillResolution = Resolution.As03MPixel;
            MMALCameraConfig.StillEncoding   = MMALEncoding.I420;
            MMALCameraConfig.StillSubFormat  = MMALEncoding.I420;

            AsyncContext.Run(async() =>
            {
                var filename = string.Empty;

                using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests/staticoverlay", "raw"))
                {
                    TestHelper.CleanDirectory("/home/pi/images/tests");
                    TestHelper.CleanDirectory("/home/pi/images/tests/staticoverlay");

                    await _fixture.MMALCamera.TakeRawPicture(imgCaptureHandler);

                    filename = imgCaptureHandler.GetFilepath();
                }

                PreviewConfiguration previewConfig = new PreviewConfiguration
                {
                    FullScreen    = false,
                    PreviewWindow = new Rectangle(160, 0, 640, 480),
                    Layer         = 2,
                    Opacity       = 1
                };

                MMALCameraConfig.StillResolution = Resolution.As1080p;
                MMALCameraConfig.StillEncoding   = MMALEncoding.OPAQUE;

                using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                    using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                        using (var video = new MMALVideoRenderer(previewConfig))
                        {
                            _fixture.MMALCamera.ConfigureCameraSettings();
                            video.ConfigureRenderer();

                            PreviewOverlayConfiguration overlayConfig = new PreviewOverlayConfiguration
                            {
                                FullScreen    = true,
                                PreviewWindow = new Rectangle(50, 0, 640, 480),
                                Layer         = 1,
                                Resolution    = new Resolution(640, 480),
                                Encoding      = MMALEncoding.I420,
                                Opacity       = 255
                            };

                            var overlay = _fixture.MMALCamera.AddOverlay(video, overlayConfig, File.ReadAllBytes(filename));
                            overlay.ConfigureRenderer();
                            overlay.UpdateOverlay();

                            // Create our component pipeline.
                            imgEncoder.ConfigureOutputPort(0, MMALEncoding.JPEG, MMALEncoding.I420, 90);

                            _fixture.MMALCamera.Camera.StillPort.ConnectTo(imgEncoder);
                            _fixture.MMALCamera.Camera.PreviewPort.ConnectTo(video);

                            _fixture.MMALCamera.PrintPipeline();

                            await _fixture.MMALCamera.ProcessAsync(_fixture.MMALCamera.Camera.StillPort);

                            if (System.IO.File.Exists(imgCaptureHandler.GetFilepath()))
                            {
                                var length = new System.IO.FileInfo(imgCaptureHandler.GetFilepath()).Length;
                                Assert.True(length > 0);
                            }
                            else
                            {
                                Assert.True(false, $"File {imgCaptureHandler.GetFilepath()} was not created");
                            }
                        }
            });
        }
        public void ChangeEncodingType()
        {
            AsyncContext.Run(async() =>
            {
                var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg");

                TestHelper.CleanDirectory("/home/pi/images/tests");

                using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                {
                    fixture.MMALCamera.ConfigureCameraSettings();

                    imgEncoder.ConfigureOutputPort(0, MMALEncoding.JPEG, MMALEncoding.I420, 90);

                    //Create our component pipeline.
                    fixture.MMALCamera.Camera.StillPort
                    .ConnectTo(imgEncoder);
                    fixture.MMALCamera.Camera.PreviewPort
                    .ConnectTo(new MMALNullSinkComponent());

                    //Camera warm up time
                    await Task.Delay(2000);

                    await fixture.MMALCamera.BeginProcessing(fixture.MMALCamera.Camera.StillPort);
                }

                if (System.IO.File.Exists(imgCaptureHandler.GetFilepath()))
                {
                    var length = new System.IO.FileInfo(imgCaptureHandler.GetFilepath()).Length;
                    Assert.True(length > 0);
                }
                else
                {
                    Assert.True(false, $"File {imgCaptureHandler.GetFilepath()} was not created");
                }

                imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "bmp");

                using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                {
                    imgEncoder.ConfigureOutputPort(0, MMALEncoding.BMP, MMALEncoding.I420, 90);

                    //Create our component pipeline.
                    fixture.MMALCamera.Camera.StillPort
                    .ConnectTo(imgEncoder);
                    fixture.MMALCamera.Camera.PreviewPort
                    .ConnectTo(new MMALNullSinkComponent());

                    //Camera warm up time
                    await Task.Delay(2000);

                    await fixture.MMALCamera.BeginProcessing(fixture.MMALCamera.Camera.StillPort);
                }

                if (System.IO.File.Exists(imgCaptureHandler.GetFilepath()))
                {
                    var length = new System.IO.FileInfo(imgCaptureHandler.GetFilepath()).Length;
                    Assert.True(length > 0);
                }
                else
                {
                    Assert.True(false, $"File {imgCaptureHandler.GetFilepath()} was not created");
                }
            });
        }
Esempio n. 15
0
        public async Task UserProvidedPortName()
        {
            TestHelper.BeginTest("UserProvidedPortName");
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                using (var imgCaptureHandler2 = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                    using (var imgCaptureHandler3 = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                        using (var imgCaptureHandler4 = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                            using (var imgEncoder = new MMALImageEncoder())
                                using (var imgEncoder2 = new MMALImageEncoder())
                                    using (var imgEncoder3 = new MMALImageEncoder())
                                        using (var imgEncoder4 = new MMALImageEncoder())
                                            using (var splitter = new MMALSplitterComponent())
                                                using (var isp1 = new MMALIspComponent())
                                                    using (var isp2 = new MMALIspComponent())
                                                        using (var isp3 = new MMALIspComponent())
                                                            using (var isp4 = new MMALIspComponent())
                                                                using (var nullSink = new MMALNullSinkComponent())
                                                                {
                                                                    Fixture.MMALCamera.ConfigureCameraSettings();

                                                                    var portConfig  = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90, userPortName: "Image encoder 1");
                                                                    var portConfig2 = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90, userPortName: "Image encoder 2");
                                                                    var portConfig3 = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90, userPortName: "Image encoder 3");
                                                                    var portConfig4 = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90, userPortName: "Image encoder 4");

                                                                    var splitterConfig = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420);

                                                                    var resizeConfig  = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 1280, height: 720);
                                                                    var resizeConfig2 = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 1024, height: 720);
                                                                    var resizeConfig3 = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 640, height: 480);
                                                                    var resizeConfig4 = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 620, height: 310);

                                                                    // Create our component pipeline.
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(0, splitterConfig, null);
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(1, splitterConfig, null);
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(2, splitterConfig, null);
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(3, splitterConfig, null);

                                                                    isp1.ConfigureOutputPort(resizeConfig, null);
                                                                    isp2.ConfigureOutputPort(resizeConfig2, null);
                                                                    isp3.ConfigureOutputPort(resizeConfig3, null);
                                                                    isp4.ConfigureOutputPort(resizeConfig4, null);

                                                                    imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);
                                                                    imgEncoder2.ConfigureOutputPort(portConfig2, imgCaptureHandler2);
                                                                    imgEncoder3.ConfigureOutputPort(portConfig3, imgCaptureHandler3);
                                                                    imgEncoder4.ConfigureOutputPort(portConfig4, imgCaptureHandler4);

                                                                    Fixture.MMALCamera.Camera.StillPort.ConnectTo(splitter);
                                                                    Fixture.MMALCamera.Camera.PreviewPort.ConnectTo(nullSink);

                                                                    splitter.Outputs[0].ConnectTo(isp1);
                                                                    splitter.Outputs[1].ConnectTo(isp2);
                                                                    splitter.Outputs[2].ConnectTo(isp3);
                                                                    splitter.Outputs[3].ConnectTo(isp4);

                                                                    isp1.Outputs[0].ConnectTo(imgEncoder);
                                                                    isp2.Outputs[0].ConnectTo(imgEncoder2);
                                                                    isp3.Outputs[0].ConnectTo(imgEncoder3);
                                                                    isp4.Outputs[0].ConnectTo(imgEncoder4);

                                                                    // Camera warm up time
                                                                    await Task.Delay(2000);

                                                                    await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler2.GetFilepath());
                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler3.GetFilepath());
                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler4.GetFilepath());
                                                                }
        }
Esempio n. 16
0
        public async Task TakeMultiplePicturesFromSplitterComponent()
        {
            // This test relies on an ISP component being connected between a splitter component output port
            // and an image encoder input port. If the ISP component is not used as a go-between, the splitter
            // component appears to only accept 1 of its output ports being connected to an image encoder. I believe
            // this may be a firmware restriction.
            TestHelper.BeginTest("TakeMultiplePicturesFromSplitterComponent");
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                using (var imgCaptureHandler2 = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                    using (var imgCaptureHandler3 = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                        using (var imgCaptureHandler4 = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                            using (var imgEncoder = new MMALImageEncoder())
                                using (var imgEncoder2 = new MMALImageEncoder())
                                    using (var imgEncoder3 = new MMALImageEncoder())
                                        using (var imgEncoder4 = new MMALImageEncoder())
                                            using (var splitter = new MMALSplitterComponent())
                                                using (var isp1 = new MMALIspComponent())
                                                    using (var isp2 = new MMALIspComponent())
                                                        using (var isp3 = new MMALIspComponent())
                                                            using (var isp4 = new MMALIspComponent())
                                                                using (var nullSink = new MMALNullSinkComponent())
                                                                {
                                                                    Fixture.MMALCamera.ConfigureCameraSettings();

                                                                    var portConfig  = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90);
                                                                    var portConfig2 = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90);
                                                                    var portConfig3 = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90);
                                                                    var portConfig4 = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90);

                                                                    var splitterConfig = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420);

                                                                    var resizeConfig  = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 1280, height: 720);
                                                                    var resizeConfig2 = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 1024, height: 720);
                                                                    var resizeConfig3 = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 640, height: 480);
                                                                    var resizeConfig4 = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, width: 620, height: 310);

                                                                    // Create our component pipeline.
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(0, splitterConfig, null);
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(1, splitterConfig, null);
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(2, splitterConfig, null);
                                                                    splitter.ConfigureOutputPort <SplitterStillPort>(3, splitterConfig, null);

                                                                    isp1.ConfigureOutputPort(resizeConfig, null);
                                                                    isp2.ConfigureOutputPort(resizeConfig2, null);
                                                                    isp3.ConfigureOutputPort(resizeConfig3, null);
                                                                    isp4.ConfigureOutputPort(resizeConfig4, null);

                                                                    imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler);
                                                                    imgEncoder2.ConfigureOutputPort(portConfig2, imgCaptureHandler2);
                                                                    imgEncoder3.ConfigureOutputPort(portConfig3, imgCaptureHandler3);
                                                                    imgEncoder4.ConfigureOutputPort(portConfig4, imgCaptureHandler4);

                                                                    Fixture.MMALCamera.Camera.StillPort.ConnectTo(splitter);
                                                                    Fixture.MMALCamera.Camera.PreviewPort.ConnectTo(nullSink);

                                                                    splitter.Outputs[0].ConnectTo(isp1);
                                                                    splitter.Outputs[1].ConnectTo(isp2);
                                                                    splitter.Outputs[2].ConnectTo(isp3);
                                                                    splitter.Outputs[3].ConnectTo(isp4);

                                                                    isp1.Outputs[0].ConnectTo(imgEncoder);
                                                                    isp2.Outputs[0].ConnectTo(imgEncoder2);
                                                                    isp3.Outputs[0].ConnectTo(imgEncoder3);
                                                                    isp4.Outputs[0].ConnectTo(imgEncoder4);

                                                                    // Camera warm up time
                                                                    await Task.Delay(2000);

                                                                    await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler2.GetFilepath());
                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler3.GetFilepath());
                                                                    Fixture.CheckAndAssertFilepath(imgCaptureHandler4.GetFilepath());
                                                                }
        }
Esempio n. 17
0
        public async Task <TakePhotoResponse> TakePhotoAsync(TakePhotoRequest takePhotoRequest)
        {
            var cameraWasUsed = false;


            if (IsTakingTimelapse())
            {
                return(new TakePhotoResponse()
                {
                    ErrorMessage = $"Timelapse {currentTimelapseId?.ToString()} is being taken",
                });
            }

            try
            {
                var path = EnsureLocalDirectoryExists();

                await cameraInUse.WaitAsync();

                cameraWasUsed = true;

                using (var imgCaptureHandler = new ImageStreamCaptureHandler(path, takePhotoRequest.ImageType))
                {
                    var stopwatch = Stopwatch.StartNew();

                    if (takePhotoRequest.QuickMode)
                    {
                        await camera.TakeRawPicture(imgCaptureHandler);
                    }
                    else
                    {
                        await camera.TakePicture(imgCaptureHandler, takePhotoRequest.GetImageEncoding(), takePhotoRequest.GetPixelFormatEncoding());
                    }
                    stopwatch.Stop();

                    var localFilePath = imgCaptureHandler.GetFilepath();
                    var blobName      = await UploadFileAsync("photos", localFilePath);

                    var fi = new FileInfo(localFilePath);
                    Logger.Log($"New photo: {fi.Length} bytes, in {stopwatch.ElapsedMilliseconds}ms");

                    if (takePhotoRequest.DeleteLocalFile)
                    {
                        File.Delete(localFilePath);
                    }

                    return(new TakePhotoResponse()
                    {
                        BlobName = blobName,
                        LocalFilePath = localFilePath,
                        DeleteLocalFile = takePhotoRequest.DeleteLocalFile,
                        PixelFormat = takePhotoRequest.PixelFormat,
                        ImageType = takePhotoRequest.ImageType,
                        QuickMode = takePhotoRequest.QuickMode,
                    });
                }
            }
            finally
            {
                if (cameraWasUsed)
                {
                    cameraInUse.Release();
                }
            }
        }
Esempio n. 18
0
        public async Task EncodeDecodeFromFile()
        {
            TestHelper.BeginTest("Image - EncodeDecodeFromFile");
            TestHelper.SetConfigurationDefaults();
            TestHelper.CleanDirectory("/home/pi/images/tests");

            string imageFilepath   = string.Empty;
            string decodedFilepath = string.Empty;

            // First take a new JPEG picture using RGB24 encoding.
            using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg"))
                using (var preview = new MMALNullSinkComponent())
                    using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler))
                    {
                        Fixture.MMALCamera.ConfigureCameraSettings();

                        var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.RGB24, 90);

                        imgEncoder.ConfigureOutputPort(portConfig);

                        // Create our component pipeline.
                        Fixture.MMALCamera.Camera.StillPort
                        .ConnectTo(imgEncoder);
                        Fixture.MMALCamera.Camera.PreviewPort
                        .ConnectTo(preview);

                        // Camera warm up time
                        await Task.Delay(2000);

                        await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort);

                        Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());

                        imageFilepath = imgCaptureHandler.GetFilepath();
                    }

            // Next decode the JPEG to raw YUV420.
            using (var stream = File.OpenRead(imageFilepath))
                using (var imgCaptureHandler = new TransformStreamCaptureHandler(stream, "/home/pi/images/", "raw"))
                    using (var imgDecoder = new MMALImageFileDecoder(imgCaptureHandler))
                    {
                        var inputConfig  = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.RGB24, 2560, 1920, 0, 0, 0, true, null);
                        var outputConfig = new MMALPortConfig(MMALEncoding.I420, null, 2560, 1920, 0, 0, 0, true, null);

                        // Create our component pipeline.
                        imgDecoder.ConfigureInputPort(inputConfig)
                        .ConfigureOutputPort(outputConfig);

                        await imgDecoder.Convert();

                        Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());

                        decodedFilepath = imgCaptureHandler.GetFilepath();
                    }

            // Finally re-encode to BMP using YUV420.
            using (var stream = File.OpenRead(decodedFilepath))
                using (var imgCaptureHandler = new TransformStreamCaptureHandler(stream, "/home/pi/images/", "bmp"))
                    using (var imgEncoder = new MMALImageFileEncoder(imgCaptureHandler))
                    {
                        var inputConfig  = new MMALPortConfig(MMALEncoding.I420, null, 2560, 1920, 0, 0, 0, true, null);
                        var outputConfig = new MMALPortConfig(MMALEncoding.BMP, MMALEncoding.I420, 2560, 1920, 0, 0, 0, true, null);

                        imgEncoder.ConfigureInputPort(inputConfig)
                        .ConfigureOutputPort(outputConfig);

                        await imgEncoder.Convert();

                        Fixture.CheckAndAssertFilepath(imgCaptureHandler.GetFilepath());
                    }
        }