0

include

#include <opencv/highgui.h>
#include <iostream>

using namespace std;
using namespace cv;

Mat srimg, deimg;

int max_brightness = 100;
int slider_b = (max_brightness / 2);

void on_change_brightness(int, void*)
{
    int brightness = slider_b - (max_brightness / 2);
    deimg = srimg + Scalar::all(brightness);
    imshow("Girl", deimg);
}

int main()
{
    srimg = imread("lenna.PNG");

    imshow("girl", srimg);

    createTrackbar("Track", "Window", &slider_b, max_brightness,on_change_brightness);

    waitKey();

    return EXIT_SUCCESS;
}

Note:: when I run the code it works well no error, but the track bar does not show up, and to my knowledge everything should be fine.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
Allaye
  • 833
  • 6
  • 18

1 Answers1

1

According to OpenCV documentation,

int createTrackbar(const string& trackbarname, const string& winname, int* value, int count, TrackbarCallback onChange=0, void* userdata=0)

Thus, your window name should be "Girl"

I think the line

createTrackbar("Track", "Window", &slider_b, max_brightness,on_change_brightness);

should instead be

createTrackbar("Track", "Girl", &slider_b, max_brightness,on_change_brightness);

and the line

imshow("girl", srimg);

should instead be

imshow("Girl", srimg);

to keep a common window name.

If this doesn't work out, try

namedWindow("Girl", 1);

above the createTrackbar function. Source: Example