Python Trackbar not Updating Variable

56 Views Asked by At

Making a program to track a simple object and want to add in trackbars to dynamically change some of the image processing variables.

Trackbars aren't updating the thresh and bwthresh variables used for image processing in the while loop. Even after moving the trackbars, printing the values of thresh and bwthresh in the loop showed they were unaffected. I've tried making them global variables but that was to no avail. It looks to me like it should work, so I'm a bit stumped here.

max_thresh = 254
thresh = 100 #CHANGE THRESHOLD HERE
bwthresh = 250

cv.createTrackbar('BW thresh:', 'Code Test', bwthresh, max_thresh, thresh_callback)
cv.createTrackbar('Canny thresh:', 'Code Test', thresh, max_thresh, thresh_callback)

while True:
    material, frame = capture.read()

    bwthreshnew = bwthresh
    threshnew = thresh

    print(bwthresh)
    src_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    src_gray = cv.blur(src_gray, (15,15))
    src_gray = cv.threshold(src_gray, bwthresh, max_thresh, cv.THRESH_BINARY)[1]
    
    cv.imshow('Other One', src_gray)

    thresh_callback(thresh)

    if cv.waitKey(1) == ord('r'):
        break
0

There are 0 best solutions below