Ask Your Question
0

Trackbars on OSX (C++)

asked 2016-02-27 20:28:24 -0600

Hello All,

I'm trying to use trackbars on my project and for some reason they're unresponsive and can't interact with them.

Below is my code:

 #include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

//global variables
int h_min_slider;
int s_min_slider;

static void on_Hchange (int hvalue,void *userData) {
    cout << "Changing H" << endl ;
}

static void on_Vchange (int vvalue, void *userData) {
    cout << "Changing V" << endl;
}

int main(int argc, const char * argv[]) {
    // insert code here...


    VideoCapture capture(0);
    if (!capture.isOpened()) {
        cout << "Webcam is not opened" << endl;
    }
    //create bars windows
    namedWindow("Trackbars",1);

    //initialize bars
    h_min_slider = 100;
    s_min_slider = 100;

    //create Trackbars
    createTrackbar("H_min", "Trackbars", 0, 255,on_Hchange,&s_min_slider);
    createTrackbar("S_min", "Trackbars", 0, 255,on_Vchange,&h_min_slider);

    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    Mat image;

    while (true) {
        Mat image;
        Mat HSVImage;
        Mat processedImage;

        capture.read(image); //read raw image from Camera
        cvtColor(image, HSVImage, CV_BGR2HSV); //convert image to HSV and save into HSVImage
        inRange(HSVImage, Scalar(0,136,192), Scalar(171,205,255), processedImage);

        imshow("Image", image);
        imshow("Processed Image", processedImage);

    }
    return 0;
}

Here is a picture of the trackbars, also, they don't show the current value either

image description

Thank you for your help!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-02-27 23:29:50 -0600

berak gravatar image

you got the arguments wrong, it should be:

//create Trackbars
createTrackbar("H_min", "Trackbars", &s_min_slider, 255,on_Hchange);
createTrackbar("S_min", "Trackbars", &h_min_slider, 255,on_Vchange);
edit flag offensive delete link more

Comments

Hi berak,

Thanks for your reply, I tried what you suggested but still getting the same trackbar behaviour. Do you know what else could be the problem?

Thanks

Otto gravatar imageOtto ( 2016-02-28 11:54:40 -0600 )edit

not really, unfortunately

but you could try to follow known issues, like https://github.com/Itseez/opencv/pull...

berak gravatar imageberak ( 2016-02-28 12:31:54 -0600 )edit

Thanks Berak!

I finally found what was wrong with my code. I forgot to use waitKey(); so I added these lines at the end of the while loop:

if(waitKey(30) >= 0) break;

Thanks for your help!

Otto gravatar imageOtto ( 2016-02-28 18:49:56 -0600 )edit
0

answered 2016-05-18 05:41:09 -0600

GOD BLESS YOU. WAITKEY IS THE ANSWER!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-27 20:28:24 -0600

Seen: 1,178 times

Last updated: Feb 27 '16