我试图通过使用OpenCV 2.3.1和两个摄像头来确定两个对象之间的距离,但无法计算对象的objectPoints(OCV 2.3.1,MSVC ++,Windows 7)。我认为这是因为在计算差异之前,图像点没有得到纠正。
予。我先做什么
步骤1.自行校准每个相机
int numSquares = numCornersHor * numCornersVer;
Size board_sz = Size(numCornersHor, numCornersVer);
Mat cameraMatrix = Mat(3, 3, CV_32FC1);
Mat distCoeffs;
vector<Mat> rvecs, tvecs;
cameraMatrix.ptr<float>(0)[0] = 1;
cameraMatrix.ptr<float>(1)[1] = 1;
calibrateCamera(object_points,
image_points,
image.size(),
cameraMatrix, distCoeffs,
rvecs, tvecs);
步骤2.一起校准相机
int numCornersHor = 4;
int numCornersVer = 3;
const float squareSize = 1.75;
Size imageSize = Size(numCornersHor, numCornersVer);
int numSquares = numCornersHor * numCornersVer;
for(int i = 0; i < pairs; i++ )
{
for( int j = 0; j < imageSize.height; j++ )
{
for( int k = 0; k < imageSize.width; k++ )
{
objectPoints[i].push_back(Point3f(j*squareSize, k*squareSize, 0));
}
}
}
Mat R, T, E, F;
rms = stereoCalibrate( objectPoints,
imagePoints[0], imagePoints[1],
cameraMatrix[0], distCoeffs[0],
cameraMatrix[1], distCoeffs[1],
imageSize,
R, T, E, F,
TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5),
CV_CALIB_FIX_ASPECT_RATIO +
CV_CALIB_ZERO_TANGENT_DIST +
CV_CALIB_SAME_FOCAL_LENGTH +
CV_CALIB_RATIONAL_MODEL +
CV_CALIB_FIX_K3 + CV_CALIB_FIX_K4 + CV_CALIB_FIX_K5
);
步骤3.创建整改数据
stereoRectify(
cameraMatrix[0], cameraMatrix[1],
distCoeffs[0], distCoeffs[1],
imageSize,
R, T,
RC1, RC2, //RC1: Rotation matrix Camera 1
PC1, PC2,
Q,
CALIB_ZERO_DISPARITY,
1,
imageSize);
II。我相信的是什么
目标: 我正在尝试不扭曲并纠正来自摄像机1的图像中的一个物体的图像点和来自摄像机2的图像(我执行此过程两次:一次粘土鸽子在发射器上,一次在粘土鸽子解体前一帧)
方法: 我相信我不需要使用initUndistortRectifyMap然后重新映射,而只需使用undistortPoints。我认为undistortPoints不会破坏兴趣点并对其进行纠正。
III。我做什么第二次
如果我的信念不正确,你可以忽略这一点。
undistortPoints(launcherC1, launcherC1Undistorted, cameraMatrixC1, distCoeffsC1, R1, P1);
undistortPoints(launcherC2, launcherC2Undistorted, cameraMatrixC2, distCoeffsC2, R2, P2);
undistortPoints(clayPigeonC1, clayPigeonC1Undistorted, cameraMatrix1, distCoeffs1, R1, P1);
undistortPoints(clayPigeonC2, clayPigeonC2Undistorted, cameraMatrix2, distCoeffs2, R2, P2);
undistortPoints(launcherC1,launcherC1Undistorted,... clayPigeonC2,clayPigeonC2Undistorted)的输入和输出数组是Point2f对象的向量。
IV。信仰与现实之间的差异
运行所有undistortPoints函数后,
他们的差异高达30%。
诉问题
答案 0 :(得分:0)
undistortPoints
无法纠正分数,因为你从未给它提供所需的整改参数 - 这就是相机与另一个相机的姿势关系。stereoCalibrate
+ initUndistortRectifyMap
+ remap
,然后是 - 相应点的y值将相同。