Commit fc471beb authored by baisheng lai's avatar baisheng lai

bug fix

parent a5ce50b1
......@@ -140,7 +140,7 @@ namespace omnidir
@param R Rotation matrix between the input and output images. By default, it is identity matrix.
*/
CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray xi, int flags,
InputArray Knew = cv::noArray(), const Size& new_size = Size(), InputArray R = Matx33d::eye());
InputArray Knew = cv::noArray(), const Size& new_size = Size(), InputArray R = Mat::eye(3, 3, CV_64F));
/** @brief Perform omnidirectional camera calibration, the default depth of outputs is CV_64F.
......
......@@ -146,11 +146,11 @@ void multiCameraCalibration::loadImages()
std::string filename = file_list[i].substr(0, file_list[i].find('.'));
int spritPosition1 = filename.rfind('/');
int spritPosition2 = filename.rfind('\\');
if (spritPosition1!=std::string::npos)
if (spritPosition1!=(int)std::string::npos)
{
filename = filename.substr(spritPosition1+1, filename.size() - 1);
}
else if(spritPosition2!= std::string::npos)
else if(spritPosition2!= (int)std::string::npos)
{
filename = filename.substr(spritPosition2+1, filename.size() - 1);
}
......@@ -176,10 +176,10 @@ void multiCameraCalibration::loadImages()
// calibrate
Mat idx;
double rms;
//double rms;
if (_camType == PINHOLE)
{
rms = cv::calibrateCamera(_objectPointsForEachCamera[camera], _imagePointsForEachCamera[camera],
cv::calibrateCamera(_objectPointsForEachCamera[camera], _imagePointsForEachCamera[camera],
image.size(), _cameraMatrix[camera], _distortCoeffs[camera], _omEachCamera[camera],
_tEachCamera[camera],_flags);
idx = Mat(1, (int)_omEachCamera[camera].size(), CV_32S);
......@@ -201,7 +201,7 @@ void multiCameraCalibration::loadImages()
//}
else if (_camType == OMNIDIRECTIONAL)
{
rms = cv::omnidir::calibrate(_objectPointsForEachCamera[camera], _imagePointsForEachCamera[camera],
cv::omnidir::calibrate(_objectPointsForEachCamera[camera], _imagePointsForEachCamera[camera],
image.size(), _cameraMatrix[camera], _xi[camera], _distortCoeffs[camera], _omEachCamera[camera],
_tEachCamera[camera], _flags, TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 300, 1e-7),
idx);
......@@ -277,8 +277,8 @@ void multiCameraCalibration::initialize()
int nEdges = (int) _edgeList.size();
// build graph
Mat G = Mat::zeros((int)this->_vertexList.size(), (int)this->_vertexList.size(), CV_32S);
for (int edgeIdx = 0; edgeIdx < (int)this->_edgeList.size(); ++edgeIdx)
Mat G = Mat::zeros(nVertices, nVertices, CV_32S);
for (int edgeIdx = 0; edgeIdx < nEdges; ++edgeIdx)
{
G.at<int>(this->_edgeList[edgeIdx].cameraVertex, this->_edgeList[edgeIdx].photoVertex) = edgeIdx + 1;
}
......@@ -334,7 +334,7 @@ double multiCameraCalibration::optimizeExtrinsics()
tvec.reshape(1, 1).copyTo(extrinParam.colRange(offset+3, offset +6));
offset += 6;
}
double error_pre = computeProjectError(extrinParam);
//double error_pre = computeProjectError(extrinParam);
// optimization
const double alpha_smooth = 0.01;
//const double thresh_cond = 1e6;
......@@ -356,7 +356,7 @@ double multiCameraCalibration::optimizeExtrinsics()
extrinParam = extrinParam + G.reshape(1, 1);
change = norm(G) / norm(extrinParam);
double error = computeProjectError(extrinParam);
//double error = computeProjectError(extrinParam);
}
double error = computeProjectError(extrinParam);
......@@ -461,10 +461,10 @@ void multiCameraCalibration::computePhotoCameraJacobian(const Mat& rvecPhoto, co
{
tvecTran.convertTo(tvecTran, CV_32F);
}
float _xi;
float xif = 0.0f;
if (_camType == OMNIDIRECTIONAL)
{
_xi= xi.at<float>(0);
xif= xi.at<float>(0);
}
Mat imagePoints2, jacobian, dx_drvecCamera, dx_dtvecCamera, dx_drvecPhoto, dx_dtvecPhoto;
......@@ -478,7 +478,7 @@ void multiCameraCalibration::computePhotoCameraJacobian(const Mat& rvecPhoto, co
//}
else if (_camType == OMNIDIRECTIONAL)
{
cv::omnidir::projectPoints(objectPoints, imagePoints2, rvecTran, tvecTran, K, _xi, distort, jacobian);
cv::omnidir::projectPoints(objectPoints, imagePoints2, rvecTran, tvecTran, K, xif, distort, jacobian);
}
if (objectPoints.depth() == CV_32F)
{
......@@ -562,7 +562,7 @@ void multiCameraCalibration::findRowNonZero(const Mat& row, Mat& idx)
double multiCameraCalibration::computeProjectError(Mat& parameters)
{
int nVertex = (int)_vertexList.size();
CV_Assert(parameters.total() == (nVertex-1) * 6 && parameters.depth() == CV_32F);
CV_Assert((int)parameters.total() == (nVertex-1) * 6 && parameters.depth() == CV_32F);
int nEdge = (int)_edgeList.size();
// recompute the transform between photos and cameras
......@@ -756,7 +756,7 @@ void multiCameraCalibration::dAB(InputArray A, InputArray B, OutputArray dABdA,
void multiCameraCalibration::vector2parameters(const Mat& parameters, std::vector<Vec3f>& rvecVertex, std::vector<Vec3f>& tvecVertexs)
{
int nVertex = (int)_vertexList.size();
CV_Assert(parameters.channels() == 1 && parameters.total() == 6*(nVertex - 1));
CV_Assert((int)parameters.channels() == 1 && (int)parameters.total() == 6*(nVertex - 1));
CV_Assert(parameters.depth() == CV_32F);
parameters.reshape(1, 1);
......
......@@ -253,7 +253,7 @@ void cv::omnidir::undistortPoints( InputArray distorted, OutputArray undistorted
undistorted.create(distorted.size(), distorted.type());
cv::Vec2d f, c;
double s;
double s = 0.0;
if (K.depth() == CV_32F)
{
Matx33f camMat = K.getMat();
......@@ -463,7 +463,7 @@ void cv::omnidir::initUndistortRectifyMap(InputArray K, InputArray D, InputArray
for (int j = 0; j < size.width; ++j, theta+=iK(0,0), h+=iK(1,0))
{
double _xt, _yt, _wt;
double _xt = 0.0, _yt = 0.0, _wt = 0.0;
if (flags == omnidir::RECTIFY_CYLINDRICAL)
{
//_xt = std::sin(theta);
......@@ -483,9 +483,9 @@ void cv::omnidir::initUndistortRectifyMap(InputArray K, InputArray D, InputArray
{
double a = theta*theta + h*h + 4;
double b = -2*theta*theta - 2*h*h;
double c = theta*theta + h*h -4;
double c2 = theta*theta + h*h -4;
_yt = (-b-std::sqrt(b*b - 4*a*c))/(2*a);
_yt = (-b-std::sqrt(b*b - 4*a*c2))/(2*a);
_xt = theta*(1 - _yt) / 2;
_wt = h*(1 - _yt) / 2;
}
......@@ -742,8 +742,6 @@ void cv::omnidir::internal::initializeCalibration(InputOutputArrayOfArrays patte
cv::Mat(tFilter).convertTo(tAll, CV_64FC3);
}
int depth1 = patternPoints.depth(), depth2 = imagePoints.depth();
//patternPoints.create(Size(1, (int)patternPointsFilter.size()), CV_MAKETYPE(depth2,3), );
//imagePoints.create(Size(1, (int)patternPointsFilter.size()), CV_MAKETYPE(depth2,2));
//std::cout << patternPoints.total() << std::endl;
......@@ -811,14 +809,6 @@ void cv::omnidir::internal::initializeStereoCalibration(InputOutputArrayOfArrays
tAll1[i] = tAllTemp1[interIdx1.at<int>(i)];
omAll2[i] = omAllTemp2[interIdx2.at<int>(i)];
tAll2[i] = tAllTemp2[interIdx2.at<int>(i)];
/*objectPointsTemp1[interIdx1.at<int>(i)].copyTo(objectPoints.getMat(i));
imagePointsTemp1[interIdx1.at<int>(i)].copyTo(imagePoints1.getMat(i));
imagePointsTemp2[interIdx2.at<int>(i)].copyTo(imagePoints2.getMat(i));
omAll1[i] = omAllTemp1[interIdx1.at<int>(i)];
tAll1[i] = tAllTemp1[interIdx1.at<int>(i)];
omAll2[i] = omAllTemp2[interIdx2.at<int>(i)];
tAll2[i] = tAllTemp2[interIdx2.at<int>(i)];*/
}
// initialize R,T
......@@ -999,12 +989,12 @@ void cv::omnidir::internal::computeJacobianStereo(InputArrayOfArrays objectPoint
Matx14d D2(para[offset2+6], para[offset2+7], para[offset2+8], para[offset2+9]);
double xi2 = para[offset2+5];
Mat om = parameters.getMat().colRange(0, 3);
Mat T = parameters.getMat().colRange(3, 6);
Mat om = parameters.getMat().reshape(1, 1).colRange(0, 3);
Mat T = parameters.getMat().reshape(1, 1).colRange(3, 6);
for (int i = 0; i < n_img; i++)
{
Mat objPointsi, imgPoints1i, imgPoints2i, om1, T1, om, T;
Mat objPointsi, imgPoints1i, imgPoints2i, om1, T1;
//objPointsi = objectPoints.getMat(i);
//imgPoints1i = imagePoints1.getMat(i);
//imgPoints2i = imagePoints2.getMat(i);
......@@ -1017,8 +1007,7 @@ void cv::omnidir::internal::computeJacobianStereo(InputArrayOfArrays objectPoint
om1 = parameters.getMat().reshape(1, 1).colRange((1 + i) * 6, (1 + i) * 6 + 3);
T1 = parameters.getMat().reshape(1, 1).colRange((1 + i) * 6 + 3, (i + 1) * 6 + 6);
om = parameters.getMat().reshape(1, 1).colRange(0, 3);
T = parameters.getMat().reshape(1, 1).colRange(3, 6);
Mat imgProj1, imgProj2, jacobian1, jacobian2;
......@@ -1253,11 +1242,11 @@ double cv::omnidir::calibrate(InputArray patternPoints, InputArray imagePoints,
currentParam = finalParam.clone();
cv::omnidir::internal::decodeParameters(currentParam, _K, _omAll, _tAll, _D, _xi);
double repr = internal::computeMeanReproErr(_patternPoints, _imagePoints, _K, _D, _xi, _omAll, _tAll);
//double repr = internal::computeMeanReproErr(_patternPoints, _imagePoints, _K, _D, _xi, _omAll, _tAll);
}
cv::omnidir::internal::decodeParameters(currentParam, _K, _omAll, _tAll, _D, _xi);
double repr = internal::computeMeanReproErr(_patternPoints, _imagePoints, _K, _D, _xi, _omAll, _tAll);
//double repr = internal::computeMeanReproErr(_patternPoints, _imagePoints, _K, _D, _xi, _omAll, _tAll);
if (omAll.needed())
{
......@@ -1353,17 +1342,8 @@ double cv::omnidir::stereoCalibrate(InputOutputArrayOfArrays objectPoints, Input
Matx33d _K1, _K2;
Matx14d _D1, _D2;
int n = objectPoints.total();
int nPoints = objectPoints.getMat(0).total();
//if (!K1.empty()) K1.getMat().convertTo(_K1, CV_64FC1);
//if (!D1.empty()) D1.getMat().convertTo(_D1, CV_64FC1);
//if (!K2.empty()) K2.getMat().convertTo(_K2, CV_64FC1);
//if (!D2.empty()) D2.getMat().convertTo(_D2, CV_64FC1);
double _xi1, _xi2;
//if(!xi1.empty()) _xi1 = xi1.getMat().at<double>(0);
//if(!xi2.empty()) _xi2 = xi1.getMat().at<double>(0);
std::vector<Vec3d> _omL, _TL;
Vec3d _om, _T;
......@@ -1377,12 +1357,12 @@ double cv::omnidir::stereoCalibrate(InputOutputArrayOfArrays objectPoints, Input
_idx.copyTo(idx.getMat());
}
n = (int)_objectPoints.size();
int n = (int)_objectPoints.size();
Mat finalParam(1, 10 + 6*n, CV_64F);
Mat currentParam(1, 10 + 6*n, CV_64F);
double repr1 = internal::computeMeanReproErrStereo(_objectPoints, _imagePoints1, _imagePoints2, _K1, _K2, _D1, _D2, _xi1, _xi2, _om,
_T, _omL, _TL);
//double repr1 = internal::computeMeanReproErrStereo(_objectPoints, _imagePoints1, _imagePoints2, _K1, _K2, _D1, _D2, _xi1, _xi2, _om,
// _T, _omL, _TL);
cv::omnidir::internal::encodeParametersStereo(_K1, _K2, _om, _T, _omL, _TL, _D1, _D2, _xi1, _xi2, currentParam);
// optimization
......@@ -1410,13 +1390,13 @@ double cv::omnidir::stereoCalibrate(InputOutputArrayOfArrays objectPoints, Input
currentParam = finalParam.clone();
cv::omnidir::internal::decodeParametersStereo(currentParam, _K1, _K2, _om, _T, _omL, _TL, _D1, _D2, _xi1, _xi2);
double repr = internal::computeMeanReproErrStereo(_objectPoints, _imagePoints1, _imagePoints2, _K1, _K2, _D1, _D2, _xi1, _xi2, _om,
_T, _omL, _TL);
//double repr = internal::computeMeanReproErrStereo(_objectPoints, _imagePoints1, _imagePoints2, _K1, _K2, _D1, _D2, _xi1, _xi2, _om,
// _T, _omL, _TL);
}
cv::omnidir::internal::decodeParametersStereo(finalParam, _K1, _K2, _om, _T, _omL, _TL, _D1, _D2, _xi1, _xi2);
double repr = internal::computeMeanReproErrStereo(_objectPoints, _imagePoints1, _imagePoints2, _K1, _K2, _D1, _D2, _xi1, _xi2, _om,
_T, _omL, _TL);
//double repr = internal::computeMeanReproErrStereo(_objectPoints, _imagePoints1, _imagePoints2, _K1, _K2, _D1, _D2, _xi1, _xi2, _om,
// _T, _omL, _TL);
if (K1.empty())
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment