opencv轨迹栏未显示

时间:2018-08-13 15:32:17

标签: visual-c++ opencv3.0

包括

#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;
}

注意::当我运行代码时,它运行正常,没有错误,但是轨迹栏没有显示,据我所知一切应该没事。

1 个答案:

答案 0 :(得分:1)

根据OpenCV documentation

  

int createTrackbar(const string&trackbarname,const string&winname,   int *值,int计数,TrackbarCallback onChange = 0,void * userdata = 0)

因此,您的窗口名称应为“女孩”

我认为这条线

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

应改为

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

和行

imshow("girl", srimg);

应该是

imshow("Girl", srimg);

保留通用窗口名称。

如果无法解决,请尝试

namedWindow("Girl", 1);

createTrackbar函数上方。 来源:Example