omnidirectional_calibration
omnidirectional_calibration copied to clipboard
Unable to use it with OpenCV 4.5.0
I am using custom pattern image to get calibration result using this library along with OpenCV 4.5.0 and I am getting following error.
number of matched points 201 number of filtered points 82 OpenCV: terminate handler is called! The last OpenCV error is: OpenCV(4.5.0) Error: Assertion failed (nimages > 0) in calibrateCameraRO, file C:\OpenCV\opencv\sources\modules\calib3d\src\calibration.cpp, line 3694
#include "opencv2/ccalib/randpattern.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/calib3d.hpp"
#include <vector>
#include <iostream>
#include <time.h>
using namespace std;
using namespace cv;
static void saveCameraParams(const string &filename, Size imageSize, float patternWidth,
float patternHeight, int flags, const Mat &cameraMatrix, const Mat &distCoeffs,
const vector<Mat> &rvecs, const vector<Mat> &tvecs, double rms)
{
FileStorage fs(filename, FileStorage::WRITE);
time_t tt;
time(&tt);
struct tm *t2 = localtime(&tt);
char buf[1024];
strftime(buf, sizeof(buf) - 1, "%c", t2);
fs << "calibration_time" << buf;
if (!rvecs.empty())
fs << "nframes" << (int)rvecs.size();
fs << "image_width" << imageSize.width;
fs << "image_height" << imageSize.height;
fs << "pattern_width" << patternWidth;
fs << "pattern_height" << patternHeight;
fs << "flags" << flags;
fs << "camera_matrix" << cameraMatrix;
fs << "distortion_coefficients" << distCoeffs;
fs << "rms" << rms;
if (!rvecs.empty() && !tvecs.empty())
{
CV_Assert(rvecs[0].type() == tvecs[0].type());
Mat bigmat((int)rvecs.size(), 6, rvecs[0].type());
for (int i = 0; i < (int)rvecs.size(); i++)
{
Mat r = bigmat(Range(i, i + 1), Range(0, 3));
Mat t = bigmat(Range(i, i + 1), Range(3, 6));
CV_Assert(rvecs[i].rows == 3 && rvecs[i].cols == 1);
CV_Assert(tvecs[i].rows == 3 && tvecs[i].cols == 1);
//*.t() is MatExpr (not Mat) so we can use assignment operator
r = rvecs[i].t();
t = tvecs[i].t();
}
//cvWriteComment( *fs, "a set of 6-tuples (rotation vector + translation vector) for each view", 0 );
fs << "extrinsic_parameters" << bigmat;
}
}
int main(int argc, char const *argv[])
{
randpattern::RandomPatternCornerFinder finder(6, 5.7, 20,0,1,1);
Mat pattern = imread("PyramidPattern.jpg", IMREAD_GRAYSCALE);
finder.loadPattern(pattern);
Mat image = imread("PyramidPatternTest.jpg", IMREAD_GRAYSCALE);
finder.computeObjectImagePointsForSingle(image);
vector<Mat> objectPoints = finder.getObjectPoints();
vector<Mat> imagePoints = finder.getImagePoints();
Mat K;
Mat D;
vector<Mat> rvec, tvec;
double rms = calibrateCamera(objectPoints, imagePoints, image.size(), K, D, rvec, tvec);
saveCameraParams("out_camera_params.xml", image.size(), 6, 5.7, CALIB_FIX_PRINCIPAL_POINT, K, D, rvec, tvec, rms);
return 0;
}
Marker Pattern
Test Image to
And whenever I trying to see value of objectPoints, imagePoints variable in debugger I am getting {...} instead collection of Mat inside vector.
Please help me to get rid of this issue.