今天就跟大家聊聊有關(guān)使用python openCV實現(xiàn)繪畫板,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
創(chuàng)新互聯(lián)建站始終堅持【策劃先行,效果至上】的經(jīng)營理念,通過多達(dá)10多年累計超上千家客戶的網(wǎng)站建設(shè)總結(jié)了一套系統(tǒng)有效的推廣解決方案,現(xiàn)已廣泛運用于各行各業(yè)的客戶,其中包括:LED顯示屏等企業(yè),備受客戶夸獎。import numpy as np import cv2 def nothing(x): pass cv2.namedWindow('image') img = np.zeros((512,512,3),np.uint8) cv2.createTrackbar('R','image',0,255,nothing) cv2.createTrackbar('G','image',0,255,nothing) cv2.createTrackbar('B','image',0,255,nothing) drawing = False mode = True ix,iy = -1,-1 def drawing_fragment(event,x,y,flags,param): r = cv2.getTrackbarPos('R','image') g = cv2.getTrackbarPos('G','image') b = cv2.getTrackbarPos('B','image') color = (b,g,r) global drawing,ix,iy,mode if event == cv2.EVENT_LBUTTONDOWN: drawing = True ix = x iy = y elif event == cv2.EVENT_MOUSEMOVE: if drawing: if mode: cv2.rectangle(img,(ix,iy),(x,y),color,-1) else: cv2.circle(img,(x,y),5,color,-1) elif event == cv2.EVENT_LBUTTONUP: drawing = False cv2.setMouseCallback('image',drawing_fragment) while True: cv2.imshow('image',img) k = cv2.waitKey(2) if k == 27: break elif k == ord('q'): mode = not mode cv2.destroyAllWindows()