OpenCV with Python - Trackbar

本文介绍了一个关于OpenCV中Trackbar回调函数的问题及其解决方案。当Trackbar的回调函数被调用时,传入的'value'参数不会更新。解决方法是在回调函数内部使用cvGetTrackbarPos函数获取最新的滑块位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Issue about CreateTrackbar

Creates a trackbar and attaches it to the specified window

[b]Usage:[/b]
int cvCreateTrackbar(trackbar name, window name, int* value, int count, callback on change );

value: Pointer to an integer variable, whose value will reflect the position of the slider. Upon creation, the slider position is defined by this variable.

[b]The problem[/b] is when the callback function is invoked, the 'value' will not change.

The solution is call GetTrackbarPos in the callback Func..

Example:

fPos = 0
sPos = 0
def bar(pos):
global fPos
global sPos

print pos
fPos = cvGetTrackbarPos('f', 'Test')
sPos = cvGetTrackbarPos('s', 'Test')
print fPos
print sPos
def show():
global fPos
global sPos

cvNamedWindow('Test', 1)
cvCreateTrackbar('f', 'Test', fPos, 10, bar)
cvCreateTrackbar('s', 'Test', sPos, 10, bar)

cvShowImage('Test', cvCreateImage(cvSize(240, 240), IPL_DEPTH_8U, 3))
cvResizeWindow('Test', 240, 240)
cvWaitKey(0)
cvDestroyWindow('Test')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值