public static StereoImage<Bgr, byte> DrawChessboardCorners(StereoImage<Bgr, byte> stereoImage, CalibrationCorners corners) { var colors = new Bgr[corners.LeftCorners.Length]; var random = new Random(); for (var i = 0; i < colors.Length; ++i) { colors[i] = new Bgr(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); } DrawChessboardCorners(stereoImage.LeftImage, corners.LeftCorners, colors); DrawChessboardCorners(stereoImage.RightImage, corners.RightCorners, colors); return stereoImage; }
public static StereoImage <Bgr, byte> DrawChessboardCorners(StereoImage <Bgr, byte> stereoImage, CalibrationCorners corners) { var colors = new Bgr[corners.LeftCorners.Length]; var random = new Random(); for (var i = 0; i < colors.Length; ++i) { colors[i] = new Bgr(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); } DrawChessboardCorners(stereoImage.LeftImage, corners.LeftCorners, colors); DrawChessboardCorners(stereoImage.RightImage, corners.RightCorners, colors); return(stereoImage); }
public static CalibrationStereoResult Calibrate(CalibrationSettings settings, CalibrationCorners[] corners) { var calibrationResult = new CalibrationStereoResult(settings); var points = new MCvPoint3D32f[calibrationResult.Settings.Count][]; for (var k = 0; k < calibrationResult.Settings.Count; ++k) { var objects = new List<MCvPoint3D32f>(); for (var i = 0; i < settings.ChessboardHeight; ++i) for (var j = 0; j < settings.ChessboardWidth; ++j) objects.Add(new MCvPoint3D32f(j*settings.CellWidth, i*settings.CellHeight, 0.0F)); points[k] = objects.ToArray(); } ExtrinsicCameraParameters extrinsicParameters; Matrix<double> fundamental; Matrix<double> essential; //If Emgu.CV.CvEnum.CALIB_TYPE == CV_CALIB_USE_INTRINSIC_GUESS and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be initialized before calling the function //if you use FIX_ASPECT_RATIO and FIX_FOCAL_LEGNTH options, these values needs to be set in the intrinsic parameters before the CalibrateCamera function is called. Otherwise 0 values are used as default. CameraCalibration.StereoCalibrate( points, corners.Select(_ => _.LeftCorners).ToArray(), corners.Select(_ => _.RightCorners).ToArray(), calibrationResult.Camera1Result.IntrinsicParameters, calibrationResult.Camera2Result.IntrinsicParameters, calibrationResult.Settings.ImageSize, CALIB_TYPE.DEFAULT, new MCvTermCriteria(0.1e5), out extrinsicParameters, out fundamental, out essential); var rec1 = new Rectangle(); var rec2 = new Rectangle(); CvInvoke.cvStereoRectify( calibrationResult.Camera1Result.IntrinsicParameters.IntrinsicMatrix, calibrationResult.Camera2Result.IntrinsicParameters.IntrinsicMatrix, calibrationResult.Camera1Result.IntrinsicParameters.DistortionCoeffs, calibrationResult.Camera2Result.IntrinsicParameters.DistortionCoeffs, calibrationResult.Settings.ImageSize, extrinsicParameters.RotationVector.RotationMatrix, extrinsicParameters.TranslationVector, calibrationResult.Camera1Result.R, calibrationResult.Camera2Result.R, calibrationResult.Camera1Result.P, calibrationResult.Camera2Result.P, calibrationResult.Q, STEREO_RECTIFY_TYPE.DEFAULT, 0, calibrationResult.Settings.ImageSize, ref rec1, ref rec2); calibrationResult.Camera1Result.Rectangle = rec1; calibrationResult.Camera2Result.Rectangle = rec2; return calibrationResult; }
public CalibrationSample(StereoImage<Bgr, byte> image, CalibrationCorners corners) { StereoImage = image; Corners = corners; IsCornersInitialized = true; }