예제 #1
0
        /// <summary>
        /// Call to initialise the camera component.
        /// </summary>
        /// <param name="stillCaptureHandler">A capture handler when capturing raw image frames from the camera's still port (no encoder attached).</param>
        /// <param name="videoCaptureHandler">A capture handler when capturing raw video from the camera's video port (no encoder attached).</param>
        public void Initialise(IOutputCaptureHandler stillCaptureHandler = null, IOutputCaptureHandler videoCaptureHandler = null)
        {
            this.DisableComponent();

            var camConfig = new MMAL_PARAMETER_CAMERA_CONFIG_T(
                new MMAL_PARAMETER_HEADER_T(MMALParametersCamera.MMAL_PARAMETER_CAMERA_CONFIG, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_CONFIG_T>()),
                MMALCameraConfig.Resolution.Width,
                MMALCameraConfig.Resolution.Height,
                0,
                1,
                MMALCameraConfig.Resolution.Width,
                MMALCameraConfig.Resolution.Height,
                3 + Math.Max(0, (new MMAL_RATIONAL_T(MMALCameraConfig.Framerate).Num - 30) / 10),
                0,
                0,
                MMALCameraConfig.ClockMode);

            this.SetCameraConfig(camConfig);

            MMALLog.Logger.LogDebug("Camera config set");

            this.Control.Start();

            MMALLog.Logger.LogDebug("Configuring camera parameters.");

            this.SetCameraParameters();

            this.InitialisePreview();
            this.InitialiseVideo(videoCaptureHandler);
            this.InitialiseStill(stillCaptureHandler);

            this.EnableComponent();

            MMALLog.Logger.LogDebug("Camera component configured.");
        }
예제 #2
0
        internal void Initialise()
        {
            this.DisableComponent();

            var camConfig = new MMAL_PARAMETER_CAMERA_CONFIG_T(
                new MMAL_PARAMETER_HEADER_T(MMALParametersCamera.MMAL_PARAMETER_CAMERA_CONFIG, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_CONFIG_T>()),
                this.CameraInfo.MaxWidth,
                this.CameraInfo.MaxHeight,
                0,
                1,
                MMALCameraConfig.VideoResolution.Width,
                MMALCameraConfig.VideoResolution.Height,
                3 + Math.Max(0, (MMALCameraConfig.VideoFramerate.Num - 30) / 10),
                0,
                0,
                MMALCameraConfig.ClockMode);

            this.SetCameraConfig(camConfig);

            MMALLog.Logger.Debug("Camera config set");

            this.Control.EnableControlPort();

            MMALLog.Logger.Debug("Configuring camera parameters.");

            this.SetCameraParameters();

            this.InitialisePreview();
            this.InitialiseVideo();
            this.InitialiseStill();

            this.EnableComponent();

            MMALLog.Logger.Debug("Camera component configured.");
        }
예제 #3
0
 internal static void SetCameraConfig(this MMALCameraComponent camera, MMAL_PARAMETER_CAMERA_CONFIG_T value)
 {
     MMALCheck(MMALPort.mmal_port_parameter_set(camera.Control.Ptr, &value.Hdr), "Unable to set camera config.");
 }
예제 #4
0
        public MMALCameraComponent() : base(MMALParameters.MMAL_COMPONENT_DEFAULT_CAMERA)
        {
            if (this.CameraInfo == null)
            {
                this.SetSensorDefaults();
            }
            if (this.Outputs.Count == 0)
            {
                throw new PiCameraError("Camera doesn't have any output ports.");
            }

            this.Control.ObjName = "Control port";

            this.PreviewPort         = this.Outputs[MMALCameraPreviewPort];
            this.PreviewPort.ObjName = "Preview port";

            this.VideoPort         = this.Outputs[MMALCameraVideoPort];
            this.VideoPort.ObjName = "Video port";

            this.StillPort         = this.Outputs[MMALCameraStillPort];
            this.StillPort.ObjName = "Still port";

            /*
             * Stereoscopic mode is only supported with the compute module as it requires two camera modules to work.
             * I have added the code in for consistency with Raspistill, however this project currently only supports one camera module
             * and therefore will not work if enabled.
             * See: https://www.raspberrypi.org/forums/viewtopic.php?p=600720
             */
            this.PreviewPort.SetStereoMode(MMALCameraConfig.StereoMode);
            this.VideoPort.SetStereoMode(MMALCameraConfig.StereoMode);
            this.StillPort.SetStereoMode(MMALCameraConfig.StereoMode);

            this.Control.SetParameter(MMALParametersCamera.MMAL_PARAMETER_CAMERA_NUM, 0);

            var eventRequest = new MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T(new MMAL_PARAMETER_HEADER_T(MMALParametersCommon.MMAL_PARAMETER_CHANGE_EVENT_REQUEST, Marshal.SizeOf <MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T>()),
                                                                         MMALParametersCamera.MMAL_PARAMETER_CAMERA_SETTINGS, 1);

            if (MMALCameraConfig.SetChangeEventRequest)
            {
                this.Control.SetChangeEventRequest(eventRequest);
            }

            var camConfig = new MMAL_PARAMETER_CAMERA_CONFIG_T(new MMAL_PARAMETER_HEADER_T(MMALParametersCamera.MMAL_PARAMETER_CAMERA_CONFIG, Marshal.SizeOf <MMAL_PARAMETER_CAMERA_CONFIG_T>()),
                                                               this.CameraInfo.MaxWidth,
                                                               this.CameraInfo.MaxHeight,
                                                               0,
                                                               1,
                                                               MMALCameraConfig.VideoResolution.Width,
                                                               MMALCameraConfig.VideoResolution.Height,
                                                               3 + Math.Max(0, (MMALCameraConfig.VideoFramerate.Num - 30) / 10),
                                                               0,
                                                               0,
                                                               MMALCameraConfig.ClockMode
                                                               );

            MMALLog.Logger.Debug("Camera config set");

            this.SetCameraConfig(camConfig);

            this.Control.EnablePort((Action <MMALBufferImpl, MMALPortBase>)CameraControlCallback);

            this.Initialise();

            MMALLog.Logger.Debug("Camera component configured.");
        }