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 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()); } }
private async Task ResizePicture(string extension, MMALEncoding encoding, MMALEncoding pixelFormat, int width, int height) { using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", extension)) using (var resizer = new MMALResizerComponent()) using (var imgEncoder = new MMALImageEncoder()) using (var nullSink = new MMALNullSinkComponent()) { this.Cam.ConfigureCameraSettings(); await Task.Delay(2000); var resizerConfig = new MMALPortConfig(pixelFormat, pixelFormat, width, height, 0, 0, 0, false, null); var encoderConfig = new MMALPortConfig(encoding, pixelFormat, 90); // Create our component pipeline. resizer.ConfigureInputPort(new MMALPortConfig(MMALCameraConfig.StillEncoding, MMALCameraConfig.StillSubFormat), this.Cam.Camera.StillPort, null); resizer.ConfigureOutputPort(resizerConfig, null); imgEncoder.ConfigureOutputPort(encoderConfig, imgCaptureHandler); this.Cam.Camera.StillPort.ConnectTo(resizer); resizer.Outputs[0].ConnectTo(imgEncoder); this.Cam.Camera.PreviewPort.ConnectTo(nullSink); await this.Cam.ProcessAsync(this.Cam.Camera.StillPort); } }
private void TakePicture(object sender, EventArgs e) { if (ReloadConfig) { this.MMALCamera.ConfigureCameraSettings(); ConfigForm.ReloadConfig = false; } using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", "jpg")) using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler)) using (var renderer = new MMALVideoRenderer()) { this.MMALCamera.ConfigureCameraSettings(); // Create our component pipeline. imgEncoder.ConfigureOutputPort(0, MMALEncoding.JPEG, MMALEncoding.I420, 90); this.MMALCamera.Camera.StillPort.ConnectTo(imgEncoder); this.MMALCamera.Camera.PreviewPort.ConnectTo(renderer); Task.Factory.Run(async() => { // Camera warm up time await Task.Delay(5000); await this.MMALCamera.BeginProcessing(this.MMALCamera.Camera.StillPort); }); } }
public async Task TakePictureWithInMemoryHandler() { TestHelper.BeginTest("TakePictureWithInMemoryHandler"); TestHelper.SetConfigurationDefaults(); var imgCaptureHandler = new InMemoryCaptureHandler(); using (var preview = new MMALNullSinkComponent()) using (var imgEncoder = new MMALImageEncoder(true)) { 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); Assert.True(imgCaptureHandler.WorkingData.Count > 0); } }
public async Task JpegThumbnail() { TestHelper.BeginTest("Image - JpegThumbnail"); TestHelper.SetConfigurationDefaults(); TestHelper.CleanDirectory("/home/pi/images/tests"); JpegThumbnail tm = new JpegThumbnail(true, 200, 200, 90); using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg")) using (var preview = new MMALNullSinkComponent()) using (var imgEncoder = new MMALImageEncoder(thumbnailConfig: tm)) { 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); } }
public async Task TakePicturesFromVideoPortWithCustomFilename(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat) { TestHelper.BeginTest("TakePicturesFromVideoPortWithCustomFilename", encodingType.EncodingName, pixelFormat.EncodingName); TestHelper.SetConfigurationDefaults(); TestHelper.CleanDirectory("/home/pi/images/tests"); using (var imgCaptureHandler = new ImageStreamCaptureHandler($"/home/pi/images/tests/fromVideoPort.{extension}")) using (var splitter = new MMALSplitterComponent()) using (var preview = new MMALNullSinkComponent()) using (var imgEncoder = new MMALImageEncoder(continuousCapture: true)) { Fixture.MMALCamera.ConfigureCameraSettings(); var portConfig = new MMALPortConfig(encodingType, pixelFormat, quality: 90); imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler); // Create our component pipeline. Fixture.MMALCamera.Camera.VideoPort .ConnectTo(splitter); splitter.Outputs[0].ConnectTo(imgEncoder); Fixture.MMALCamera.Camera.PreviewPort .ConnectTo(preview); // Camera warm up time await Task.Delay(2000); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.VideoPort, cts.Token); Fixture.CheckAndAssertDirectory(imgCaptureHandler.Directory); } }
public async Task TakePictureTimeout() { TestHelper.BeginTest("TakePictureTimeout"); TestHelper.SetConfigurationDefaults(); 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()) { 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); var timeout = DateTime.Now.AddSeconds(10); while (DateTime.Now.CompareTo(timeout) < 0) { await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort); } Fixture.CheckAndAssertDirectory(imgCaptureHandler.Directory); } }
public void TakePictureTimeout(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat) { AsyncContext.Run(async() => { var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests/split_tests", extension); TestHelper.CleanDirectory("/home/pi/images/tests/split_tests"); using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler)) { 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(); var timeout = DateTime.Now.AddSeconds(30); while (DateTime.Now.CompareTo(timeout) < 0) { await fixture.MMALCamera.BeginProcessing(fixture.MMALCamera.Camera.StillPort, imgEncoder); } } }); }
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 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 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"); } } }); }
/// <summary> /// Self-contained method for capturing timelapse images. /// An MMALImageEncoder component will be created and attached to the still port. /// </summary> /// <param name="handler">The image capture handler to apply to the encoder component.</param> /// <param name="encodingType">The image encoding type e.g. JPEG, BMP.</param> /// <param name="pixelFormat">The pixel format to use with the encoder e.g. I420 (YUV420).</param> /// <param name="timelapse">A Timelapse object which specifies the timeout and rate at which images should be taken.</param> /// <returns>The awaitable Task.</returns> /// <exception cref="ArgumentNullException"/> public async Task TakePictureTimelapse(IFileStreamCaptureHandler handler, MMALEncoding encodingType, MMALEncoding pixelFormat, Timelapse timelapse) { int interval = 0; if (timelapse == null) { throw new ArgumentNullException(nameof(timelapse), "Timelapse object null. This must be initialized for Timelapse mode"); } using (var imgEncoder = new MMALImageEncoder()) using (var renderer = new MMALNullSinkComponent()) { this.ConfigureCameraSettings(); var portConfig = new MMALPortConfig(encodingType, pixelFormat, 90); imgEncoder.ConfigureOutputPort(portConfig, handler); // Create our component pipeline. this.Camera.StillPort.ConnectTo(imgEncoder); this.Camera.PreviewPort.ConnectTo(renderer); // Camera warm up time await Task.Delay(2000).ConfigureAwait(false); while (!timelapse.CancellationToken.IsCancellationRequested) { switch (timelapse.Mode) { case TimelapseMode.Millisecond: interval = timelapse.Value; break; case TimelapseMode.Second: interval = timelapse.Value * 1000; break; case TimelapseMode.Minute: interval = (timelapse.Value * 60) * 1000; break; } await Task.Delay(interval).ConfigureAwait(false); MMALLog.Logger.LogInformation($"Preparing to take picture. Resolution: {MMALCameraConfig.StillResolution.Width} x {MMALCameraConfig.StillResolution.Height}. " + $"Encoder: {encodingType.EncodingName}. Pixel Format: {pixelFormat.EncodingName}."); await this.ProcessAsync(this.Camera.StillPort).ConfigureAwait(false); if (!timelapse.CancellationToken.IsCancellationRequested) { handler.NewFile(); } } } }
private void ConfigureButton() { _buttonPin.PinMode = GpioPinDriveMode.Input; _button = new Unosquare.RaspberryIO.Peripherals.Button(_buttonPin); _buttonPin.InputPullMode = GpioPinResistorPullMode.PullUp; MMALLog.Logger.Debug($"Input button configured"); _button.Released += (s, e) => { MMALLog.Logger.Debug($"Button released"); }; _button.Pressed += (s, e) => { MMALLog.Logger.Debug($"Button pressed"); if (Processing) { return; } Processing = true; if (ReloadConfig) { this.MMALCamera.ConfigureCameraSettings(); ConfigForm.ReloadConfig = false; } AsyncContext.Run(async() => { using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", "jpg")) using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler)) using (var renderer = new MMALVideoRenderer()) { this.MMALCamera.ConfigureCameraSettings(); // Create our component pipeline. imgEncoder.ConfigureOutputPort(0, MMALEncoding.JPEG, MMALEncoding.I420, 90); this.MMALCamera.Camera.StillPort.ConnectTo(imgEncoder); this.MMALCamera.Camera.PreviewPort.ConnectTo(renderer); await Task.Delay(2000); await this.MMALCamera.BeginProcessing(this.MMALCamera.Camera.StillPort); Processing = false; } }); }; }
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"); }
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()); } }
public async Task TakePictureTimelapse() { TestHelper.BeginTest("TakePictureTimelapse"); TestHelper.SetConfigurationDefaults(); 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()) { 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); // Camera warm up time await Task.Delay(2000); CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); Timelapse tl = new Timelapse { Mode = TimelapseMode.Second, CancellationToken = cts.Token, Value = 5 }; while (!tl.CancellationToken.IsCancellationRequested) { int interval = tl.Value * 1000; await Task.Delay(interval); await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort); } Fixture.CheckAndAssertDirectory(imgCaptureHandler.Directory); } }
/// <summary> /// Self-contained method for capturing a single image from the camera still port. /// An MMALImageEncoder component will be created and attached to the still port. /// </summary> /// <param name="handler">The image capture handler to apply to the encoder component</param> /// <param name="encodingType">The image encoding type e.g. JPEG, BMP</param> /// <param name="pixelFormat">The pixel format to use with the encoder e.g. I420 (YUV420)</param> /// <returns>The awaitable Task</returns> public async Task TakePicture(ImageStreamCaptureHandler handler, MMALEncoding encodingType, MMALEncoding pixelFormat) { using (var imgEncoder = new MMALImageEncoder(handler)) using (var renderer = new MMALNullSinkComponent()) { imgEncoder.ConfigureOutputPort(0, encodingType, pixelFormat, 90); //Create our component pipeline. this.Camera.StillPort.ConnectTo(imgEncoder); this.Camera.PreviewPort.ConnectTo(renderer); this.ConfigureCameraSettings(); //Enable the image encoder output port. MMALLog.Logger.Info($"Preparing to take picture. Resolution: {imgEncoder.Width} x {imgEncoder.Height}. " + $"Encoder: {encodingType.EncodingName}. Pixel Format: {pixelFormat.EncodingName}."); await BeginProcessing(this.Camera.StillPort, imgEncoder); } }
public async Task GrabImageAsync() { var camera = MMALCamera.Instance; using (var imgCaptureHandler = new ImageStreamCaptureHandler(Path.Combine(Folder, Image), "jpg")) using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler)) using (var renderer = new MMALNullSinkComponent()) { imgEncoder.ConfigureOutputPort(0, MMALEncoding.JPEG, MMALEncoding.I420, 90); camera.Camera.StillPort.ConnectTo(imgEncoder); camera.Camera.PreviewPort.ConnectTo(renderer); camera.ConfigureCameraSettings(); await camera.BeginProcessing(camera.Camera.StillPort); } camera.Cleanup(); LastImageFilename = Path.Combine(Image, GetLastFile(Path.Combine(Folder, Image)).Name); }
private async Task TakePictureManual(string extension, MMALEncoding encoding, MMALEncoding pixelFormat) { using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/", extension)) using (var imgEncoder = new MMALImageEncoder()) using (var nullSink = new MMALNullSinkComponent()) { this.Cam.ConfigureCameraSettings(); await Task.Delay(2000); var encoderConfig = new MMALPortConfig(encoding, pixelFormat, quality: 90); // Create our component pipeline. imgEncoder.ConfigureOutputPort(encoderConfig, imgCaptureHandler); this.Cam.Camera.StillPort.ConnectTo(imgEncoder); this.Cam.Camera.PreviewPort.ConnectTo(nullSink); await this.Cam.ProcessAsync(this.Cam.Camera.StillPort); } }
public void TakePictureTimelapse(string extension, MMALEncoding encodingType, MMALEncoding pixelFormat) { AsyncContext.Run(async() => { var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests/split_tests", extension); TestHelper.CleanDirectory("/home/pi/images/tests/split_tests"); using (var imgEncoder = new MMALImageEncoder(imgCaptureHandler)) { fixture.MMALCamera.ConfigureCameraSettings(); imgEncoder.ConfigureOutputPort(0, encodingType, pixelFormat, 90); //Create our component pipeline. fixture.MMALCamera.Camera.StillPort .ConnectTo(imgEncoder); fixture.MMALCamera.Camera.PreviewPort .ConnectTo(new MMALNullSinkComponent()); Timelapse tl = new Timelapse { Mode = TimelapseMode.Second, Timeout = DateTime.Now.AddSeconds(30), Value = 5 }; while (DateTime.Now.CompareTo(tl.Timeout) < 0) { int interval = tl.Value * 1000; await Task.Delay(interval); //Camera warm up time await Task.Delay(2000); await fixture.MMALCamera.BeginProcessing(fixture.MMALCamera.Camera.StillPort); } } }); }
public async Task <byte[]> TakePicture(int quality) { using (var jpegCaptureHandler = new InMemoryCaptureHandler()) using (var imageEncoder = new MMALImageEncoder()) using (var nullSink = new MMALNullSinkComponent()) { lock (this) { MMALCamera.Instance.ConfigureCameraSettings(); } MMALPortConfig portConfigJPEG = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: quality); imageEncoder.ConfigureOutputPort(portConfigJPEG, jpegCaptureHandler); MMALCamera.Instance.Camera.StillPort.ConnectTo(imageEncoder); MMALCamera.Instance.Camera.PreviewPort.ConnectTo(nullSink); await MMALCamera.Instance.ProcessAsync(MMALCamera.Instance.Camera.StillPort); return(jpegCaptureHandler.WorkingData.ToArray()); } }
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"); } } }); }
private static void TakePictureAndSave() { using (var imgCaptureHandler = new ImageStreamCaptureHandler(pathToSavePicture + "/", "jpg")) using (var imgEncoder = new MMALImageEncoder()) using (var nullSink = new MMALNullSinkComponent()) { cam.ConfigureCameraSettings(); var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, 90); // Create our component pipeline. imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler); cam.Camera.StillPort.ConnectTo(imgEncoder); cam.Camera.PreviewPort.ConnectTo(nullSink); // Camera warm up time Thread.Sleep(2000); cam.ProcessAsync(cam.Camera.StillPort); Thread.Sleep(2000); } }
private async Task BuildCameraPipelineAsync(CancellationToken cancellationToken) { camera.ConfigureCameraSettings(); this.imageEncoder = new MMALImageEncoder(); this.memoryStreamHandler = new MemoryStreamCaptureHandler(); this.resizer = new MMALResizerComponent(); this.nullSink = new MMALNullSinkComponent(); this.portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, 90); this.resizerPortConfig = new MMALPortConfig(MMALEncoding.I420, MMALEncoding.I420, 1024, 768, 0, 0, 0, false, null); this.imageEncoder.ConfigureOutputPort(this.portConfig, memoryStreamHandler); this.resizer.ConfigureInputPort(new MMALPortConfig(MMALEncoding.OPAQUE, MMALEncoding.I420), camera.Camera.StillPort, null) .ConfigureOutputPort(this.resizerPortConfig, null); camera.Camera.StillPort.ConnectTo(resizer); this.resizer.Outputs[0].ConnectTo(imageEncoder); camera.Camera.PreviewPort.ConnectTo(nullSink); await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken); }
private void ClearCameraPipeline() { if (this.nullSink != null) { this.nullSink.Dispose(); this.nullSink = null; } if (this.imageEncoder != null) { this.imageEncoder.Dispose(); this.imageEncoder = null; } if (this.resizer != null) { this.resizer.Dispose(); this.resizer = null; } if (this.memoryStreamHandler != null) { this.memoryStreamHandler.Dispose(); this.memoryStreamHandler = null; } }
/// <summary> /// Wires up the various image processing components. /// </summary> protected virtual void ConfigurePipeline() { Console.WriteLine("Preparing pipeline."); VideoCaptureHandler = new CircularBufferCaptureHandler(4000000, AppConfig.Get.LocalPath, "h264"); MotionCaptureHandler = new FrameBufferCaptureHandler(); SnapshotCaptureHandler = new FrameBufferCaptureHandler(directory: AppConfig.Get.LocalPath, extension: "jpg", fileDateTimeFormat: Program.FILENAME_DATE_FORMAT); Splitter = new MMALSplitterComponent(); Resizer = new MMALIspComponent(); VideoEncoder = new MMALVideoEncoder(); SnapshotEncoder = new MMALImageEncoder(continuousCapture: true); Resizer.ConfigureOutputPort <VideoPort>(0, new MMALPortConfig(MMALEncoding.RGB24, MMALEncoding.RGB24, width: 640, height: 480), MotionCaptureHandler); VideoEncoder.ConfigureOutputPort(new MMALPortConfig(MMALEncoding.H264, MMALEncoding.I420, quality: 10, MMALVideoEncoder.MaxBitrateLevel4), VideoCaptureHandler); SnapshotEncoder.ConfigureOutputPort(new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: 90), SnapshotCaptureHandler); Cam.Camera.VideoPort.ConnectTo(Splitter); Splitter.Outputs[0].ConnectTo(Resizer); Splitter.Outputs[1].ConnectTo(VideoEncoder); Splitter.Outputs[2].ConnectTo(SnapshotEncoder); }
/// <summary> /// Self-contained method for capturing a single image from the camera still port. /// An MMALImageEncoder component will be created and attached to the still port. /// </summary> /// <param name="handler">The image capture handler to apply to the encoder component.</param> /// <param name="encodingType">The image encoding type e.g. JPEG, BMP.</param> /// <param name="pixelFormat">The pixel format to use with the encoder e.g. I420 (YUV420).</param> /// <returns>The awaitable Task.</returns> public async Task TakePicture(IOutputCaptureHandler handler, MMALEncoding encodingType, MMALEncoding pixelFormat) { using (var imgEncoder = new MMALImageEncoder()) using (var renderer = new MMALNullSinkComponent()) { this.ConfigureCameraSettings(); var portConfig = new MMALPortConfig(encodingType, pixelFormat, 90); imgEncoder.ConfigureOutputPort(portConfig, handler); // Create our component pipeline. this.Camera.StillPort.ConnectTo(imgEncoder); this.Camera.PreviewPort.ConnectTo(renderer); MMALLog.Logger.LogInformation($"Preparing to take picture. Resolution: {this.Camera.StillPort.Resolution.Width} x {this.Camera.StillPort.Resolution.Height}. " + $"Encoder: {encodingType.EncodingName}. Pixel Format: {pixelFormat.EncodingName}."); // Camera warm up time await Task.Delay(2000).ConfigureAwait(false); await this.ProcessAsync(this.Camera.StillPort).ConfigureAwait(false); } }
public async Task ImageFxComponentFromCameraStillPortSetColourEnhancement() { TestHelper.BeginTest("Image - ImageFxComponentFromCameraStillPortSetColourEnhancement"); 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); imageFx.ImageEffect = MMAL_PARAM_IMAGEFX_T.MMAL_PARAM_IMAGEFX_SOLARIZE; imageFx.ColourEnhancement = new ColourEffects(true, Color.Blue); // 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); } }