Exemplo n.º 1
0
        public async Task <ActionResult> GetImage()
        {
            if (DateTime.Now.Hour > 18 || DateTime.Now.Hour < 7)
            {
                _logger.LogInformation("Tuning for night mode...");
                MMALCameraConfig.ExposureCompensation = (int)MMAL_PARAM_EXPOSUREMODE_T.MMAL_PARAM_EXPOSUREMODE_NIGHT;
            }
            else
            {
                _logger.LogInformation("Tuning for normal mode...");
                MMALCameraConfig.ExposureCompensation = (int)MMAL_PARAM_EXPOSUREMODE_T.MMAL_PARAM_EXPOSUREMODE_OFF;
            }
            byte[] imageData;
            using (var imgCaptureHandler = new MemoryStreamCaptureHandler())
            {
                _logger.LogInformation("Capturing the picture...");
                await _camera.TakePicture(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420);

                imageData = new byte[imgCaptureHandler.CurrentStream.Length];
                imgCaptureHandler.CurrentStream.Seek(0, System.IO.SeekOrigin.Begin);
                imgCaptureHandler.CurrentStream.Read(imageData, 0, imageData.Length);
                _logger.LogInformation("Captured the picture...");
            }
            return(File(imageData, "image/jpeg"));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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;
     }
 }