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')