圖像處理練習ide
製做一個滑動條調色板,使用函數cv2.getTrackbarPos();cv2.creatTrackbar()函數
import cv2 import numpy as np def nothing(x): pass img = np.zeros((300,512,3), np.uint8) cv2.namedWindow('image') 」建立一個開關「 switch = '0:OFF\n1:ON' cv2.createTrackbar(switch,'image',0,1,nothing) 」建立3個調色條「 cv2.createTrackbar('R','image',0,255,nothing) cv2.createTrackbar('G','image',0,255,nothing) cv2.createTrackbar('B','image',0,255,nothing) while(1): cv2.imshow('image', img) k=cv2.waitKey(0) if k == ord('q'):#按q鍵退出 break 」從調色條 獲取值「 r = cv2.getTrackbarPos('R','image') g = cv2.getTrackbarPos('G','image') b = cv2.getTrackbarPos('B','image') 」開關「 change = cv2.getTrackbarPos(switch, 'image') if k == ord('s') and change == 1: img[:]=[r,g,b] cv2.destroyAllWindows()