OpenCvSharp.OpenCVException: 'fabs(sc) > DBL_EPSILON'
wanless79 opened this issue · comments
wanless79 commented
Summary of your issue
When running the Cv2.CalibrateCamera function I get this errror OpenCvSharp.OpenCVException: 'fabs(sc) > DBL_EPSILON'
What did you do when you faced the problem?
I checked the obj_points, img_points arrays and both contain the same number of items obj_points has x,y,z values all 0 and img_points has x,y values all with numeric values
I removed all my calib images and replaced them with a single flat checkerboard image, I also attempted to pass in an all 0 obj_points and img_points and still got the same error.
Example code:
DirectoryInfo dir = new DirectoryInfo("CalibImages");
var calibFiles = dir.GetFiles().Where(m => m.Extension == ".jpg");
TermCriteria criteria = new TermCriteria(CriteriaTypes.MaxIter | CriteriaTypes.Eps, 30, 0.001);
var size = new OpenCvSharp.Size(0, 0);
int PAT_COL = 10;
int PAT_ROW = 7;
int PAT_SIZE = PAT_ROW * PAT_COL;
OpenCvSharp.Size PatternSize = new OpenCvSharp.Size(PAT_COL, PAT_ROW);
List<List<Point3f>> obj_points = new List<List<Point3f>>();
List<List<Point2f>> img_points = new List<List<Point2f>>();
var objp = np.zeros((PAT_SIZE, 3), np.float32);
var objpl = NDArrayToList(objp);
foreach (FileInfo file in calibFiles)
{
Mat img = Cv2.ImRead(file.FullName);
var gray = img.CvtColor(ColorConversionCodes.BGR2GRAY);
size = img.Size();
Point2f[] corners;
var found = Cv2.FindChessboardCorners(gray, PatternSize, out corners);
if (found)
{
obj_points.Add(objpl);
var corners2 = Cv2.CornerSubPix(gray, corners, new OpenCvSharp.Size(6, 6),
new OpenCvSharp.Size(-1, -1), criteria);
if (corners2?.Length > 0)
{
img_points.Add(corners2.ToList());
}
else
{
img_points.Add(corners.ToList());
}
}
gray.Dispose();
img.Dispose();
}
double[,] cameraMatrix = new double[3, 3];
double[] distCoeffs = new double[5];
Vec3d[] rvecs = new Vec3d[] { };
Vec3d[] tvecs = new Vec3d[] { };
var ret = Cv2.CalibrateCamera(obj_points, img_points, size,
cameraMatrix, distCoeffs, out rvecs, out tvecs);
Output:
OpenCvSharp.OpenCVException: 'fabs(sc) > DBL_EPSILON'
stale commented
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.