纯旋转情况下相机标定,f焦距确定

在这里插入图片描述

#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;
}

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值