diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 1542da0600ba2af5554a6928417a773c512f3be5..2c09173dbd277f4918b8c9e048b3dcb73e0ec71e 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 914d758ecd8671feb506b1e00622dd3809cd548a..b0fb84e60c8666fb92dd8bcba836f267108f5211 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 dcaa483dbb30457ffd2b25bb16b13163d3cdb678..5a4f218da5f50d6431cb41699ef99ed409ee07f8 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>