I am creating a simple image processing application using OpenCV / Qt and I am looking for a way to optimize the code that I have created (https://github.com/krslynx/ImageProcessingApplication). Currently, each time a slider is moved in the application the respective method is called which alters the image, for example:
/** ActionEvent for the brightness slider moving */
void MainWindow::on_brightnessSlider_sliderMoved() {
//setBrightness is the method called
updateImage(ui->pixmap, setBrightness(this->image, ui->brightnessSlider->value());
}
Where the updateImage method updates the QLabel (ui->pixmap) which stores the image. This presents a problem as the cv::Mat image / this->image is the raw image which is called in each ActionEvent thus if the Brightness Slider is moved, then the Contrast Slider is moved, the brightness changes won't be persisted due to the sliders depending on this->image rather than the set QLabel pixmap. I 'solved' this issue by using the following code:
/** ActionEvent for the brightness slider moving */
void MainWindow::on_brightnessSlider_sliderMoved() {
cv::Mat result = this->image;
result = setBrightness(result, ui->brightnessSlider->value());
result = setContrast(result, ui->contrastSlider->value());
result = setSharpness(result, ui->sharpnessSlider->value());
result = setZoom(result, ui->zoomSlider->value());
updateImage(ui->pixmap, result);
}
While this code gives the exact visual effect I need, it means that each action event needs to have ALL of the above code within it (and I need to keep adding code for each new feature I add), and I am re-processing things that I've already processed. When dealing with a larger image, which has had all of the sliders moved it can sometimes take over 1.1 seconds to process.
I tried to instead change the global image this->image by reference, and even create another global for the altered image however I ran into problems where when I moved the brightness/contrast/sharpness/zoom slider up/down, it would change far too vigorously.
Any pointers would be greatly appreciated! I am fairly new to C++!