`
rotter
  • 浏览: 8695 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

OpenCV with Python - Trackbar

阅读更多
Issue about CreateTrackbar

Creates a trackbar and attaches it to the specified window

Usage:
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.

The problem 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')
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics