OpenCV C++中给定校准数据的无失真图像

Undistort image from given calibration data in OpenCV C++

本文关键字:数据 无失真图像 C++ OpenCV      更新时间:2023-10-16

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

您是如何创建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

然后使用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);
// ...

我从aishack.in获取了以上信息,如果你在网上(或SO上)搜索,会发现更多详细的教程。