31 static int clamp(
int num,
int v0,
int v1) {
32 return std::max(v0, std::min(num, v1));
50 controlIn->setStreamName(
"control");
57 camRgb->setVideoSize(640, 360);
58 camRgb->setPreviewSize(300, 300);
63 camRgb->video.link(videoEncoder->input);
64 camRgb->still.link(stillEncoder->
input);
65 camRgb->preview.link(previewOut->
input);
66 controlIn->
out.
link(camRgb->inputControl);
67 configIn->
out.
link(camRgb->inputConfig);
68 videoEncoder->bitstream.link(videoMjpegOut->input);
82 float maxCropX = (camRgb->getResolutionWidth() - camRgb->getVideoWidth()) / (
float)camRgb->getResolutionWidth();
83 float maxCropY = (camRgb->getResolutionHeight() - camRgb->getVideoHeight()) / (
float)camRgb->getResolutionHeight();
108 auto previewFrames = previewQueue->tryGetAll<
dai::ImgFrame>();
109 for(
const auto& previewFrame : previewFrames) {
110 cv::Mat frame(previewFrame->getHeight(), previewFrame->getWidth(), CV_8UC3, previewFrame->getData().data());
111 cv::imshow(
"preview", frame);
115 for(
const auto& videoFrame : videoFrames) {
117 auto frame = cv::imdecode(videoFrame->getData(), cv::IMREAD_UNCHANGED);
119 cv::imshow(
"video", frame);
125 configQueue->send(cfg);
126 printf(
"Sending new crop - x: %f, y: %f\n", cropX, cropY);
132 for(
const auto& stillFrame : stillFrames) {
134 auto frame = cv::imdecode(stillFrame->getData(), cv::IMREAD_UNCHANGED);
136 cv::imshow(
"still", frame);
140 int key = cv::waitKey(1);
143 }
else if(key ==
'c') {
146 controlQueue->send(ctrl);
147 }
else if(key ==
't') {
148 printf(
"Autofocus trigger (and disable continuous)\n");
152 controlQueue->send(ctrl);
153 }
else if(key ==
'f') {
154 printf(
"Autofocus enable, continuous\n");
157 controlQueue->send(ctrl);
158 }
else if(key ==
'e') {
159 printf(
"Autoexposure enable\n");
162 controlQueue->send(ctrl);
163 }
else if(key ==
'b') {
164 printf(
"Auto white-balance enable\n");
167 controlQueue->send(ctrl);
168 }
else if(key ==
',' || key ==
'.') {
171 lensPos =
clamp(lensPos, lensMin, lensMax);
172 printf(
"Setting manual focus, lens position: %d\n", lensPos);
175 controlQueue->send(ctrl);
176 }
else if(key ==
'i' || key ==
'o' || key ==
'k' || key ==
'l') {
181 expTime =
clamp(expTime, expMin, expMax);
182 sensIso =
clamp(sensIso, sensMin, sensMax);
183 printf(
"Setting manual exposure, time: %d, iso: %d\n", expTime, sensIso);
186 controlQueue->send(ctrl);
187 }
else if(key ==
'[' || key ==
']') {
188 if(key ==
'[') wbManual -=
WB_STEP;
189 if(key ==
']') wbManual +=
WB_STEP;
190 wbManual =
clamp(wbManual, wbMin, wbMax);
191 printf(
"Setting manual white balance, temperature: %d K\n", wbManual);
194 controlQueue->send(ctrl);
195 }
else if(key ==
'w' || key ==
'a' || key ==
's' || key ==
'd') {
197 cropX -= (maxCropX / camRgb->getResolutionWidth()) *
STEP_SIZE;
198 if(cropX < 0) cropX = maxCropX;
199 }
else if(key ==
'd') {
200 cropX += (maxCropX / camRgb->getResolutionWidth()) *
STEP_SIZE;
201 if(cropX > maxCropX) cropX = 0.0f;
202 }
else if(key ==
'w') {
203 cropY -= (maxCropY / camRgb->getResolutionHeight()) *
STEP_SIZE;
204 if(cropY < 0) cropY = maxCropY;
205 }
else if(key ==
's') {
206 cropY += (maxCropY / camRgb->getResolutionHeight()) *
STEP_SIZE;
207 if(cropY > maxCropY) cropY = 0.0f;