can't get trackbar working, getting : "Type invalid conversion from 'void (*)(int)' to 'cv::TrackbarCallback {aka void (*)(int, void*)}' [-fpermissive]"

asked 2016-03-31 23:57:42 -0600

Blaze gravatar image

Hello,

I am trying to implement trackbar in a gui that shows up an AVI video. But I am getting "Type invalid conversion from 'void ()(int)' to 'cv::TrackbarCallback {aka void ()(int, void*)}' [-fpermissive]". Also, I am getting "Invalid arguments" for "createTrackbar".

I am using MinGW as compiler and eclipse kepler as IDE.

I must be doing something terribly wrong, please help me. Given below is the code I am using.

#include "stdio.h"
#include "opencv2/opencv.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"

using namespace cv;
using namespace std;

void MyCallBack(int);

int main(int argc, char** argv) {

    int contrast=50;
    namedWindow("Example1", CV_WINDOW_AUTOSIZE);
    createTrackbar("test","Example1",&contrast,100,MyCallBack,0);
    cout<<endl;
    VideoCapture cap(argv[1]);
    if (!cap.isOpened()) return -1;
    //  CvCapture* capture = cvCreateFileCapture(argv[1]);
    Mat img;
    while(1){
        bool success = cap.read(img);
        if(!success) break;
        imshow("Example1", img);
        char c = cvWaitKey(33);
        if (c == 27) break;
    }
    cap.release();
    destroyWindow("Example2");
    return 0;
}

 void MyCallBack(int contrast){
//some code goes here
}
edit retag flag offensive close merge delete

Comments

try void MyCallBack(int contast, void *unused)

berak gravatar imageberak ( 2016-04-01 01:27:01 -0600 )edit

Maybe take a look here for possible constructions using a trackbar that got discussed yesterday. A trackbar always expects a void pointer being passed, whether it is attached to data or not.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-01 01:55:13 -0600 )edit

Thanks for your reply: berak, Steven. As suggested by both of you, I tried adding a void pointer but still the same results. Added:

int var = 9;
createTrackbar("test","Example1",&contrast,100,MyCallBack,&var);

and

void MyCallBack(int contrast, void* data){
//some code goes here
}
Blaze gravatar imageBlaze ( 2016-04-01 03:46:48 -0600 )edit