来自OpenCV C++中给定校准数据的Undistort图像

Bow*_*cho -2 c++ opencv image-processing

我有一个图像Foam_Image.jpg,我想从中删除鱼眼失真.我已经在我的calibration_data.xml文件中有相机校准数据.我真的是C++的新手,我听说过这个 undistort功能,但我不知道如何在OpenCV C++中应用它.谁能给我一个想法?

nil*_*ils 5

你是怎么创造的calibration_data.xml

你到目前为止做了什么?

我将假设它包含您从OpenCV的棋盘校准中获得的信息

// Extract chessboard
vector<vector<Point3f>> object_points;
vector<vector<Point2f>> image_points;

// ...

bool found = findChessboardCorners(image, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

// ...

// Compute intrinsic camera parameters.
vector<Mat> rvecs;
vector<Mat> tvecs;
calibrateCamera(object_points, image_points, image.size(), Camera_Matrix, Distortion_Coefficients, rvecs, tvecs);

// Store results to calibration_data.xml
Run Code Online (Sandbox Code Playgroud)

然后使用undistort()像这样的图像可以不失真

#include <opencv2/highgui/highgui.hpp>

// ...

Mat Camera_Matrix;           // From calibration_data.xml
Mat Distortion_Coefficients; // From calibration_data.xml

cv::Mat image = cv::imread( "Foam_Image,jpg" );
cv::Mat imageUndistorted; // Will be the undistorted version of the above image.

undistort(image, imageUndistorted, Camera_Matrix, Distortion_Coefficients);

// ...
Run Code Online (Sandbox Code Playgroud)

我从aishack.in获取了上述信息,如果你在网上搜索它(或者在SO上)会找到更多详细的教程.

  • 你混淆了术语.但是,您包含头文件可能不会将相应的DLL/SO链接到您的程序中.无论如何,评论不应该用于冗长的讨论.请问一个新问题. (3认同)