簡體   English   中英

OpenCV:使用cv :: triangulatepoints()進行立體定向跟蹤的問題

[英]OpenCV: Issue with Stereocamera Tracking using cv::triangulatepoints()

我正在嘗試使用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);
}

該代碼看起來正確

您應使用重映射功能檢查立體聲整流是否正確。

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM