As the title suggest, I\'m having some trouble implementing OpenCV\'s mouseCallback function in a class based C++ structure. Allow me to explain. I have defined a class called B
I was using this method too, however I realized that the static helper class was quite rigid and type and method bound.
Just for further reference I've defined a templated free function that looks like:
template
void FreeOnMouseCallback(int event, int x, int y, int flags, void* ptr)
{
auto* mcPtr = static_cast(ptr);
if(mcPtr != NULL)
{
(mcPtr->*MouseClickType)(event, x, y, flags);
}
}
And I can now call arbitrary functions (matching the signature, but not the name) inside classes with
cv::setMouseCallback( WindowName, FreeOnMouseCallback, this );
It might be extended if the void* ptr is also required, but I've omitted it here.