Ask Your Question
0

How to solve the problem on C2056 undeclared identifier

asked 2019-01-12 04:01:58 -0500

LCY gravatar image

updated 2019-01-12 04:16:16 -0500

berak gravatar image

I having problem with this

void colortrackbar() {

        namedWindow("Color", CV_WINDOW_AUTOSIZE);
    cvCreateTrackbar("Blue", "Color", 0, 1, bluecolor_callback);
    cvCreateTrackbar("Green", "Color", 0, 1);
    cvCreateTrackbar("Red", "Color", 0, 1);
}

void bluecolor_callback(int position) {

    if (position == 0) {
        int H_MIN = 0;
        int H_MAX = 255;
        int S_MIN = 0;
        int S_MAX = 255;
        int V_MIN = 0;
        int V_MAX = 255;
    }
    else {
        int H_MIN = 0;
        int H_MAX = 255;
        int S_MIN = 110;
        int S_MAX = 255;
        int V_MIN = 148;
        int V_MAX = 255;
    }

and having error

C2065  "bluecolor_callback" : undeclared identifier

and I don't know how to solve the problem. Please help me, thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-01-12 04:25:40 -0500

berak gravatar image

you have to declare your callback function, before you use it in the code

(also, you need a different signature !). like this:

 // declaration:
 void bluecolor_callback(int position, void*);

 int main() {
          ...
          // you HAVE TO use c++, not the deprecated c-api calls !!!!!
          cv::createTrackbar("Blue", "Color", 0, 1, bluecolor_callback);
          ...
 }

 // definition:
 void bluecolor_callback(int position, void*) {
         ... some code
 }

please also have another look at the tutorial

edit flag offensive delete link more

Comments

must create trackbar at main function?

LCY gravatar imageLCY ( 2019-01-12 04:28:00 -0500 )edit

must create trackbar at main function?

not nessecarily, that was just an example. but again, the declaration has to go before you use it.

berak gravatar imageberak ( 2019-01-12 04:29:22 -0500 )edit

ok thank you

LCY gravatar imageLCY ( 2019-01-12 04:32:00 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-12 04:01:58 -0500

Seen: 17 times

Last updated: Jan 12