error C3867 在OpenCV中将回调函数与变量进行封装

在OpenCV中试图将滑动条回调函数与变量进行封装,便于管理,尝试以下类似代码时出错,error C3867。

cv::createTrackbar ("Thresh", "HarrDemo", &this->thresh, this->maxThresh, this->HarrTrack);
//或者
cv::createTrackbar ("Thresh", "HarrDemo", &object.thresh, object.maxThresh, object.HarrTrack);

将 this->HarrTrack前面加上&会出现error C2276: “&”: 绑定成员函数表达式上的非法操作

原因类的成员函数默认带有一个this指针参数,那么它作为泛函的参数其实就不匹配了,因为泛函中的Func类型并没有this指针。

解决思路:用全局函数、友元函数或者类静态成员函数作为回调函数,利用了函数creatTrackbar的最后一个参数,函数原型:

@param onChange Pointer to the function to be called every time the slider changes position. This function should be prototyped as void Foo(int,void\*); , where the first parameter is the trackbar
position and the second parameter is the user data (see the next parameter). If the callback is the NULL pointer, no callbacks are called, but only value is updated.
@param userdata User data that is passed as is to the callback. It can be used to handle trackbar events without using global variables.
 */
CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname,
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值