Computer vision: How to Bind Trackbar To OpenCV Windows
import cv2 as cv | ||
| ||
def nothing(x): | ||
print(x) | ||
# Create a black image, a window | ||
img = np.zeros((300,512,3), np.uint8) | ||
cv.namedWindow('image') | ||
cv.createTrackbar('B', 'image', 0, 255, nothing) | ||
cv.createTrackbar('G', 'image', 0, 255, nothing) | ||
cv.createTrackbar('R', 'image', 0, 255, nothing) | ||
switch = '0 : OFF\n 1 : ON' | ||
cv.createTrackbar(switch, 'image', 0, 1, nothing) | ||
while(1): | ||
cv.imshow('image',img) | ||
k = cv.waitKey(1) & 0xFF | ||
if k == 27:#esc | ||
break | ||
b = cv.getTrackbarPos('B', 'image') | ||
g = cv.getTrackbarPos('G', 'image') | ||
r = cv.getTrackbarPos('R', 'image') | ||
s = cv.getTrackbarPos(switch, 'image') | ||
if s == 0: | ||
img[:] = 0 | ||
else: | ||
img[:] = [b, g, r] | ||
cv.destroyAllWindows()#close window
#=======================================#
if you faced any issue contact me via what's app : +201210894349 or facebook |
Comments
Post a Comment
I hope you have benefited from this blog, and if you have any question, feel free to leave it here.