protected override void Dispose(bool disposing) { base.Dispose(disposing); if (_bgModel != null) { _bgModel.Dispose(); _bgModel = null; } if (_fgModel != null) { _fgModel.Dispose(); _fgModel = null; } if (_calc != null) { _calc.Dispose(); _calc = null; } if (_foreground != null) { _foreground.Dispose(); _foreground = null; } if (_markerBuffer != null) { Marshal.FreeHGlobal((IntPtr)_markerBuffer); _markerBuffer = null; } if (_laser != null) { _laser.Dispose(); _laser = null; } if (_scanner != null) { _scanner.Hit(new IppiPoint_32f(0.0f, 0.0f)); _scanner.Dispose(); _scanner = null; } if (_strel3x3 != null) { _strel3x3.Dispose(); _strel3x3 = null; } }
/// <summary> /// Runs the initial three point calibration to find approximate camera height and angle/reflection /// </summary> /// <param name="frameNumber">The current camera frame number</param> /// <param name="camImage">The camera image</param> /// <param name="poi">The detected beam centroid</param> protected void ThreePointCalibration(int frameNumber, Image8 camImage, out IppiPoint?poi) { poi = null; //Points not set in _threePointPoints are set to -1,-1. Use this to track which point we handle right now if (_threePointPoints.Origin.x == -1) { //Work on origin var p = MoveAndDetect(_threePointFrame, camImage, new IppiPoint_32f(0.0f, 0.0f)); if (p.x != -1) { //found the point _threePointFrame = -1; //will be incremented to 0 below! _threePointPoints.Origin = new IppiPoint(p.x, p.y); _p0 = new IppiPoint(p.x, p.y); //set our origin coordinates for later calculations poi = p; //reset foreground in preparation for x movement _fgModel.Dispose(); _fgModel = new DynamicBackgroundModel(camImage, 5.0f / Properties.Settings.Default.FrameRate); } } else if (_threePointPoints.XMove.x == -1) { //Work on x-displacement var p = MoveAndDetect(_threePointFrame, camImage, new IppiPoint_32f(Properties.Settings.Default.MirrorXVAln, 0.0f)); if (p.x != -1) { //found the point _threePointFrame = -1;//will be incremented to 0 below! _threePointPoints.XMove = new IppiPoint(p.x, p.y); poi = p; //reset foreground in preparation for y movement _fgModel.Dispose(); _fgModel = new DynamicBackgroundModel(camImage, 5.0f / Properties.Settings.Default.FrameRate); } } else if (_threePointPoints.YMove.x == -1) { //Work on y-displacement var p = MoveAndDetect(_threePointFrame, camImage, new IppiPoint_32f(0.0f, Properties.Settings.Default.MirrorYVAln)); if (p.x != -1) { //found the point _threePointFrame = -1;//will be incremented to 0 below! _threePointPoints.YMove = new IppiPoint(p.x, p.y); poi = p; //reset foreground in preparation of interpolation table building _fgModel.Dispose(); _fgModel = new DynamicBackgroundModel(camImage, 20.0f / Properties.Settings.Default.FrameRate); } } else { //Use results to calculate calibration //Height double camera_height_x = CalculateHeight(_threePointPoints.XMove, MirrorAngle(Properties.Settings.Default.MirrorXVAln)); System.Diagnostics.Debug.WriteLine("Height according to x-mirror is: {0}", camera_height_x); double camera_height_y = CalculateHeight(_threePointPoints.YMove, MirrorAngle(Properties.Settings.Default.MirrorYVAln)); System.Diagnostics.Debug.WriteLine("Height according to y-mirror is: {0}", camera_height_y); _camera_height = (camera_height_x + camera_height_y) / 2.0; //Theta and reflection double theta_x = CalculateCameraTheta(_threePointPoints.XMove, false); System.Diagnostics.Debug.WriteLine("Theta according to x-mirror is: {0}", theta_x); double theta_y = CalculateCameraTheta(_threePointPoints.YMove, true); System.Diagnostics.Debug.WriteLine("Theta according to y-mirror is: {0}", theta_y); _isYReflected = CheckReflection(theta_x, theta_y, out _camera_theta); System.Diagnostics.Debug.WriteLine("Y reflection: {0}", _isYReflected); System.Diagnostics.Debug.WriteLine("Final camera theta is: {0}", _camera_theta); _experimentPhase = ExperimentPhases.InterpTable; _interpParams = new InterpolationParams(); //At this point have 10 pixel borders around camera image in the interpolation ROI _interpParams.LookupTable = new BLIScanLookupTable(new IppiROI(10, 10, camImage.Width - 20, camImage.Height - 20), 4); } _threePointFrame++; }