加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
undistort_rectify.cpp 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
sourishg 提交于 2016-07-02 19:16 . Add popt to undistort_rectify
#include <opencv2/core/core.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <iostream>
#include "popt_pp.h"
using namespace std;
using namespace cv;
int main(int argc, char const *argv[])
{
char* leftimg_filename;
char* rightimg_filename;
char* calib_file;
char* leftout_filename;
char* rightout_filename;
static struct poptOption options[] = {
{ "leftimg_filename",'l',POPT_ARG_STRING,&leftimg_filename,0,"Left imgage path","STR" },
{ "rightimg_filename",'r',POPT_ARG_STRING,&rightimg_filename,0,"Right image path","STR" },
{ "calib_file",'c',POPT_ARG_STRING,&calib_file,0,"Stereo calibration file","STR" },
{ "leftout_filename",'L',POPT_ARG_STRING,&leftout_filename,0,"Left undistorted imgage path","STR" },
{ "rightout_filename",'R',POPT_ARG_STRING,&rightout_filename,0,"Right undistorted image path","STR" },
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0, NULL, NULL }
};
POpt popt(NULL, argc, argv, options, 0);
int c;
while((c = popt.getNextOpt()) >= 0) {}
Mat R1, R2, P1, P2, Q;
Mat K1, K2, R;
Vec3d T;
Mat D1, D2;
Mat img1 = imread(leftimg_filename, CV_LOAD_IMAGE_COLOR);
Mat img2 = imread(rightimg_filename, CV_LOAD_IMAGE_COLOR);
cv::FileStorage fs1(calib_file, cv::FileStorage::READ);
fs1["K1"] >> K1;
fs1["K2"] >> K2;
fs1["D1"] >> D1;
fs1["D2"] >> D2;
fs1["R"] >> R;
fs1["T"] >> T;
fs1["R1"] >> R1;
fs1["R2"] >> R2;
fs1["P1"] >> P1;
fs1["P2"] >> P2;
fs1["Q"] >> Q;
cv::Mat lmapx, lmapy, rmapx, rmapy;
cv::Mat imgU1, imgU2;
cv::initUndistortRectifyMap(K1, D1, R1, P1, img1.size(), CV_32F, lmapx, lmapy);
cv::initUndistortRectifyMap(K2, D2, R2, P2, img2.size(), CV_32F, rmapx, rmapy);
cv::remap(img1, imgU1, lmapx, lmapy, cv::INTER_LINEAR);
cv::remap(img2, imgU2, rmapx, rmapy, cv::INTER_LINEAR);
imwrite(leftout_filename, imgU1);
imwrite(rightout_filename, imgU2);
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化