-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSLCameraVirtual.cpp
More file actions
148 lines (107 loc) · 4.15 KB
/
SLCameraVirtual.cpp
File metadata and controls
148 lines (107 loc) · 4.15 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "SLCameraVirtual.h"
#include <cstdio>
#include <QString>
#include <QSettings>
#include "CodecPhaseShift3.h"
#include "CodecPhaseShift3Unwrap.h"
#include "CodecPhaseShift4.h"
#include "CodecPhaseShift2x3.h"
#include "CodecPhaseShiftNStep.h"
#include "CodecPhaseShift3FastWrap.h"
#include "CodecPhaseShift2p1.h"
#include "CodecFastRatio.h"
#include "CodecGrayCode.h"
std::vector<CameraInfo> SLCameraVirtual::getCameraList(){
CameraInfo info;
info.vendor = "SLStudio";
info.model = "Virtual Camera";
info.busID = 0;
std::vector<CameraInfo> ret;
ret.push_back(info);
return ret;
}
SLCameraVirtual::SLCameraVirtual(unsigned int, CameraTriggerMode triggerMode): Camera(triggerMode), frameWidth(640), frameHeight(512), counter(0){
QSettings settings("SLStudio");
CodecDir dir = (CodecDir)settings.value("pattern/direction", CodecDirHorizontal).toInt();
if(dir == CodecDirNone)
std::cerr << "SLCameraVirtual: invalid coding direction " << std::endl;
QString patternMode = settings.value("pattern/mode", "CodecPhaseShift3").toString();
if(patternMode == "CodecPhaseShift3")
encoder = new EncoderPhaseShift3(frameWidth, frameHeight, dir);
else if(patternMode == "CodecPhaseShift4")
encoder = new EncoderPhaseShift4(frameWidth, frameHeight, dir);
else if(patternMode == "CodecPhaseShift2x3")
encoder = new EncoderPhaseShift2x3(frameWidth, frameHeight, dir);
else if(patternMode == "CodecPhaseShift3Unwrap")
encoder = new EncoderPhaseShift3Unwrap(frameWidth, frameHeight, dir);
else if(patternMode == "CodecPhaseShiftNStep")
encoder = new EncoderPhaseShiftNStep(frameWidth, frameHeight, dir);
else if(patternMode == "CodecPhaseShift3FastWrap")
encoder = new EncoderPhaseShift3FastWrap(frameWidth, frameHeight, dir);
else if(patternMode == "CodecPhaseShift2p1")
encoder = new EncoderPhaseShift2p1(frameWidth, frameHeight, dir);
else if(patternMode == "CodecFastRatio")
encoder = new EncoderFastRatio(frameWidth, frameHeight, dir);
else if(patternMode == "CodecGrayCode")
encoder = new EncoderGrayCode(frameWidth, frameHeight, dir);
else
std::cerr << "SLScanWorker: invalid pattern mode " << patternMode.toStdString() << std::endl;
currentBuffer.create(frameHeight, frameWidth, CV_8U);
std::cout << "SLCameraVirtual: Virtual Camera Started" << std::endl;
}
CameraSettings SLCameraVirtual::getCameraSettings(){
CameraSettings settings;
settings.shutter = 0.0;
settings.gain = 0.0;
return settings;
}
void SLCameraVirtual::startCapture(){
capturing = true;
}
void SLCameraVirtual::stopCapture(){
if(!capturing){
std::cerr << "SLCameraVirtual: not capturing!" << std::endl;
return;
}
}
CameraFrame SLCameraVirtual::getFrame(){
unsigned int depth = counter % encoder->getNPatterns();
cv::Mat patternCV = encoder->getEncodingPattern(depth);
// pick out first channel
cv::Mat patternCVChannels[3];
cv::split(patternCV, patternCVChannels);
patternCV = patternCVChannels[0];
// general repmat
cv::Mat frameCV;
frameCV = cv::repeat(patternCV, (frameHeight+patternCV.rows-1)/patternCV.rows, (frameWidth+patternCV.cols-1)/patternCV.cols);
frameCV = frameCV(cv::Range(0, frameHeight), cv::Range(0, frameWidth));
frameCV = frameCV.clone();
// add noise
frameCV.convertTo(frameCV, CV_32F);
cv::Mat noise(frameCV.size(), frameCV.type());
cv::randn(noise, 0, 3);
frameCV += noise;
frameCV.convertTo(currentBuffer, CV_8U);
counter++;
//cv::imwrite("frameCV.png", frameCV);
// return as CameraFrame struct
CameraFrame frame;
frame.height = currentBuffer.rows;
frame.width = currentBuffer.cols;
frame.memory = currentBuffer.data;
frame.timeStamp = counter;
frame.sizeBytes = currentBuffer.rows*currentBuffer.cols;
return frame;
}
size_t SLCameraVirtual::getFrameSizeBytes(){
return frameWidth*frameHeight;
}
size_t SLCameraVirtual::getFrameWidth(){
return frameWidth;
}
size_t SLCameraVirtual::getFrameHeight(){
return frameHeight;
}
SLCameraVirtual::~SLCameraVirtual(){
delete encoder;
}