温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python_opencv用线段画封闭矩形的实例

发布时间:2020-09-30 20:57:37 来源:脚本之家 阅读:192 作者:嗨小方 栏目:开发技术

如下所示:

def draw_circle(event,x,y,flags,param):
  global ix,iy,drawing,mode,start_x,start_y

  if event == cv2.EVENT_LBUTTONDOWN:
    if drawing == False:
      start_x, start_y = x,y
      ix,iy = x,y
      drawing = True
    elif drawing == True:
      cv2.line(img,(ix,iy),(x,y),(0,255,0),3)
      ix, iy = x, y
    print(drawing)
  elif event == cv2.EVENT_MBUTTONDOWN:
    drawing = False

    cv2.line(img, (ix, iy), (start_x, start_y), (0, 255, 0), 3)
    print(drawing)


  #
  # elif event == cv2.EVENT_RBUTTONUP:
  #   cv2.line(img,(ix,iy),(x,y),(0,255,0),3)
# Next we have to bind this mouse callback function to OpenCV # # window. In the main loop, we should set a keyboard binding for
# key ‘m' to toggle between rectangle and circle.
img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)

while(1):
  cv2.imshow('image',img)
  k = cv2.waitKey(1) & 0xFF
  if k == ord('m'): # 切换模式
    mode = not mode
  elif k == 27:
    break

cv2.destroyAllWindows()

以上这篇python_opencv用线段画封闭矩形的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI