#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <fstream>
#include <sstream>
#include <boost/format.hpp>
#include <iomanip>
#include <string.h>
using namespace std;
using namespace cv;
string dataset_path = "/home/wang/Ginger2020/Dataset/Bumblebee/01/image_0";
void ReadImg(int &index,
string &DatasetPath,
cv::Mat &dataset);
int main ( int argc, char** argv )
{
int img_file_index = 0;
int filecount = 0;
while (1)
{
cv::Mat dataset;
ReadImg(img_file_index, dataset_path, dataset);
if(dataset.data == 0) { cout<<"图像读取完毕"<<endl; break; }
cout << " img_file_index " << img_file_index << endl;
img_file_index++;
cv::Mat K_img(3, 3, CV_64F);
cv::Mat coeff(5, 1, CV_64F);
K_img.at<double>(0, 0) = 1644.7156613466043;
K_img.at<double>(0, 1) = 0;
K_img.at<double>(0, 2) = 640.0;
K_img.at<double>(1, 0) = 0;
K_img.at<double>(1, 1) = 1644.7156613466043;
K_img.at<double>(1, 2) = 480.0;
K_img.at<double>(2, 0) = 0;
K_img.at<double>(2, 1) = 0;
K_img.at<double>(2, 2) = 1;
coeff.at<double>(0,0) = -0.54184704404293005;
coeff.at<double>(1,0) = -1.1038602217192159;
coeff.at<double>(2,0) = 0.0;
coeff.at<double>(3,0) = 0.0;
coeff.at<double>(4,0) = 7.8578495299742874;
cv::Mat newimage;
cv::Mat new_matrix;
cv::undistort(dataset, newimage, K_img, coeff, new_matrix);
string imgfilename;
std::stringstream StrStm;
StrStm << setfill('0') << setw(5) << filecount;
filecount++;
StrStm >> imgfilename;
imgfilename += ".jpg";
imwrite(imgfilename, newimage);
StrStm.clear();
imgfilename.clear();
if(index==10) { break; }
}
return 0;
}
void ReadImg(int &index,
string &DatasetPath,
cv::Mat &dataset)
{
boost::format fmt("%s/my_video-3_%03d.jpg");
cv::Mat Lab;
Lab = cv::imread((fmt % DatasetPath % index).str(), cv::IMREAD_GRAYSCALE);
if ( Lab.data == 0 )
{
cout << " 图像读取完毕! " << endl;
break;
}
dataset = Lab;
}