-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.cpp
61 lines (50 loc) · 1.26 KB
/
Camera.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
#include "Camera.h"
#include "opencv2/opencv.hpp"
Camera::Camera()
{
intrinsic_matrix = cv::Mat(3, 3, CV_32F);
distortion_coeffs = cv::Mat(1, 5, CV_32F);
}
Camera::Camera(cv::Mat intrinsic, cv::Mat distortion)
{
intrinsic_matrix = intrinsic;
distortion_coeffs = distortion;
}
Camera::~Camera()
{
}
void Camera::serialise(QDataStream& stream)
{
stream << mat2ByteArray(intrinsic_matrix) << mat2ByteArray(distortion_coeffs);
}
void Camera::deserialise(QDataStream& stream)
{
QByteArray b1, b2;
stream >> b1 >> b2;
intrinsic_matrix = byteArray2Mat(b1);
distortion_coeffs = byteArray2Mat(b2);
}
QByteArray Camera::mat2ByteArray(const cv::Mat &image)
{
QByteArray byteArray;
QDataStream stream(&byteArray, QIODevice::WriteOnly);
stream << image.type();
stream << image.rows;
stream << image.cols;
const size_t data_size = image.cols * image.rows * image.elemSize();
QByteArray data = QByteArray::fromRawData((const char*)image.ptr(), data_size);
stream << data;
return byteArray;
}
cv::Mat Camera::byteArray2Mat(const QByteArray & byteArray)
{
QDataStream stream(byteArray);
int matType, rows, cols;
QByteArray data;
stream >> matType;
stream >> rows;
stream >> cols;
stream >> data;
cv::Mat mat(rows, cols, matType, (void*)data.data());
return mat.clone();
}