python_opencv滑动条的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25254777/article/details/80238778
import cv2
import numpy as np




def nothing(x):
    pass



img = np.zeros((640,480,3),np.uint8)
cv2.namedWindow('img')

cv2.createTrackbar('R','img',0,255,nothing)
cv2.createTrackbar('G','img',0,255,nothing)
cv2.createTrackbar('B','img',0,255,nothing)

switch = '0:OFF \n1:ON'
cv2.createTrackbar(switch,'img',0,1,nothing)



while(1):
    cv2.imshow('img',img)
    k = cv2.waitKey(5)
    if k == ord('q'):
        break

    r = cv2.getTrackbarPos('R', 'img')
    g = cv2.getTrackbarPos('G', 'img')
    b = cv2.getTrackbarPos('B', 'img')
    s = cv2.getTrackbarPos(switch, 'img')

    if s == 0:
        img[:] = 0
    else:
        img[:] = [b,g,r]

cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/qq_25254777/article/details/80238778