OpenCV中cv2.waitKey()相關(guān)

import cv2
img = cv2.imread('C:/Users/WZChan/Desktop/2/image00248_001_crhg.jpg')
cv2.imshow('Beautiful Woman', img)
cv2.waitKey()

cv2.waitKey(parameter)
parameter = NONE & 0表示一直顯示
除此之外表示顯示的毫秒數(shù)

import os
from itertools import cycle
import cv2

filenames = os.listdir('C:/Users/WZChan/Desktop/2/')
img_iter = cycle([cv2.imread(os.sep.join(['C:/Users/WZChan/Desktop/2/', x])) for x in filenames])
key = 0
while key !=27:
    cv2.imshow('Animation', next(img_iter))
    key = cv2.waitKey()
    msg = '{} is pressed.'.format(chr(key) if key < 256 else key)
    print msg

獲取按下鍵盤的鍵值

import os
from itertools import cycle
import cv2

def on_mouse(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        print 'Left button down at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_LBUTTONUP:
        print 'Left button up at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_LBUTTONDBLCLK:
        print 'Left button doule clicked at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_RBUTTONDOWN:
        print 'Right button down at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_RBUTTONUP:
        print 'Right button up at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_RBUTTONDBLCLK:
        print 'Right button doule clicked at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_MBUTTONDOWN:
        print 'Middle button down at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_MBUTTONUP:
        print 'Middle button up at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_MBUTTONDBLCLK:
        print 'Middle button doule clicked at ({}, {})'.format(x, y)
    elif event == cv2.EVENT_MOUSEMOVE:
        print 'Moving at ({}, {})'.format(x, y)

cv2.namedWindow('Animation')
cv2.setMouseCallback('Animation', on_mouse)

filenames = os.listdir('C:/Users/WZChan/Desktop/2/')
img_iter = cycle([cv2.imread(os.sep.join(['C:/Users/WZChan/Desktop/2/', x])) for x in filenames])
key = 0
while key != 27:
    cv2.imshow('Animation', next(img_iter))
    key = cv2.waitKey()
    msg = '{} is pressed.'.format(chr(key) if key < 256 else key)
    print msg

獲取鼠標事件

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容