-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtualcamera.cpp
More file actions
75 lines (67 loc) · 1.84 KB
/
virtualcamera.cpp
File metadata and controls
75 lines (67 loc) · 1.84 KB
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
73
74
75
#include "virtualcamera.h"
#include "utilities.h"
#include <QFile>
#include <QObject>
#include <QMessageBox>
VirtualCamera::VirtualCamera()
{
distortion = NULL;
rotationMatrix = NULL;
translationVector = NULL;
fc.x=0;
fc.y=0;
cc.x=0;
cc.y=0;
}
VirtualCamera::~VirtualCamera()
{
}
void VirtualCamera::loadDistortion(QString path)
{
loadMatrix(distortion, 5, 1, path.toStdString());
}
bool VirtualCamera::loadCameraMatrix(QString path)
{
bool existPath = QFile::exists(path);
if(!existPath){
QMessageBox::warning(NULL, QObject::tr("Matrix not found"), QObject::tr("File: '") + path + QObject::tr("' need to be added."));
return false;//Imply that the matrix didn't loaded successfully.
}
cv::Mat camMatrix;
loadMatrix(camMatrix, 3, 3, path.toStdString());
cc.x = Utilities::matGet2D(camMatrix, 0, 2);//0, 2表示第0行,第2列
cc.y = Utilities::matGet2D(camMatrix, 1, 2);
fc.x = Utilities::matGet2D(camMatrix, 0, 0);
fc.y = Utilities::matGet2D(camMatrix, 1, 1);
return true;
}
void VirtualCamera::loadRotationMatrix(QString path)
{
loadMatrix(rotationMatrix, 3, 3, path.toStdString());
}
void VirtualCamera::loadTranslationVector(QString path)
{
loadMatrix(translationVector, 3, 1, path.toStdString());
}
int VirtualCamera::loadMatrix(cv::Mat &matrix, int rows, int cols, std::string file)
{
std:: ifstream in1;
in1.open(file);
if(!in1)
{
return -1;
}
if(!matrix.empty())
matrix.release();
matrix = cv::Mat(rows, cols, CV_32F);//cv_32f表示数据精度32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN )
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
float val;
in1>>val;
Utilities::matSet2D(matrix, i, j, val);
}
}
return 1;
}