2 #include <opencv2/opencv.hpp>
8 constexpr
auto FPS = 25.0;
15 auto now = std::chrono::steady_clock::now();
24 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
frameTimes.back() -
frameTimes.front()).count();
25 return (
frameTimes.size() - 1) * 1000.0 / duration;
29 std::queue<std::chrono::steady_clock::time_point>
frameTimes;
37 rgbWeight =
static_cast<double>(percentRgb) / 100.0;
46 cv::Mat nanMask = cv::Mat::zeros(frame.size(), CV_8UC1);
47 for(
int r = 0; r < frame.rows; ++r) {
48 for(
int c = 0; c < frame.cols; ++c) {
49 if(std::isnan(frame.at<
float>(r, c))) {
50 nanMask.at<uchar>(r, c) = 255;
59 int thermalWidth = -1, thermalHeight = -1;
60 bool thermalFound =
false;
66 thermalSocket = features.socket;
67 thermalWidth = features.width;
68 thermalHeight = features.height;
74 throw std::runtime_error(
"No thermal camera found!");
93 camRgb->setIspScale(1, 3);
95 out->setStreamName(
"out");
97 sync->setSyncThreshold(std::chrono::milliseconds(
static_cast<int>((1 /
FPS) * 1000.0 * 0.5)));
99 cfgIn->setStreamName(
"config");
101 align->outputAligned.link(sync->inputs[
"aligned"]);
102 camRgb->isp.link(sync->inputs[
"rgb"]);
103 camRgb->isp.link(align->inputAlignTo);
105 sync->out.link(out->input);
106 cfgIn->out.link(align->inputConfig);
114 std::string windowName =
"rgb-thermal";
115 cv::namedWindow(windowName, cv::WINDOW_NORMAL);
116 cv::resizeWindow(windowName, 1280, 720);
118 cv::createTrackbar(
"Static Depth Plane [mm]", windowName,
nullptr, 2000,
updateDepthPlane);
125 auto thermalAligned = messageGroup->get<
dai::ImgFrame>(
"aligned");
127 if(frameRgb && thermalAligned) {
129 auto thermalFrame = thermalAligned->
getFrame(
true);
133 cv::Mat colormappedFrame;
134 cv::Mat thermalFrameFloat;
135 thermalFrame.convertTo(thermalFrameFloat, CV_32F);
138 auto meanValue = cv::mean(thermalFrameFloat, ~mask);
139 thermalFrameFloat.setTo(meanValue, mask);
140 cv::normalize(thermalFrameFloat, thermalFrameFloat, 0, 255, cv::NORM_MINMAX, CV_8U);
141 cv::applyColorMap(thermalFrameFloat, colormappedFrame, cv::COLORMAP_MAGMA);
143 colormappedFrame.setTo(cv::Scalar(0, 0, 0), mask);
147 cv::putText(blended,
"FPS: " +
std::to_string(fpsCounter.
getFps()), cv::Point(10, 30), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255), 2);
148 cv::imshow(windowName, blended);
151 int key = cv::waitKey(1);
152 if(key ==
'q' || key ==
'Q') {
156 auto cfg = align->initialConfig.get();
158 auto alignConfig = std::make_shared<dai::ImageAlignConfig>();
159 alignConfig->set(cfg);
160 cfgQ->send(alignConfig);