成都网站建设设计

将想法与焦点和您一起共享

使用pythonopenCV实现绘画板-创新互联

今天就跟大家聊聊有关使用python openCV实现绘画板,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联建站始终坚持【策划先行,效果至上】的经营理念,通过多达10多年累计超上千家客户的网站建设总结了一套系统有效的推广解决方案,现已广泛运用于各行各业的客户,其中包括:LED显示屏等企业,备受客户夸奖。
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()

分享标题:使用pythonopenCV实现绘画板-创新互联
网站网址:http://chengdu.cdxwcx.cn/article/egjjs.html