import cv2
# Function to be called when the trackbar value changes (placeholder)
def trackChanged(x):
pass
# Create a named window to display color trackbars
cv2.namedWindow('Color Track Bar')
# Define names for the trackbars
hh = 'Max'
hl = 'Min'
# Create trackbars for maximum and minimum values
cv2.createTrackbar("Max", 'Color Track Bar', 0, 255, trackChanged)
cv2.createTrackbar("Min", 'Color Track Bar', 0, 255, trackChanged)
# Load and resize an image
img = cv2.imread('lena.tif')
img = cv2.resize(img, (0, 0), fx=0.55, fy=0.55)
while (True):
# Get the current position of the trackbars
hul = cv2.getTrackbarPos("Max", 'Color Track Bar')
huh = cv2.getTrackbarPos("Min", 'Color Track Bar')
# Apply thresholding with different methods based on the trackbar values
ret, thresh1 = cv2.threshold(img, hul, huh, cv2.THRESH_BINARY)
ret, thresh4 = cv2.threshold(img, hul, huh, cv2.THRESH_TOZERO)
# Display the thresholded images
cv2.imshow("thresh1", thresh1)
cv2.imshow("thresh4", thresh4)
# Break the loop if the ESC key is pressed
if cv2.waitKey(1) == 27:
break
# Close all windows
cv2.destroyAllWindows()