11 void mouseCallback(
int event,
int x,
int y,
int flags,
void* userdata) {
16 const cv::Scalar
WHITE(255, 255, 255);
24 bool thermal_found =
false;
26 if(std::find_if(features.supportedTypes.begin(),
27 features.supportedTypes.end(),
29 != features.supportedTypes.end()) {
31 width = features.width;
32 height = features.height;
37 throw std::runtime_error(
"Thermal camera not found!");
39 thermal->setPreviewSize(width, height);
43 thermal->preview.link(xlink->input);
45 thermal->raw.link(xlinkRaw->
input);
48 xlink->setStreamName(
"thermal");
53 const char* tempWindow =
"temperature";
54 const char* imageWindow =
"image";
55 cv::namedWindow(tempWindow, cv::WINDOW_NORMAL);
57 cv::namedWindow(imageWindow, cv::WINDOW_NORMAL);
60 cv::moveWindow(tempWindow, 0, 0);
61 cv::resizeWindow(tempWindow, width * 4, height * 4);
62 cv::moveWindow(imageWindow, width * 4, 0);
63 cv::resizeWindow(imageWindow, width * 4, height * 4);
69 cv::Mat frameFp32(temp->getHeight(), temp->getWidth(), CV_32F);
70 frame.convertTo(frameFp32, CV_32F);
72 cv::normalize(frameFp32, normalized, 0, 255, cv::NORM_MINMAX, CV_8UC1);
73 cv::Mat colormapped(temp->getHeight(), temp->getWidth(), CV_8UC3);
74 cv::applyColorMap(normalized, colormapped, cv::COLORMAP_MAGMA);
75 if(
mouseX < 0 || mouseY < 0 || mouseX >= colormapped.cols ||
mouseY >= colormapped.rows) {
76 mouseX = std::max(0, std::min(
static_cast<int>(
mouseX), colormapped.cols - 1));
77 mouseY = std::max(0, std::min(
static_cast<int>(
mouseY), colormapped.rows - 1));
80 cv::minMaxLoc(frameFp32, &min, &max);
81 auto textColor =
WHITE;
87 snprintf(text,
sizeof(text),
"%.1f deg C", frameFp32.at<
float>(
mouseY,
mouseX));
88 bool putTextLeft =
mouseX > colormapped.cols / 2;
89 cv::putText(colormapped, text, cv::Point(putTextLeft ?
mouseX - 100 :
mouseX + 10,
mouseY - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, textColor, 1);
90 cv::imshow(tempWindow, colormapped);
94 cv::imshow(imageWindow, image->getCvFrame());
96 int key = cv::waitKey(1);