【AI基礎】python:openCV——圖像處理(2)
阿新 • • 發佈:2018-03-14
getTrackbarPos圖像處理練習
制作一個滑動條調色板,使用函數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()
【AI基礎】python:openCV——圖像處理(2)