private async void _structuredLightSingleCaptureButton_Click(object sender, EventArgs e) { if (!CheckConnection()) { return; } //Show screen ShowProjectorScreenBtnOnClick(null, null); // Initialize structured light structuredLight = new StructuredLight(episcan.Screen.Size); if (!structuredLight.LoadCalibrationData()) { MessageBox.Show("No calibration data loaded"); } var frames = await ProjectPatternsAndCaptureAsync(); var disparity = structuredLight.CalculateDisparity(frames); var sfd = new SaveFileDialog { Filter = "Txt file (*.txt)|*.txt|All files(*.*)|*.*" }; if (sfd.ShowDialog() == DialogResult.OK) { File.WriteAllLines(sfd.FileName, disparity.Select(s => String.Join(" ", s))); } }
public async Task CalibrateStructuredLightAsync(double planeDistance, double baseline, double focalLength) { if (!CheckConnection()) { return; } // Show screen ShowProjectorScreenBtnOnClick(null, null); // Initialize structured light structuredLight = StructuredLight.CalibrationSetup(episcan.Screen.Size); // Project patterns and capture var frames = await ProjectPatternsAndCaptureAsync(); structuredLight.Calibrate(planeDistance, baseline, focalLength, frames); structuredLight.Calib.Save(); }
private async void delaySweepStartButton_Click(object sender, EventArgs e) { if (!CheckConnection()) { return; } _manualModeRb.Checked = true; UpdateDelayExposure(); // Show screen ShowProjectorScreenBtnOnClick(null, null); var sfd = new SaveFileDialog() { Filter = "PNG file (*.png)|*.png|All files(*.*)|*.*", FileName = "capture.png" }; if (sfd.ShowDialog() != DialogResult.OK) { return; } var basename = Path.GetDirectoryName(sfd.FileName) + @"/" + Path.GetFileNameWithoutExtension(sfd.FileName); // color mode var isEightBit = episcan.Sensor.PixelFormat == MySensor.PixelFormatList.Mono8 | episcan.Sensor.PixelFormat == MySensor.PixelFormatList.BGR24; var isMono = episcan.Sensor.PixelFormat == MySensor.PixelFormatList.Mono8 | episcan.Sensor.PixelFormat == MySensor.PixelFormatList.Mono12; // capture black //episcan.Screen.BackColor = Color.Black; _syncDelayNud.Value = 0; UpdateDelayExposure(); await Task.Delay(50); var averageNum = (int)sweepAverageInput.Value; var blackFilename = basename + "_black.png"; if (isEightBit) { var black = await CaptureAverage8Async(averageNum); black = CropImage(black, episcan.Sensor.Width, episcan.Sensor.Height, Roi); if (isMono) { ImageFileUtil.Png.SaveGray8(blackFilename, Roi[2], Roi[3], black); } else { ImageFileUtil.Png.SaveRgb24(blackFilename, Roi[2], Roi[3], black); } } else { var black = await CaptureAverage12Async(averageNum); black = CropImage(black, episcan.Sensor.Width, episcan.Sensor.Height, Roi); if (isMono) { ImageFileUtil.Png.SaveGray16(blackFilename, Roi[2], Roi[3], black); } // if (isMono) ImageFileUtil.Png.SaveBgr48(blackFilename, Roi[2], Roi[3], black); } // capture delay sweep var delayMin = sweepFromInput.Value; var delayMax = sweepToInput.Value; var delayStep = sweepStepInput.Value; var pcMin = PC_From.Value; var pcMax = PC_To.Value; var pcStep = PC_Step.Value; episcan.Screen.BackColor = Color.White; var captureNum = (delayMax - delayMin) / delayStep + 1; var pccapNum = (pcMax - pcMin) / pcStep + 1; for (int pc = 0; pc < pccapNum; pc++) { var pcvalue = (int)(pcMin + pc * pcStep); var foname = basename + $"_{pcvalue:D2}" + @"/" + Path.GetFileNameWithoutExtension(sfd.FileName); Directory.CreateDirectory(foname); episcan.Sensor.PixelClock = pcvalue; //_pixelClockCb.ValueMember = pcvalue.ToString(); for (int i = 0; i < captureNum; i++) { var delay = (int)(delayMin + i * delayStep); _syncDelayNud.Value = delay; UpdateDelayExposure(); //await Task.Delay(50); var exposure = (int)Math.Round(episcan.Sensor.Exposure * 1000); var suffix = $"_{i:D4}_{exposure:D5}_{delay:D5}"; var sweepFilename = foname + suffix + ".png"; if (isEightBit) { var arr = await CaptureAverage8Async(averageNum); arr = CropImage(arr, episcan.Sensor.Width, episcan.Sensor.Height, Roi); if (isMono) { ImageFileUtil.Png.SaveGray8(sweepFilename, Roi[2], Roi[3], arr); } else { ImageFileUtil.Png.SaveBgr24(sweepFilename, Roi[2], Roi[3], arr); } } else { var arr = await CaptureAverage12Async(averageNum); arr = CropImage(arr, episcan.Sensor.Width, episcan.Sensor.Height, Roi); if (isMono) { ImageFileUtil.Png.SaveGray16(sweepFilename, Roi[2], Roi[3], arr); } else { ImageFileUtil.Png.SaveBgr48(sweepFilename, Roi[2], Roi[3], arr); } } } } // measure disparity structuredLight = new StructuredLight(episcan.Screen.Size); if (!structuredLight.LoadCalibrationData()) { MessageBox.Show("No calibration data loaded"); } _syncDelayNud.Value = 0; UpdateDelayExposure(); await Task.Delay(50); var frames = await ProjectPatternsAndCaptureAsync(); var disparity = structuredLight.CalculateDisparity(frames); File.WriteAllLines(basename + "_disp.txt", disparity.Select(s => String.Join(" ", s))); // restart capture UpdateDelayExposure(); if (delaySweepTurnOffProjector.Checked) { ProjectorPowerToggleBtnOnClick(null, null); } }