【发布时间】:2017-10-12 02:15:14
【问题描述】:
所以OpenCV undistort 将两个数组double k[6], p[2]; 作为参数,但是当您无法访问相机(仅访问其帧)时,设置它们很复杂。有一个algorithm called Algebraic Lens Distortion Model Estimation,它在一个框架上接收一张图片和手绘线,并产生一个undistorted image。
它的输出可能如下所示:
(Emin, Vmin, D) = (9.7709e+05, 8.3106e+00, 8.2942e+00)
失真参数:k[0] = 8.549082532748524e-01 k1 = 0.000000000000000e+00 k2 = 3.217447043912507e-08 k3 = 0.000000000000000e+00 k4 = 1.407606498960670e-12
畸变中心 (x0,y0) = (655.091196, 385.002911)
所以我们从 k 数组中获得了 5 项,而从 p 中没有。而且我在他们的文章中没有提到p。所以我想知道如何将他们的输出映射到opencv?
不适用于this images的代码示例:
#include <iostream>
#include <opencv2/world.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
int main() {
Mat result;
auto in = imread("test.png"); // http://demo.ipol.im/demo/ags_algebraic_lens_distortion_estimation/archive/?key=1C3EFA932C69EE5A1254458F6F9F2B87
int fov = 60;
//Center of distortion (x0,y0)
auto x = 640.000000;
auto y = 360.000000;
// http://answers.opencv.org/question/17076/conversion-focal-distance-from-mm-to-pixels/?answer=17180#post-id-17180
auto focalLengthX = x / tan(fov * 0.5 * acos(-1) / 180.0);
auto focalLengthY = y / tan(fov* 0.5 * acos(-1) / 180.0);
cv::Mat camera_matrix = (cv::Mat_<double>(3, 3) << focalLengthX, 0, x, 0, focalLengthX, y, 0, 0, 1);
// https://stackoverflow.com/a/34024057/1973207
double k[5];
k[0] = 8.648648537891959e-01;
k[1] = 0.000000000000000e+00;
k[2] = 8.319218976751903e-08;
k[3] = 0.000000000000000e+00;
k[4] = 9.568850206942498e-13;
Mat distortionCoefficients = (Mat1d(1, 8) << k[0], k[1], 0, 0, k[2], k[3], k[4], 0);
undistort(in, result, camera_matrix, distortionCoefficients);
imshow("test", result);
waitKey();
cin.get();
return 0;
}
结果:
【问题讨论】:
-
他们为相机镜头使用了另一种失真模型,是吗?
标签: c++ algorithm opencv opencv3.0 distortion