如何在opencv中使用UndistortPoints函数

How to use the UndistortPoints function in opencv

本文关键字:UndistortPoints 函数 opencv      更新时间:2023-10-16
#define fx 1532.49;
#define fy 1521.439;
#define cx 1267.78;
#define cy 952.078;
Mat_<float> cam(3,3); cam << 1531.49,0,1267.78,0,1521.439,952.078,0,0,1;
Mat_<float> dist(1,5); dist <<-0.27149,0.15384,0.0046,-0.0026;
const int npoints = 2; // number of point specified 
// Points initialization. 
// Only 2 ponts in this example, in real code they are read from file.
Mat_<Point2f> points(1,npoints);
points(0) = Point2f(0,0);
points(1) = Point2f(2560, 1920);
Mat dst;// leave empty, opencv will fill it.
undistortPoints(points, dst, cam, dist);
MatIterator_<double> i;
 for(i=dst.begin<double>();i!=dst.end <double>();++i)
  {
      cout<<(*i)<<endl;
  }

我想使用不扭曲点功能来消除失真。这是 vs2012 的 OpenCV2.4.9 中的 UndistortPoints 函数,但是当它运行时,它只输出 2 个参数。谁能帮我?谢谢。

这是结果!这是结果!运行代码1。

实际上,Mat dst中有4个四个值,其值类型是floatFLOAT32)而不是double

您可以简单地cout整个矩阵即可清楚地看到它:

cout << dst;