From 06f1e4d73fb858900520adbcff2082c9401e6ce0 Mon Sep 17 00:00:00 2001 From: "simon.fanetti" <simon.fanetti@etu.hesge.ch> Date: Sun, 24 May 2020 19:37:56 +0200 Subject: [PATCH] add contrasts display in GUI camera settings --- app/SandboxSetup/camerafocus.cpp | 41 ++++++++++++++++++++++++++++++++ app/SandboxSetup/camerafocus.h | 4 ++++ app/SandboxSetup/camerafocus.ui | 13 ++++++++++ 3 files changed, 58 insertions(+) diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 1542da0..2c09173 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -58,6 +58,11 @@ void CameraFocus::refreshFrame(){ // Preview image for the user cv::cvtColor(rgb, gray, CV_BGR2GRAY); gray = setup->beamer.editContrast(gray, (double)p.getContrast(), (double)p.getBrightness()); + + if(displayConstrasts){ + cvSobel(&gray); + } + cv::cvtColor(gray, rgbFromGray, CV_GRAY2BGR); if(!crc.empty()){ @@ -129,3 +134,39 @@ void CameraFocus::on_btnReset_clicked() { loadProfil(&defaultProfil, setup->beamer.getProfil()); } + +void CameraFocus::on_chbxDisplayContrast_clicked() +{ + displayConstrasts = ui->chbxDisplayContrast->isChecked(); +} + + +cv::Mat* CameraFocus::cvSobel(cv::Mat *gray){ + + // From : https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html + + int scale = 1; + int delta = 0; + int ddepth = CV_16S; + cv::Mat grad, src_gray = *gray; + + /// Generate grad_x and grad_y + cv::Mat grad_x, grad_y; + cv::Mat abs_grad_x, abs_grad_y; + + /// Gradient X + //Scharr( src_gray, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT ); + cv::Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, cv::BORDER_DEFAULT ); + cv::convertScaleAbs( grad_x, abs_grad_x ); + + /// Gradient Y + //Scharr( src_gray, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT ); + cv::Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, cv::BORDER_DEFAULT ); + cv::convertScaleAbs( grad_y, abs_grad_y ); + + /// Total Gradient (approximate) + cv::addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad ); + grad.copyTo(*gray); + + return gray; +} diff --git a/app/SandboxSetup/camerafocus.h b/app/SandboxSetup/camerafocus.h index 914d758..b0fb84e 100644 --- a/app/SandboxSetup/camerafocus.h +++ b/app/SandboxSetup/camerafocus.h @@ -36,16 +36,20 @@ private slots: void on_btnReset_clicked(); + void on_chbxDisplayContrast_clicked(); + private: Ui::CameraFocus *ui; SandboxSetup *setup; bool state = false; QTimer *frameTimer; FrameProcessProfil defaultProfil; + bool displayConstrasts = false; void refreshFrame(); void loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfil *profilSaved); void initCameraParams(); + cv::Mat* cvSobel(cv::Mat *gray); }; #endif // CAMERAFOCUS_H diff --git a/app/SandboxSetup/camerafocus.ui b/app/SandboxSetup/camerafocus.ui index dcaa483..5a4f218 100644 --- a/app/SandboxSetup/camerafocus.ui +++ b/app/SandboxSetup/camerafocus.ui @@ -160,6 +160,19 @@ <string>Reset</string> </property> </widget> + <widget class="QCheckBox" name="chbxDisplayContrast"> + <property name="geometry"> + <rect> + <x>80</x> + <y>30</y> + <width>131</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Show Contrasts</string> + </property> + </widget> </widget> <resources/> <connections> -- GitLab