/// <summary> /// Second Calibration Phase /// Performing: /// 1. Find Calibration Marks to verify image is fine /// 2. Update Table Image Processing Coverage /// 3. Recalculate Homography matrices /// </summary> /// <param name="frame"></param> private void Finalize(IFrame frame) { //ignore first frames if (_skippedFrames < FRAMES_TO_SKIP) { _skippedFrames++; } else { try { _skippedFrames = 0; Log.Print("***** Starting calibration Phase II... *****", eCategory.Info, LogTag.IMAGE); Image <Gray, byte> image = frame.Image.Clone(); //Remove Noise from picture image = CalibrationUtils.PrepareFrame(image); ComputerVisionMonitors[eComputerVisionMonitor.MonitorA].ShowFrame(image); //Find Calibration Marks List <CircleF> circles = FindCalibrationMarks(image); CalibrationUtils.VerifyMarksFound(circles); //Update coverage ImagingData.CalibrationMarks = CalibrationUtils.UpdateCoverage(ImagingData.CalibrationMarks); Log.Print("Coverage and marks updated.", eCategory.Info, LogTag.IMAGE); //Show table border marks Marks.DrawTableBorders(ImagingData.CalibrationMarks); //Recalculate Homography Matrix CalibrationUtils.SetTransformationMatrix(AXE_X_LENGTH, AXE_Y_LENGTH, ImagingData.CalibrationMarks); Log.Print("Homography matrix re-calculated.", eCategory.Info, LogTag.IMAGE); CurrentState = eCalibrationState.Finished; Log.Print("***** Finished calibration Phase II *****", eCategory.Info, LogTag.IMAGE); } catch (CalibrationException ex) { Log.Print(String.Format("Calibration failed in second phase. Will retry after [{0}] frames. Reason: {1}", FRAMES_TO_SKIP, ex.Message), eCategory.Warn, LogTag.IMAGE); } } }