Popular Posts

May 22, 2020

TrackBar(example1)- OpenCV, python



import numpy as np
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)

#adding a switch(on/Off)
switch = 'O : OFF\n 1 : ON'
cv.createTrackbar(switch, 'image', 0, 1, nothing)

while(1):
    cv.imshow(
'image', img)
    k=cv.waitKey(
1)
   
if k==27:
       
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:
       
#change image color
       
img[:] = [b, g, r]

cv.destroyAllWindows()

No comments:

Post a Comment