-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathundistort.cpp
56 lines (50 loc) · 1.58 KB
/
undistort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <opencv2/highgui/highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include "undistort.h"
#include <iostream>
using namespace cv;
using namespace std;
void UndistortImages::loadImage()
{
UndistortImages::src1=imread("1.png");
UndistortImages::src2=imread("2.png");
UndistortImages::src3=imread("3.png");
UndistortImages::src4=imread("4.png");
src_vec.push_back(src1);
src_vec.push_back(src2);
src_vec.push_back(src3);
src_vec.push_back(src4);
dst_vec.push_back(dst1);
dst_vec.push_back(dst2);
dst_vec.push_back(dst3);
dst_vec.push_back(dst4);
cout<<" load src success! "<<endl;
}
void UndistortImages::loadParameters()
{
FileStorage fs("c:\\xrayA.xml",cv::FileStorage::READ);
if(!fs.isOpened()) {
cerr<<"Failed to open CamMatrix"<<endl;
system("pause");
exit(EXIT_FAILURE);
}
fs["camera_matrix"]>>matrix;
fs["distortion_coefficients"]>>coeff;
cout<<"Matrix"<<matrix<<std::endl;
cout<<"Coeff"<<coeff<<std::endl;
cout<<" load parameters success! "<<endl;
}/*I wonder if there is a better way to automatically write images and save as different file.
Now, after call OpenCV undistort function, I have saved undistorted images as “dst.png”,
and whenever the program generates a picture, I will manually modify the name.*/
void UndistortImages::undistortImages()
{
for(int i=0;i<4;i++)
{
undistort(src_vec[i],dst_vec[i],matrix,coeff,new_matrix);
cv::imshow("src_img",src_vec[i]);
cv::imshow("dst_img",dst_vec[i]);
cv::waitKey();
cv::imwrite("dst.png",dst_vec[i]);
}
cout<<"undistort success!"<<endl;
}