-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera_single.cpp
51 lines (36 loc) · 1.31 KB
/
camera_single.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
#include "camera_single.h"
using namespace std;
c_camera_single::c_camera_single(){
}
c_camera_single::c_camera_single(const char *calibrationFileName, const char *device_name, int width, int height)
{
// Camera parameter allocations
cameraMatrix = cv::Mat(3,3, CV_64F);
distCoeffs = cv::Mat(5,1, CV_64F);
// Frame size. Don't change the frame size if you didn't calibrate it for that spesific resolution.
frameSize.width = width;
frameSize.height = height;
// Open the camera calibration file. File name is in the config file.
cv::FileStorage file;
file.open(calibrationFileName, cv::FileStorage::READ);
if(!file.isOpened()){
cout << "ERROR: File " << calibrationFileName << " could not be opened";
}
// Get the calibration parameters.
file["Camera_Matrix"] >> cameraMatrix;
file["Distortion_Coefficients"] >> distCoeffs;
file.release();
deviceName = std::string(device_name);
}
bool c_camera_single::update(cv::Mat &imgReturn){
cv::Mat img;
if(!capture.grab() ){
cout << "Video camera is not working at the moment. Capture Error!";
exit(1);
}
capture.retrieve(img);
cv::Mat undistortedImage;
cv::undistort(img, undistortedImage, cameraMatrix, distCoeffs);
undistortedImage.copyTo(imgReturn);
return true;
}