#include "opencv2/core/core.hpp"
#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/stitching/detail/autocalib.hpp"
#include "opencv2/stitching/detail/blenders.hpp"
#include "opencv2/stitching/detail/camera.hpp"
#include "opencv2/stitching/detail/exposure_compensate.hpp"
#include "opencv2/stitching/detail/matchers.hpp"
#include "opencv2/stitching/detail/motion_estimators.hpp"
#include "opencv2/stitching/detail/seam_finders.hpp"
#include "opencv2/stitching/detail/util.hpp"
#include <opencv2/stitching/detail/warpers.hpp>
#include <opencv2/stitching/warpers.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <string>
using namespace cv;
using namespace std;
using namespace detail;
void motion_estimator(vector<cv::String> filename)
{
vector<ImageFeatures> features(filename.size());
for(int i=0;i<filename.size();++i)
{
Mat img = imread(filename[i]);
Ptr<FeaturesFinder> finder; //特征检测
finder = new SurfFeaturesFinder();
(*finder)(img, features[i]);
}
vector<MatchesInfo> pairwise_matches; //特征匹配
BestOf2NearestMatcher matcher(false, 0.3f, 6, 6);
matcher(features, pairwise_matches);
HomographyBasedEstimator estimator; //定义参数评估器
vector<CameraParams> cameras; //表示相机参数
estimator(features, pairwise_matches, cameras); //相机参数评估
for (size_t i = 0; i < cameras.size(); ++i)
{
Mat R;
cameras[i].R.convertTo(R, CV_32F); //数据类型转换 ***必须进行
cameras[i].R = R;
}
Ptr<detail::BundleAdjusterBase> adjuster; //光束平差法,优化相机参数
adjuster = new detail::BundleAdjusterReproj(); //重映射误差方法
adjuster->setConfThresh(1); //设置匹配置信度
(*adjuster)(features, pairwise_matches, cameras); //相机参数的精确评估
cout<<"姿态个数"<<cameras.size()<<endl;
for (int i=0;i<cameras.size();++i)
{
cout<<"第"<<i+1<<"个相机的内参数"<< ":\n" << cameras[i].K()<<endl;
cout<<"第"<<i+1<<"个相机的旋转参数"<< ":\n" << cameras[i].R<<endl;
}
cout<<"相机焦距:" << cameras[0].focal<<endl;
}
int main(int argc, char** argv)
{
vector<cv::String> filename;
glob("1/*.jpg",filename);
motion_estimator(filename);
return 0;
}
纯旋转情况下相机标定,f焦距确定
最新推荐文章于 2024-07-31 15:46:21 发布