How to change the red value of an image from a slider in QT?

  c++, qt

How can I increase/decrease the RED value from an image cv::Mat from an horizontal slider?
I tried this:

void MainWindow::RedSlider(cv::Mat image2, int value)
{


    for (int i=0; i < image2.rows; i++)
   {
        for (int j=0; j < image2.cols; j++)

        {
            image2.at<cv::Vec3b>(i,j)[2] = cv::saturate_cast<uchar>(image.at<cv::Vec3b>(i,j)[2]) + value;

        }
    }

    QImage imageupdate= QImage((const unsigned char*)(image2.data), image2.cols,image2.rows,QImage::Format_RGB888);

    int w = ui->label2->width();
    int h =ui-> label2->height();
   ui->label2->setPixmap(QPixmap::fromImage(imageupdate.scaled(w,h,Qt::KeepAspectRatio)));
}


void MainWindow::on_horizontalSlider_valueChanged(int value)
{
    brightness =(float)value;
           QPixmap pm =ui->label2->pixmap();
               if (!pm.isNull() )
               {
                    RedSlider(image,value);
               }
}

And I set the min value of the slider to -50 and mac to +50. Are these values wrong? I don’t get the right image , changing the value even slightly changes the image colors totally.

Source: Windows Questions C++

LEAVE A COMMENT