OpenCV:使用 cv::triangulatepoints() 进行立体摄像机跟踪的问题
Posted
技术标签:
【中文标题】OpenCV:使用 cv::triangulatepoints() 进行立体摄像机跟踪的问题【英文标题】:OpenCV: Issue with Stereocamera Tracking using cv::triangulatepoints() 【发布时间】:2018-05-18 16:55:30 【问题描述】:我正在尝试使用 cv::triangulatePoints() 函数来跟踪棋盘图案,使用两个现成的网络摄像头。我使用 MATLAB 的 Stereocamera Calibration Toolbox 校准了我的设置,然后在我的 OpenCV 代码中使用了它。
我的问题是,当我从 cv::triangulatePoints() 获取坐标时(在将其转换为欧几里得空间之后),当将它们 3D 绘制到 MATLAB 中时,它们不会形成点平面。 我想知道我的代码中是否有我忽略的错误?
下面列出了我正在使用的代码。任何见解都会有很大帮助!
Mat cameraMat1 = (Mat_<double>(3,3) << 1411.3, 2.2527, 958.3516,
0, 1404.1, 566.6821,
0, 0, 1);
Mat distCoeff1 =(Mat_<double>(5,1) << 0.0522,
-0.1651,
0.0023,
0.0020,
0.0924);
Mat cameraMat2 = (Mat_<double>(3,3) << 1413.7, -1.2189, 968.5768,
0, 1408.1, 505.1645,
0, 0, 1);
Mat distCoeff2 =(Mat_<double>(5,1) << 0.0465,
-0.1948,
-0.0013,
-0.00016774,
0.1495);
Mat R = (Mat_<double>(3,3) << 0.9108, 0.0143, -0.4127, -0.0228, 0.9996, -0.0157, 0.4123, 0.0237, 0.9107);
Mat T = (Mat_<double>(3,1) << -209.4118, 0.2208, 49.1987);
Mat R1, R2, P1, P2, Q;
Size imSize = Size(1920,1080); //Pixel Resolution
Mat frame1, frame2;
vector<Point2f> foundCorners1;
vector<Point2f> foundCorners2;
Size chessSize(11,8);
//for undistort
vector<Point2f> ufoundCorners1;
vector<Point2f> ufoundCorners2;
Mat homopnts3D(4, foundCorners1.size(), CV_64F);
Mat pnts3D;
int main(int argc, char** argv)
//Read in checkerboard images
frame1 = imread(file1);
frame2 = imread(file2);
//get corners
found1 = findChessboardCorners(frame1, chessSize, foundCorners1);
found2 = findChessboardCorners(frame2, chessSize, foundCorners2);
stereoRectify(cameraMat1, distCoeff1, cameraMat2, distCoeff2, imSize, R, T, R1, R2, P1, P2, Q);
//Addition - Undistort those points
undistortPoints(foundCorners1, ufoundCorners1, cameraMat1, distCoeff1, R1, P1);
undistortPoints(foundCorners2, ufoundCorners2, cameraMat2, distCoeff2, R2, P2);
//StereoTriangulation
triangulatePoints(P1, P2, ufoundCorners1, ufoundCorners2, homopnts3D);
//convert to euclidean
convertPointsFromHomogeneous(homopnts3D.reshape(4,1), pnts3D);
【问题讨论】:
【参考方案1】:代码看起来正确
您应该使用重映射功能检查您的立体声校正是否正确。
Mat rmap[2][2];
Mat rectifiedLeftImg;
Mat rectifiedRightImg;
initUndistortRectifyMap(cameraMat1, distCoeff1, R1, P1, imageSize, CV_16SC2, rmap[0][0], rmap[0][1]);
initUndistortRectifyMap(cameraMat2, distCoeff2, R2, P2, imageSize, CV_16SC2, rmap[1][0], rmap[1][1]);
cv::remap(frame1, rectifiedLeftimg, rmap[0][0], rmap[0][1], INTER_LINEAR, BORDER_CONSTANT, Scalar());
cv::remap(frame2, rectifiedRightimg, rmap[1][0], rmap[1][1], INTER_LINEAR, BORDER_CONSTANT, Scalar());
imshow("rectifiedLeft",rectifiedLeftimg);
imshow("rectifiedRight",rectifiedRightimg);
【讨论】:
以上是关于OpenCV:使用 cv::triangulatepoints() 进行立体摄像机跟踪的问题的主要内容,如果未能解决你的问题,请参考以下文章
我是不是需要使用 Gstreamer 构建 OpenCV 才能在 OpenCV 中使用 Gstreamer