예제 #1
0
        /// <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(ImageStreamCaptureHandler 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(handler))
                using (var renderer = new MMALNullSinkComponent())
                {
                    this.ConfigureCameraSettings();

                    imgEncoder.ConfigureOutputPort(encodingType, pixelFormat, 90);

                    // Create our component pipeline.
                    this.Camera.StillPort.ConnectTo(imgEncoder);
                    this.Camera.PreviewPort.ConnectTo(renderer);

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

                    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);

                        MMALLog.Logger.Info($"Preparing to take picture. Resolution: {imgEncoder.Width} x {imgEncoder.Height}. " +
                                            $"Encoder: {encodingType.EncodingName}. Pixel Format: {pixelFormat.EncodingName}.");

                        await this.ProcessAsync(this.Camera.StillPort);
                    }
                }
        }
        /// <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>
        public async Task TakePictureTimelapse(ImageStreamCaptureHandler handler, MMALEncoding encodingType, MMALEncoding pixelFormat, Timelapse timelapse)
        {
            int interval = 0;

            if (timelapse == null)
            {
                throw new PiCameraError("Timelapse object null. This must be initialized for Timelapse mode");
            }

            while (DateTime.Now.CompareTo(timelapse.Timeout) < 0)
            {
                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);

                await TakePicture(handler, encodingType, pixelFormat);
            }
        }