SEMS-data-collection/src/display.cpp

60 lines
1.6 KiB
C++
Raw Permalink Normal View History

2024-09-11 17:14:49 +08:00
// #include <fstream>
#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include "display.h"
#include <string>
// #include <vector>
void display_spectral_image(unsigned char *raw_data, long long width, long long height,std::string window_name)
{
cv::Mat img = cv::Mat(height, width,CV_16U, raw_data);
img.convertTo(img, CV_16F);
img = img / 4095 * 255;
img.convertTo(img, CV_8U);
cv::applyColorMap(img, img, cv::COLORMAP_TURBO);
cv::namedWindow("Spectral Image", 0);
cv::resizeWindow("Spectral Image", width , height );
uint16_t *p = (uint16_t *)raw_data;
cv::Vec3b white= img.at<cv::Vec3b>(0, 0);
white[0]=0;
white[1]=0;
white[2]=0;
int over_exposure_num=0;
int max_intensity=0;
for(int i=0;i<width;i++){
for(int j=0;j<height;j++){
if(*(p+(j*width+i))==4095){
img.at<cv::Vec3b>(j,i)=white;
over_exposure_num++;
}
if (*(p+(j*width+i))>max_intensity){
max_intensity=*(p+(j*width+i));
}
}
}
std::string add_text=std::string("Over Exposure:")+std::to_string(over_exposure_num)+std::string(" Max Intensity:")+std::to_string(max_intensity);
cv::putText(img,add_text.c_str(),cv::Point(30,400),cv::FONT_HERSHEY_SIMPLEX,1,CV_RGB(255,255,255),1,8);
cv::imshow(window_name, img);
cv::waitKey(1);
}
void display_img(cv::Mat img, std::string window_name)
{
cv::imshow(window_name, img);
cv::waitKey(1); // Wait for a keystroke in the window
}