static MMALCamera GetConfiguredCamera() { if (useDebug) { Console.WriteLine("\nVerbose debug logging enabled to debug.log in current directory."); File.Delete("debug.log"); MMALCameraConfig.Debug = true; MMALLog.LoggerFactory = new LoggerFactory() .AddSerilog(new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.File("debug.log") .CreateLogger()); } Console.WriteLine("Initializing..."); var cam = MMALCamera.Instance; // 1296 x 972 with 2x2 binning (full-frame 4:3 capture) MMALCameraConfig.StillResolution = new MMALSharp.Common.Utility.Resolution(1296, 972); MMALCameraConfig.VideoResolution = new MMALSharp.Common.Utility.Resolution(1296, 972); MMALCameraConfig.SensorMode = MMALSensorMode.Mode4; MMALCameraConfig.VideoFramerate = new MMAL_RATIONAL_T(24, 1); // numerator & denominator // overlay text var overlay = new AnnotateImage(Environment.MachineName, 30, Color.White) { ShowDateText = true, ShowTimeText = true, }; MMALCameraConfig.Annotate = overlay; cam.EnableAnnotation(); // image quality tweaks to play with later MMALCameraConfig.Sharpness = 0; // 0 = auto, default; -100 to 100 MMALCameraConfig.Contrast = 0; // 0 = auto, default; -100 to 100 MMALCameraConfig.Brightness = 50; // 50 = default; 0 = black, 100 = white MMALCameraConfig.Saturation = 0; // 0 = default; -100 to 100 MMALCameraConfig.ExposureCompensation = 0; // 0 = none, default; -10 to 10, lightens/darkens the image // low-light tweaks which don't seem to degrade full-light recording MMALCameraConfig.ExposureMode = MMAL_PARAM_EXPOSUREMODE_T.MMAL_PARAM_EXPOSUREMODE_NIGHT; MMALCameraConfig.ExposureMeterMode = MMAL_PARAM_EXPOSUREMETERINGMODE_T.MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX; MMALCameraConfig.DrcLevel = MMAL_PARAMETER_DRC_STRENGTH_T.MMAL_PARAMETER_DRC_STRENGTH_HIGH; // produces a grayscale image //MMALCameraConfig.ColourFx = new ColourEffects(true, Color.FromArgb(128, 128, 128)); return(cam); }
/// <summary> /// Camera settings (applies both config and hard-coded defaults). /// </summary> protected virtual void ConfigureCamera() { Console.WriteLine("Configuring camera."); MMALCameraConfig.Resolution = new Resolution(AppConfig.Get.Camera.Width, AppConfig.Get.Camera.Height); MMALCameraConfig.SensorMode = AppConfig.Get.Camera.Mode; MMALCameraConfig.Framerate = AppConfig.Get.Camera.FPS; var overlay = new AnnotateImage(AppConfig.Get.Name, 30, Color.White) { ShowDateText = true, ShowTimeText = true, DateFormat = "yyyy-MM-dd", TimeFormat = "HH:mm:ss", RefreshRate = DateTimeTextRefreshRate.Seconds }; MMALCameraConfig.Annotate = overlay; // image quality tweaks to play with later MMALCameraConfig.Sharpness = 0; // 0 = auto, default; -100 to 100 MMALCameraConfig.Contrast = 0; // 0 = auto, default; -100 to 100 MMALCameraConfig.Brightness = 50; // 50 = default; 0 = black, 100 = white MMALCameraConfig.Saturation = 0; // 0 = default; -100 to 100 MMALCameraConfig.ExposureCompensation = 0; // 0 = none, default; -10 to 10, lightens/darkens the image // low-light tweaks which don't seem to degrade full-light recording MMALCameraConfig.ExposureMode = MMAL_PARAM_EXPOSUREMODE_T.MMAL_PARAM_EXPOSUREMODE_NIGHT; MMALCameraConfig.ExposureMeterMode = MMAL_PARAM_EXPOSUREMETERINGMODE_T.MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX; MMALCameraConfig.DrcLevel = MMAL_PARAMETER_DRC_STRENGTH_T.MMAL_PARAMETER_DRC_STRENGTH_HIGH; // h.264 requires key frames for the circular buffer capture handler MMALCameraConfig.InlineHeaders = true; Cam.ConfigureCameraSettings(); Cam.EnableAnnotation(); }