python openCV自制繪畫板
本文實(shí)例為大家分享了python openCV自制繪畫板的具體代碼,供大家參考,具體內(nèi)容如下
import numpy as npimport cv2def nothing(x): passcv2.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 = Falsemode = Trueix,iy = -1,-1def 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 = Falsecv2.setMouseCallback(’image’,drawing_fragment)while True: cv2.imshow(’image’,img) k = cv2.waitKey(2) if k == 27: break elif k == ord(’q’): mode = not modecv2.destroyAllWindows()
測(cè)試效果
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. vue跳轉(zhuǎn)頁(yè)面常用的幾種方法匯總2. XML 非法字符(轉(zhuǎn)義字符)3. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)4. XML入門的常見問(wèn)題(三)5. 不要在HTML中濫用div6. ASP動(dòng)態(tài)include文件7. 父div高度不能自適應(yīng)子div高度的解決方案8. asp createTextFile生成文本文件支持utf89. Jquery使用原生AJAX方法請(qǐng)求數(shù)據(jù)10. el-input無(wú)法輸入的問(wèn)題和表單驗(yàn)證失敗問(wèn)題解決
