7把滑鼠當畫筆
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time : 2016/11/14 9:42
# @author : retacn
# @site :
處理滑鼠事件
# @file : mousedraw.py
# @software: pycharm
importcv2
events=[iforiindir(cv2)if
'event'
ini]
print(events)
['event_flag_altkey', 'event_flag_ctrlkey', 'event_flag_lbutton', 'event_flag_mbutton', 'event_flag_rbutton', 'event_flag_shiftkey', 'event_lbuttondblclk', 'event_lbuttondown', 'event_lbuttonup', 'event_mbuttondblclk', 'event_mbuttondown', 'event_mbuttonup',
'event_mousehwheel', 'event_mousemove', 'event_mousewheel', 'event_rbuttondblclk', 'event_rbuttondown', 'event_rbuttonup']
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time : 2016/11/14 9:42
# @author : retacn
# @site :
處理滑鼠事件
,雙擊畫圓
# @file : mousedraw.py
# @software: pycharm
importcv2
importnumpyas
np
#events=[i for i in dir(cv2) if 'event' in i]
#print(events)
#滑鼠事件**函式
defdraw_circle(event,x,y,flags,param):
ifevent==cv2.event_lbuttondblclk:
cv2.circle(img,(x,y),100,(255,0,0),-1)
#建立影象與視窗
#將視窗和**函式邦定
img=np.zeros((512,512,3),np.uint8)
cv2.namedwindow("mouse_draw")
cv2.setmousecallback("mouse_draw",draw_circle)
while(1):
cv2.imshow("mouse_draw",img)
ifcv2.waitkey(20)&0xff==27:
break;
cv2.destroyallwindows()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time : 2016/11/14 9:55
# @author : retacn
# @site :
根據選擇在拖動時畫矩形或是畫圓
# @file : mousedraw2.py
# @software: pycharm
importcv2
importnumpyas
np
# 當滑鼠按下的為
true
drawing =false
#
如果mode
為true
繪製矩形,按下
m繪製曲線
mode =true
lx, ly = -1, -1
# **函式
defdraw_circle(event, x, y, flags,
param):
globallx, ly, drawing, mode
# 當按下左健時返回起始位置座標
if
event == cv2.event_lbuttondown:
drawing =true
lx, ly = x, y
# 當左健按下並移動是繪製圖形
,event(
移動),flag(
是否按下
)elif
event == cv2.event_mousemoveand
flags == cv2.event_flag_lbutton:
ifdrawing ==true:
ifmode ==true:
cv2.rectangle(img, (lx, ly), (x, y), (0,
255, 0), -1)
else:
# 繪製圓
cv2.circle(img, (x, y),
3, (0,
0, 255), -1)
# 當滑鼠放開停止
elif
event == cv2.event_lbuttonup:
drawing =false
img = np.zeros((512, 512, 3), np.uint8)
cv2.namedwindow("mouse_draw2")
cv2.setmousecallback('mouse_draw2', draw_circle)
while(1):
cv2.imshow('mouse_draw2', img)
k = cv2.waitkey(1) & 0xff
if
k == ord('m'):
mode =notmode
elifk == 27:
break
opencv python學習筆記八
十 影象上的算術運算 常用運算有 加法 減法 位運算 cv2.add cv2.addweighted 函式原型 defadd src1,src2,dst none,mask none,dtype none defaddweighted src1,第乙個原陣列 alpha,第乙個原陣列的權值 src2...
opencv python學習筆記十一
14 幾何變換 移動,旋轉 仿射變換 常用函式 cv2.getperspectivetransform 函式原型 defgetperspectivetransform src,dst cv2.warpaffine 函式原型,接收 2 3的矩陣 defwarpaffine src,輸入源影象 m,透視...
OpenCV python學習筆記 二
不多說,上 全在裡面 coding utf 8 import numpy as np import cv2 目標 獲取畫素值並修改 獲取影象的資訊 影象的rio 圖象通道的拆分及合併 step1 獲取影象的資訊 讀取 讀入彩色圖和灰度圖 獲取資訊 影象的資訊包括 行 列 通道 影象資料型別 畫素數目...