linux下使用opencv测量相机内参

环境要求:

ubuntu下已经源码编译了opencv。

首先截取20到30张相机的原图片。

 

创建imglist_create.cpp

#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <string>
#include <iostream>

using std::string;
using std::cout;
using std::endl;

using namespace cv;

static void help(char** av)
{
    cout << "\nThis creates a yaml or xml list of files from the command line args\n"
        "usage:\n./" << av[0] << " imagelist.yaml *.png\n"
        << "Try using different extensions.(e.g. yaml yml xml xml.gz etc...)\n"
        << "This will serialize this list of images or whatever with opencv's FileStorage framework" << endl;
}

int main(int ac, char** av)
{
    cv::CommandLineParser parser(ac, av, "{help h||}{@output||}");
    if (parser.has("help"))
    {
        help(av);
        return 0;
    }
    string outputname = parser.get<string>("@output");

    if (outputname.empty())
    {
        help(av);
        return 1;
    }

    Mat m = imread(outputname); //check if the output is an image - prevent overwrites!
    if (!m.empty()) {
        std::cerr << "fail! Please specify an output file, don't want to overwrite you images!" << endl;
        help(av);
        return 1;
    }

    FileStorage fs(outputname, FileStorage::WRITE);
    fs << "images" << "[";
    for (int i = 2; i < ac; i++) {
        fs << string(av[i]);
    }
    fs << "]";
    return 0;
}

使用命令  g++ imglist_create.cpp `pkg-config --cflags --libs opencv`

将a.out与图片放在一起。

运行   ./a.out  imagelist.yaml  1.jpg 2.jpg 3.jpg .......18.jpg 19.jpg 20.jpg

此时会生成一个imagelist.yaml 的文件

使用calibration.cpp 进行编译

g++ calibration.cpp -o calibration -std=c++11 `pkg-config --cflags --libs opencv`

然后将calibrtion与图片放在一起

运行./calibration imagelist.yaml 1.jpg 2.jpg ..........19.jpg 20.jpg -w=8 -h=6

此时会生成一个out_camera_data.yaml的文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值