TEST_F(fisheyeTest, Homography) { const int n_images = 1; std::vector<std::vector<cv::Point2d> > imagePoints(n_images); std::vector<std::vector<cv::Point3d> > objectPoints(n_images); const std::string folder =combine(datasets_repository_path, "calib-3_stereo_from_JY"); cv::FileStorage fs_left(combine(folder, "left.xml"), cv::FileStorage::READ); CV_Assert(fs_left.isOpened()); for(int i = 0; i < n_images; ++i) fs_left[cv::format("image_%d", i )] >> imagePoints[i]; fs_left.release(); cv::FileStorage fs_object(combine(folder, "object.xml"), cv::FileStorage::READ); CV_Assert(fs_object.isOpened()); for(int i = 0; i < n_images; ++i) fs_object[cv::format("image_%d", i )] >> objectPoints[i]; fs_object.release(); cv::internal::IntrinsicParams param; param.Init(cv::Vec2d(cv::max(imageSize.width, imageSize.height) / CV_PI, cv::max(imageSize.width, imageSize.height) / CV_PI), cv::Vec2d(imageSize.width / 2.0 - 0.5, imageSize.height / 2.0 - 0.5)); cv::Mat _imagePoints (imagePoints[0]); cv::Mat _objectPoints(objectPoints[0]); cv::Mat imagePointsNormalized = NormalizePixels(_imagePoints, param).reshape(1).t(); _objectPoints = _objectPoints.reshape(1).t(); cv::Mat objectPointsMean, covObjectPoints; int Np = imagePointsNormalized.cols; cv::calcCovarMatrix(_objectPoints, covObjectPoints, objectPointsMean, cv::COVAR_NORMAL | cv::COVAR_COLS); cv::SVD svd(covObjectPoints); cv::Mat theR(svd.vt); if (cv::norm(theR(cv::Rect(2, 0, 1, 2))) < 1e-6) theR = cv::Mat::eye(3,3, CV_64FC1); if (cv::determinant(theR) < 0) theR = -theR; cv::Mat theT = -theR * objectPointsMean; cv::Mat X_new = theR * _objectPoints + theT * cv::Mat::ones(1, Np, CV_64FC1); cv::Mat H = cv::internal::ComputeHomography(imagePointsNormalized, X_new.rowRange(0, 2)); cv::Mat M = cv::Mat::ones(3, X_new.cols, CV_64FC1); X_new.rowRange(0, 2).copyTo(M.rowRange(0, 2)); cv::Mat mrep = H * M; cv::divide(mrep, cv::Mat::ones(3,1, CV_64FC1) * mrep.row(2).clone(), mrep); cv::Mat merr = (mrep.rowRange(0, 2) - imagePointsNormalized).t(); cv::Vec2d std_err; cv::meanStdDev(merr.reshape(2), cv::noArray(), std_err); std_err *= sqrt((double)merr.reshape(2).total() / (merr.reshape(2).total() - 1)); cv::Vec2d correct_std_err(0.00516740156010384, 0.00644205331553901); EXPECT_MAT_NEAR(std_err, correct_std_err, 1e-12); }
// On copy apply for type image! bool histogramRGBL::apply(const image& src,dvector& dest) const { if (src.empty()) { dest.clear(); setStatusString("input channel empty"); return false; } const parameters& param = getParameters(); int theMin(0),theMax(255); const int lastIdx = param.cells-1; const float m = float(lastIdx)/(theMax-theMin); int y,r,g,b,l; int idx; int entries; vector<rgbPixel>::const_iterator it,eit; dest.resize(4*param.cells,0.0,false,true); // initialize with 0 dvector theR(param.cells,0.0); dvector theG(param.cells,0.0); dvector theB(param.cells,0.0); dvector theL(param.cells,0.0); entries = 0; // if b too small, it's possible to calculate everything faster... // check if the ignore value if (param.considerAllData) { for (y=0;y<src.rows();++y) { const vector<rgbPixel>& vct = src.getRow(y); for (it=vct.begin(),eit=vct.end();it!=eit;++it) { r = (*it).getRed(); g = (*it).getGreen(); b = (*it).getBlue(); l = (min(r,g,b)+max(r,g,b))/2; idx = static_cast<int>(r*m); theR.at(idx)++; idx = static_cast<int>(g*m); theG.at(idx)++; idx = static_cast<int>(b*m); theB.at(idx)++; idx = static_cast<int>(l*m); theL.at(idx)++; entries++; } } } else { for (y=0;y<src.rows();++y) { const vector<rgbPixel>& vct = src.getRow(y); for (it=vct.begin(),eit=vct.end();it!=eit;++it) { if ((*it) != param.ignoreValue) { r = (*it).getRed(); g = (*it).getGreen(); b = (*it).getBlue(); l = (min(r,g,b)+max(r,g,b))/2; idx = static_cast<int>(r*m); theR.at(idx)++; idx = static_cast<int>(g*m); theG.at(idx)++; idx = static_cast<int>(b*m); theB.at(idx)++; idx = static_cast<int>(l*m); theL.at(idx)++; entries++; } } } } if (param.smooth) { convolution convolver; convolution::parameters cpar; cpar.boundaryType = lti::Mirror; cpar.setKernel(param.kernel); convolver.setParameters(cpar); matrix<double> tmp; tmp.useExternData(4,param.cells,&dest.at(0)); convolver.apply(theR,tmp.getRow(0)); convolver.apply(theG,tmp.getRow(1)); convolver.apply(theB,tmp.getRow(2)); convolver.apply(theL,tmp.getRow(3)); } else { dest.fill(theR,0); dest.fill(theG,param.cells); dest.fill(theB,2*param.cells); dest.fill(theL,3*param.cells); } if (param.normalize) { if (entries > 0) { dest.divide(entries); } } return true; };