Ejemplo n.º 1
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");
                            }
                        }
            });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of a Video renderer component. This component is intended to be connected to the Camera's preview port
 /// and is used to measure exposure. It also produces real-time video to the Pi's HDMI output from the camera.
 /// </summary>
 /// <param name="config">The configuration object for this renderer.</param>
 public MMALVideoRenderer(PreviewConfiguration config)
     : base(MMALParameters.MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER)
 {
     this.EnableComponent();
     this.Configuration = config;
 }