溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python_opencv用線段畫封閉矩形的實例

發(fā)布時間:2020-09-30 20:57:37 來源:腳本之家 閱讀:192 作者:嗨小方 欄目:開發(fā)技術(shù)

如下所示:

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用線段畫封閉矩形的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI