Trackbars to isolate a color in an image are not working as expected

since you use waitKey(1) anyway, you can remove all the callbacks.

why do you set in the callback? that could constitute a feedback loop.

createTrackbar with a pointer argument has been deprecated. while that still works, you can keep the code as is. in the future, the recommended way is to create with nullptr, and then call getTrackbarPos wherever you need the current value.