float k[]={1531.49,0,1267.78,0,1521.439,952.078,0,0,1};
float d[]={-0.27149,0.15384,0.0046,-0.0026};
CvMat camera1=cvMat( 3, 3, CV_32FC2, k );
CvMat distCoeffs1=cvMat(1,4,CV_32FC2,d);
const int npoints = 4; // number of point specified
// Points initialization.
// Only 2 ponts in this example, in real code they are read from file.
float input_points[npoints][4] = {{0,0}, {2560, 1920}}; // the rest will be set to 0
CvMat * src = cvCreateMat(1, npoints, CV_32FC2);
CvMat * dst = cvCreateMat(1, npoints, CV_32FC2);
// fill src matrix
float * src_ptr = (float*)src->data.ptr;
for (int pi = 0; pi < npoints; ++pi) {
for (int ci = 0; ci < 2; ++ci) {
*(src_ptr + pi * 2 + ci) = input_points[pi][ci];
}
}
cvUndistortPoints(src, dst, &camera1, &distCoeffs1);
我希望使用cvUndistortPoints函数。并使用示例代码进行测试。当我使用VS2012运行时,它已经工作了。它说“src.size与dst匹配。尺寸&#34;。我是OpenCV的新手。有人能帮助我吗? 谢谢。 由vs2012 1
运行的结果答案 0 :(得分:1)
再次请使用opencv的c ++ api,而不是弃用的c:
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 = 4; // 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);
cerr << dst;
[-0.90952414, -0.69702172, 0.92829341, 0.69035494, -0.90952414, -0.69702172, -0.90952414, -0.69702172]