public void FishEyeCalibrate() { var patternSize = new Size(10, 7); using (var image = Image("calibration/00.jpg")) using (var corners = new MatOfPoint2f()) { Cv2.FindChessboardCorners(image, patternSize, corners); var objectPointsArray = Create3DChessboardCorners(patternSize, 1.0f).ToArray(); var imagePointsArray = corners.ToArray(); using (var objectPoints = MatOfPoint3f.FromArray(objectPointsArray)) using (var imagePoints = MatOfPoint2f.FromArray(imagePointsArray)) using (var cameraMatrix = new MatOfDouble(Mat.Eye(3, 3, MatType.CV_64FC1))) using (var distCoeffs = new MatOfDouble()) { var rms = Cv2.FishEye.Calibrate(new[] { objectPoints }, new[] { imagePoints }, image.Size(), cameraMatrix, distCoeffs, out var rotationVectors, out var translationVectors, FishEyeCalibrationFlags.None); var distCoeffValues = distCoeffs.ToArray(); Assert.Equal(55.15, rms, 2); Assert.Contains(distCoeffValues, d => Math.Abs(d) > 1e-20); Assert.NotEmpty(rotationVectors); Assert.NotEmpty(translationVectors); } } }
public void BuildPatternFromImage(Mat image, Pattern pattern) { // Store original image in pattern structure pattern.size = new Size(image.Cols, image.Rows); pattern.frame = image.Clone(); GetGray(image, pattern.grayImg); // Build 2d and 3d contours (3d contour lie in XY plane since it's planar) List <Point2f> points2dList = new List <Point2f>(4); List <Point3f> points3dList = new List <Point3f>(4); // Image dimensions float w = image.Cols; float h = image.Rows; // Normalized dimensions: points2dList.Add(new Point2f(0, 0)); points2dList.Add(new Point2f(w, 0)); points2dList.Add(new Point2f(w, h)); points2dList.Add(new Point2f(0, h)); pattern.points2d = MatOfPoint2f.FromArray(points2dList); points3dList.Add(new Point3f(-0.5f, -0.5f, 0)); points3dList.Add(new Point3f(+0.5f, -0.5f, 0)); points3dList.Add(new Point3f(+0.5f, +0.5f, 0)); points3dList.Add(new Point3f(-0.5f, +0.5f, 0)); pattern.points3d = MatOfPoint3f.FromArray(points3dList); ExtractFeatures(pattern.grayImg, ref pattern.keypoints, pattern.descriptors); Train(pattern); }