public void ImagesToVideo() { TestHelper.BeginTest("ImagesToVideo"); TestHelper.SetConfigurationDefaults(); AsyncContext.Run(async() => { TestHelper.CleanDirectory("/home/pi/videos/tests"); TestHelper.CleanDirectory("/home/pi/images/tests"); // This example will take an image every 5 seconds for 1 minute. using (var imgCaptureHandler = new ImageStreamCaptureHandler("/home/pi/images/tests", "jpg")) { var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)); var tl = new Timelapse { Mode = TimelapseMode.Second, CancellationToken = cts.Token, Value = 5 }; await _fixture.MMALCamera.TakePictureTimelapse(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420, tl); // Process all images captured into a video at 2fps. imgCaptureHandler.ImagesToVideo("/home/pi/videos/tests", 2); _fixture.CheckAndAssertFilepath("/home/pi/videos/tests/out.avi"); } }); }
//private int noteCount = 0; //private int fixedchoiceCount = 0; //private int counterCount = 0; public OptionsWindow(TimelapseWindow mainWindow, Timelapse.MarkableImageCanvas mcanvas) { InitializeComponent(); this.Topmost = true; this.markableCanvas = mcanvas; this.mainProgram = mainWindow; //// The Max Zoom Value sldrMaxZoom.Value = markableCanvas.MaxZoom; sldrMaxZoom.ToolTip = markableCanvas.MaxZoom; sldrMaxZoom.Maximum = markableCanvas.MaxZoomUpperBound; sldrMaxZoom.Minimum = 1; //// Image Differencing Thresholds sldrDifferenceThreshold.Value = mainProgram.differenceThreshold; sldrDifferenceThreshold.ToolTip = mainProgram.differenceThreshold; sldrDifferenceThreshold.Maximum = mainProgram.differenceThresholdMax; sldrDifferenceThreshold.Minimum = mainProgram.differenceThresholdMin; //// For swapping data within notes, fixed choices, or counters: //// Get the counts of each type of code control, as we only need to do this once, //// then generate the contents of the listboxes //this.noteCount = this.mainProgram.codeControls.notes.Length; //this.fixedchoiceCount = this.mainProgram.codeControls.fixedChoice.Length; //this.counterCount = this.mainProgram.codeControls.counters.Length; //GenerateLists(); }
public async Task TakePicturesAsync(string filename, TimeSpan duration, int msWaitBetweenPictures) { try { // Singleton initialized lazily. Reference once in your application. MMALCamera cam = this.MMALSharpCameraInstance; MMALCameraConfig.StillResolution = new Resolution(1080, 920); cam.ConfigureCameraSettings(); using (var imgCaptureHandler = new IndexedImageStreamCaptureHandler(filename)) { Console.WriteLine($"Current filename in handler: {imgCaptureHandler.CurrentFilename}"); var cts = new CancellationTokenSource(duration); var timelapse = new Timelapse { Mode = TimelapseMode.Millisecond, Value = msWaitBetweenPictures, CancellationToken = cts.Token }; await cam.TakePictureTimelapse(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420, timelapse); } // Cleanup disposes all unmanaged resources and unloads Broadcom library. To be called when no more processing is to be done // on the camera. Console.WriteLine($"Wrote picture to: {filename} with running index"); } catch (Exception ex) { Console.WriteLine($"{nameof(MMALSharpCamera)} {nameof(TakePictureAsync)} Failed"); Console.WriteLine($"{nameof(MMALSharpCamera)} {nameof(TakePictureAsync)} {ex.ToString()}"); Console.WriteLine($"{nameof(MMALSharpCamera)} {nameof(TakePictureAsync)} Failed"); } }
protected override int Invoke() { if (InputFiles.Count <= 0) { throw outputCulledFromInput ? new Exception( $"At least one input file must be specified. " + $"'{OutputFile}' was interpreted as an output file.") : new Exception("At least one input file must be specified."); } if (OutputFile is null) { throw new Exception("Output file must be specified."); } var timelapse = new Timelapse( InputFiles, TotalInputDuration, OutputFile, TimeScaleFactor, DesiredDuration); timelapse .InvokeAsync() .GetAwaiter() .GetResult(); return(0); }
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"); } } }); }
protected override void TakeScreenShot() { var args = new ScreenShotArgs { fileName = Owner.filename, Path = Owner.path, ResolutionMultiplier = Owner.scale }; Timelapse?.Stop(); Timelapse = new Timelapse(waitTime, times, args); }
public async Task <TakeTimelapseResponse> StartTimelapseAsync(TakeTimelapseRequest req) { if (IsTakingTimelapse()) { return(new TakeTimelapseResponse() { ErrorMessage = $"Timelapse {currentTimelapseId?.ToString()} is being taken", }); } var cameraUsed = false; try { var path = EnsureLocalDirectoryExists(); currentTimelapseId = Guid.NewGuid().ToString(); var pathForImages = Path.Combine(path, currentTimelapseId); await cameraInUse.WaitAsync(); cameraUsed = true; // This example will take an image every 10 seconds for 4 hours var imgCaptureHandler = new ImageStreamCaptureHandler(pathForImages, "jpg"); timelapseCts = new CancellationTokenSource(TimeSpan.FromSeconds(req.Duration)); var tl = new Timelapse { Mode = TimelapseMode.Second, CancellationToken = timelapseCts.Token, Value = req.Interval }; Logger.Log($"Starting timelapse {currentTimelapseId}"); _ = camera.TakePictureTimelapse(imgCaptureHandler, MMALEncoding.JPEG, MMALEncoding.I420, tl) .ContinueWith(async(t) => await PrepareTimelapseVideoAsync(t, imgCaptureHandler, pathForImages)); return(new TakeTimelapseResponse() { Id = currentTimelapseId, Duration = req.Duration, Interval = req.Interval, }); } catch { if (cameraUsed) { cameraInUse.Release(); } throw; } }
public static Timelapse UpdateSnapsCount(string code, int userId, int count) { var client = new RestClient(Settings.TimelapseAPIUrl); var request = new RestRequest("v1/timelapses/" + code + "/snaps/" + count + "/users/" + userId, Method.POST); var timelapsedata = client.Execute <Timelapse>(request); Timelapse timelapse = timelapsedata.Data; if (timelapsedata == null || timelapsedata.Data == null) { return(new Timelapse()); } return(timelapse); }
public static Timelapse GetTimelapse(string timelapseCode, int userId) { var client = new RestClient(Settings.TimelapseAPIUrl); var request = new RestRequest("v1/timelapses/" + timelapseCode + "/users/" + userId, Method.GET); var timelapsedata = client.Execute <Timelapse>(request); Timelapse timelapse = timelapsedata.Data; if (timelapsedata == null || timelapsedata.Data == null) { return(new Timelapse()); } return(timelapse); }
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); } }
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); } } }); }