Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "main.h"
- using namespace cv;
- using namespace std;
- cv::Mat tros_frame;
- cv::Mat radio_mat, radio_frame, radio_framex;
- cv::Mat thermo_mat, thermo_mat32, thermo_frame, thermo_framex, thermo_colored, thermo_mycolored;
- int ksize_dred = 2, ksize_dred_c = 1, threshold_dred = 250;
- Mat grad, grad_x, grad_y;
- Mat dred_frame, canny_frame_d;
- Mat t_col_grad, t_col_grad1, t_col_gradx;
- float resize_val = 1.5;
- int filename_r = 1, filename_t = 1;
- cv::FileStorage storage;// (ffname, cv::FileStorage::READ);
- std::string path_r = "rims36/", path_t = "t1/";//"thermophotos_10/";
- std::string filename = "1";
- std::string fileformat1 = ".png";
- std::string fileformat2 = ".xml";
- std::string ffname_r = "rims36/1.xml", ffname_t = "thermophotos_10/1.xml"; //full file name
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- radio_mat = (MatZ, MatX, CV_16SC1, Scalar(0));
- radio_frame = (MatZ, MatX, CV_8UC1, Scalar(0));
- t_col_grad = imread("tgrad/thermo-gradient.png", IMREAD_COLOR);
- t_col_grad1 = imread("tgrad/thermo-gradient_scuare.png", IMREAD_COLOR);
- cv::resize (t_col_grad1, t_col_gradx, cv::Size(), 0.2, 0.231);
- //ui->label_label->setText(QString::number(radio_mat.depth()));//shit
- //ui->label_label_2->setText(QString::number(radio_frame.depth()));
- QImage thermo_rgb((uchar*)t_col_gradx.data, t_col_gradx.cols, t_col_gradx.rows, t_col_gradx.step, QImage::Format_RGB888);
- thermo_rgb = thermo_rgb.rgbSwapped();
- ui->col_grad->setPixmap(QPixmap::fromImage(thermo_rgb));//QImage::Format_RGB888
- ui->col_grad_2->setPixmap(QPixmap::fromImage(thermo_rgb));
- // ui->col_grad->setPixmap(QPixmap::fromImage(QImage(t_col_grad.data, t_col_grad.cols, t_col_grad.rows, t_col_grad.step, QImage::Format_RGB888)));
- // ui->col_grad_2->setPixmap(QPixmap::fromImage(QImage(t_col_grad.data, t_col_grad.cols, t_col_grad.rows, t_col_grad.step, QImage::Format_RGB888)));
- cv::imshow("t_col_grad", t_col_grad);
- on_s_rim_update_clicked();
- on_s_thermo_update_clicked();
- on_s_dred_update_clicked();
- on_s_dtod_update_clicked();
- on_s_tros_update_clicked();
- }
- MainWindow::~MainWindow(){
- delete ui;
- }
- void MainWindow::on_s_rim_update_clicked(){
- filename = to_string(filename_r);
- ffname_r = path_r + filename + fileformat2;
- storage.open(ffname_r, cv::FileStorage::READ);
- storage["rim"] >> radio_mat;
- storage.release();
- rim_mat2frame (&radio_mat, &radio_frame);
- cv::resize (radio_frame, radio_framex, Size(), resize_val, resize_val);
- ui->s_rim->setPixmap(QPixmap::fromImage(QImage(radio_framex.data, radio_framex.cols, radio_framex.rows, radio_framex.step, QImage::Format_Grayscale8)));
- ui->rim_num->setText(QString::number(filename_r));
- }
- void MainWindow::on_s_thermo_update_clicked(){
- filename = to_string(filename_t);
- ffname_t = path_t + filename + fileformat2;
- storage.open(ffname_t, cv::FileStorage::READ);
- storage["thermo"] >> thermo_mat;
- storage.release();
- rim_mat2frame (&thermo_mat, &thermo_frame);
- cv::resize (thermo_frame, thermo_framex, Size(), resize_val, resize_val);
- ui->s_thermo->setPixmap(QPixmap::fromImage(QImage(thermo_framex.data, thermo_framex.cols, thermo_framex.rows, thermo_framex.step, QImage::Format_Grayscale8)));
- ui->th_num->setText(QString::number(filename_t));
- }
- void MainWindow::on_s_dred_update_clicked(){
- sobel_oper (&radio_frame, &grad, &ksize_dred);
- Canny(grad, canny_frame_d, threshold_dred, 255, (2*ksize_dred_c+1));
- cv::resize (canny_frame_d, canny_frame_d, Size(), resize_val, resize_val);
- ui->s_dred ->setPixmap(QPixmap::fromImage(QImage(canny_frame_d.data, canny_frame_d.cols, canny_frame_d.rows, canny_frame_d.step, QImage::Format_Grayscale8)));
- }
- void MainWindow::on_s_dtod_update_clicked(){
- cv::normalize(thermo_mat, thermo_frame, 0, 255, cv::NORM_MINMAX);
- thermo_frame.convertTo(thermo_frame, CV_8UC1, 1);
- cv::applyColorMap(thermo_frame, thermo_colored, COLORMAP_HOT);
- cv::resize (thermo_colored, thermo_colored, cv::Size(), resize_val, resize_val);
- QImage thermo_rgb((uchar*)thermo_colored.data, thermo_colored.cols, thermo_colored.rows, thermo_colored.step, QImage::Format_RGB888);
- thermo_rgb = thermo_rgb.rgbSwapped();
- ui->s_dtod->setPixmap(QPixmap::fromImage(thermo_rgb));//QImage::Format_RGB888
- }
- void MainWindow::on_s_tros_update_clicked(){
- tros_frame = (radio_frame.rows,radio_frame.cols, CV_8UC3, Scalar(0,0,0));
- mount_frame(&canny_frame_d, &thermo_colored, &tros_frame);
- QImage thermo_rgb1((uchar*)tros_frame.data, tros_frame.cols, tros_frame.rows, tros_frame.step, QImage::Format_RGB888);
- //thermo_rgb1 = thermo_rgb1.rgbSwapped();
- ui->s_tros->setPixmap(QPixmap::fromImage(thermo_rgb1));//QImage::Format_RGB888
- }
- void MainWindow::on_s_color_update_clicked(){
- int j, k;
- float min=65535.0, max=0.0;//
- for (j = 0; j < MatX; j++) {
- for (k = 0; k < MatZ; k++) {
- if (thermo_mat.at<ushort>(k,j) > max )
- max = thermo_mat.at<ushort>(k,j);
- if (thermo_mat.at<ushort>(k,j) < min) min = thermo_mat.at<ushort>(k,j);
- }
- }
- ui->label_thermo_max->setText(QString::number(max));
- ui->label_thermo_min->setText(QString::number(min));
- for (j = 0; j < MatX; j++) {
- for (k = 0; k < MatZ; k++) {
- thermo_mat.at<ushort>(k,j) = thermo_mat.at<ushort>(k,j) - min;
- }
- }
- //
- thermo_mat32 = (MatZ, MatX, CV_32FC1, Scalar(0));
- int histSize = (max-min+1);//256;
- thermo_mat.convertTo(thermo_mat32, CV_32F, 1.0/(histSize));
- float range[]={0.0, 1.0};
- const float *histRange = range;
- Mat hist;
- cv::calcHist(&thermo_mat32, 1, 0, Mat(),
- hist, 1, &histSize, &histRange, true, false );
- // Plot the histogram
- int hist_w = 512*2; int hist_h = 400;
- int bin_w = cvRound( (double) hist_w/histSize );
- Mat histImage( hist_h, hist_w, CV_8UC1, Scalar(0) );
- normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
- for( int i = 1; i < histSize; i++ ) {
- line( histImage, Point( bin_w*(i-1), hist_h - cvRound(hist.at<float>(i-1)) ) ,
- Point( bin_w*(i), hist_h - cvRound(hist.at<float>(i)) ),
- Scalar( 255, 0, 0), 2, 8, 0 );
- }
- namedWindow( "Result", 1 ); imshow( "Result", histImage );/**/
- blur(thermo_mat32, thermo_mat32, Size(3,3), Point(-1,-1), BORDER_DEFAULT);
- //medianBlur(thermo_mat32, thermo_mat32, 3);
- cv::calcHist(&thermo_mat32, 1, 0, Mat(),
- hist, 1, &histSize, &histRange, true, false );
- float hmax = 0;
- int medT = 0; // imax
- for( int i = 0; i < histSize; i++ ) {
- if (hist.at<float>(i) > hmax ) {
- hmax = hist.at<float>(i);
- medT = i;
- }
- }
- //ui->label_thermo_max->setText(QString::number(medT));
- thermo_mycolored = Mat (MatZ, MatX, CV_8UC3, Scalar(0,0,0));
- for (int j = 0; j < thermo_mycolored.rows; j++){//thermo_mycolored.rows
- // uchar* ptr = (uchar*)(thermo_mycolored.data+j * thermo_mycolored.step);
- for (int k = 0; k < thermo_mycolored.cols; k++){
- if (thermo_mat.at<ushort>(j,k) < (ushort)medT){
- // ptr[3*k] = 0;
- // ptr[3*k+1] = 0;
- // ptr[3*k+2] = 0;
- //thermo_mycolored.at<Vec3b>(j,k)[0] = 0;
- //thermo_mycolored.at<Vec3b>(j,k)[1] = 0;
- thermo_mycolored.at<Vec3b>(j,k) =
- t_col_grad.at<Vec3b>(cvRound(thermo_mat.at<ushort>(j,k)*320/medT), 1);
- }else{
- //ptr[3*k] = 255;
- //ptr[3*k+1] = 255;
- //ptr[3*k+2] = 255;
- //thermo_mycolored.at<Vec3b>(j,k)[0] = 255;
- //thermo_mycolored.at<Vec3b>(j,k)[1] = 255;
- thermo_mycolored.at<Vec3b>(j,k) =
- t_col_grad.at<Vec3b>(cvRound((thermo_mat.at<ushort>(j,k)-medT)*(999-320)/(histSize-medT))+320, 1);
- }
- }
- }
- namedWindow( "Result0", 1 );
- imshow( "Result0", thermo_mycolored );
- // Plot the histogram
- histImage = ( hist_h, hist_w, CV_8UC1, Scalar(0) );
- normalize(hist, hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
- for( int i = 1; i < histSize; i++ ) {
- line( histImage, Point( bin_w*(i-1), hist_h - cvRound(hist.at<float>(i-1)) ) ,
- Point( bin_w*(i), hist_h - cvRound(hist.at<float>(i)) ),
- Scalar( 255, 0, 0), 2, 8, 0 );
- }
- namedWindow( "Result1", 1 ); imshow( "Result1", histImage );/**/
- //QImage thermo_rgb1((uchar*)tros_frame.data, tros_frame.cols, tros_frame.rows, tros_frame.step, QImage::Format_RGB888);
- //thermo_rgb1 = thermo_rgb1.rgbSwapped();
- //ui->s_color->setPixmap(QPixmap::fromImage(thermo_rgb1));//QImage::Format_RGB888
- for (j = 0; j < MatX; j++) {
- for (k = 0; k < MatZ; k++) {
- thermo_mat.at<ushort>(k,j) = thermo_mat.at<ushort>(k,j) + min;
- }
- }
- }
- // ///////////
- void MainWindow::on_push_next_t_clicked(){
- if (filename_t < 14) filename_t ++;
- on_s_thermo_update_clicked();
- on_s_dtod_update_clicked();
- on_s_tros_update_clicked();
- // on_s_color_update_clicked();
- }
- void MainWindow::on_push_next_r_clicked(){
- if (filename_r < 9) filename_r ++;//26
- on_s_rim_update_clicked();
- on_s_dred_update_clicked();
- on_s_tros_update_clicked();
- if (filename_t < 9) filename_t ++;
- on_s_thermo_update_clicked();
- on_s_dtod_update_clicked();
- on_s_tros_update_clicked();
- // on_s_color_update_clicked();
- }
- void MainWindow::on_push_back_t_clicked(){
- if (filename_t > 1) filename_t --;
- on_s_thermo_update_clicked();
- on_s_dtod_update_clicked();
- on_s_tros_update_clicked();
- // on_s_color_update_clicked();
- }
- void MainWindow::on_push_back_r_clicked(){
- if (filename_r > 1) filename_r --;
- on_s_rim_update_clicked();
- on_s_dred_update_clicked();
- on_s_tros_update_clicked();
- if (filename_t > 1) filename_t --;
- on_s_thermo_update_clicked();
- on_s_dtod_update_clicked();
- on_s_tros_update_clicked();
- // on_s_color_update_clicked();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement