-
Notifications
You must be signed in to change notification settings - Fork 5
/
undistortImage_.cpp
72 lines (59 loc) · 1.89 KB
/
undistortImage_.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <fstream>
#include "CV_header.hpp"
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
Mat img;
VideoCapture cap(0);
int m = 0, n = 0;
int rtnWaitKey = 0;
// read variables from the out file.
ifstream in("cameraCalibrationData/out.txt");
if (in.fail())
{
cout << "FAILED :: IN STREAM ! :: LINE : " << __LINE__ << ", FILE : " << __FILE__ << endl;
return -1;
}
// get matrix values.
// 1. camera matrix size.
in >> m >> n;
// define matrix variable for reading intrinsic variables
// Mat intrinsicRead = Mat(m, n, intrinsic.type());
Mat intrinsicRead = Mat(m, n, 6);
// 2. camera marix values.
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
in >> intrinsicRead.ptr<double>(i)[j];
// 3. distortion coefficients matrix size.
in >> m >> n;
// define matrix variable for reading distCoeffs variables
// Mat distCoeffsRead = Mat(m, n, distCoeffs.type());
Mat distCoeffsRead = Mat(m, n, 6);
// 4. distortion coefficients matrix value.
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
in >> distCoeffsRead.ptr<double>(i)[j];
in.close();
/* undistorting image. */
Mat imgUndistorted;
while (true)
{
cap >> img;
// img = imread("data/cb_src.png");
undistort(img, imgUndistorted, intrinsicRead, distCoeffsRead);
resize(img, img, Size(), 0.5, 0.5);
resize(imgUndistorted, imgUndistorted, Size(), 0.5, 0.5);
imshow("image", img);
imshow("image undistorted", imgUndistorted);
rtnWaitKey = waitKey(1);
if (rtnWaitKey == 27)
{
// imwrite("imgOrigin_resized.png", img);
// imwrite("imgUndistorted_resized.png", imgUndistorted);
cap.release();
return 0;
}
}
}