I'm trying to avoid using global variables in an openCV project (I'll have my supervisor no doubt teach me as to why they are bad rah rah rah :) - but at the moment they seem to be the only way I can get information out of mouse and trackbar callback functions.
Using the mouse example - at the moment I have as globals:
vector<Point2d> vectorOfPoints;
int clickCount = 0;
At the moment I have this line in main:
setMouseCallback("test",onMouse, NULL);
Then above main:
void onMouse(int event, int x, int y, int f, void* ){
if(event == CV_EVENT_LBUTTONDOWN){
vectorOfPoints.push_back(Point(x,y));
clickCount++;
}
}
It is working, but what is the syntax to get read/write access to both vectorOfPoints and clickCount inside the callback function without using globals?
I have found this question online a few times but the answers are unclear to me or wont work. There are hints within comments as how to do it, but I am so far unable to interpret the jargon correctly.
I was hoping for something as simple as the syntax I use to pass variables as references to methods ...
void referenceExampleMethod(vector<Point2d>& referenceExample){
//do something with referenceExample...
}
...less convoluted the better
I'm scared to ask (jargon overload!) but maybe it's 100% relevant - what is void* ??
Any help appreciated
Aucun commentaire:
Enregistrer un commentaire