OpenCV中cv2.waitKey()相关

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表示一直显示
除此之外表示显示的毫秒数

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

获取鼠标事件

你可能感兴趣的:(OpenCV中cv2.waitKey()相关)