我必须使用已知标记估计相机的姿势。相机已校准,我拥有所有校准系数。
当前版本的算法从帧中提取 4 个共面点,并使用它们使用 solvePnP 函数来估计位姿。
算法似乎工作正常,但我有疑问。由于solvePnP也将校准系数作为输入,我是否需要在查看4个点之前不扭曲图像?
在下面的代码中,是否需要 initUndistortRectifyMap/remap 函数?
while(1) {
frame = camera->getFrame();
imshow("frame", frame);
// Estimation of Map1 and Map2 for image rectification (to be done only on the first iteration)
if (initRectifyMap_flag)
{
// Rectify the image
// The initialization of the Rectification Parameters will be carried out only at the first frame.
initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(), getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, frame.size(), 1, frame.size(), 0), frame.size(), CV_16SC2, map1, map2);
initRectifyMap_flag = false;
}
// Remapping of the current frame
remap(frame, src, map1, map2, INTER_LINEAR, BORDER_TRANSPARENT, Scalar::all(255));
// Here is the code for the extraction of the 4 points based on the content of the variable src
...
...
// Pose estimation
solvePnP(Mat(refMarkerPoint), Mat(markerPoints), cameraMatrix, distCoeffs, rvec, tvec,false);