zoukankan      html  css  js  c++  java
  • Python 键盘和鼠标事件

    #!/usr/bin/env python
    # !_*_ coding:utf-8 _*_
    
    import os
    import cv2 as cv
    import numpy as np
    import sys
    
    
    def keyboard_demo():
        continue_flag = True
        single_flag = False
        while True:
            while continue_flag:
                mouse_demo()
                for filename in dir_list:
                    path = os.path.join('imgs', filename)
                    # print(path)
                    image = cv.imread(path)
                    cv.imshow("Contuinue", image)
                    key = cv.waitKey(500)
                    if key == ord('s'):
                        continue_flag = False
                        single_flag = True
                        cv.destroyAllWindows()
                        break
                    if key & 0xFF == 27:
                        sys.exit()
            while single_flag:
                for filename in dir_list:
                    path = os.path.join('imgs', filename)
                    # print(path)
                    image = cv.imread(path)
                    cv.imshow("Single", image)
                    key = cv.waitKey(0)
                    if key == ord('c'):
                        continue_flag = True
                        single_flag = False
                        cv.destroyAllWindows()
                        break
                    if key & 0xFF == 27:
                        sys.exit()
    
    
    def tempstop(event, x, y, flags, para):
        if event == cv.EVENT_LBUTTONDOWN:
            print("stop")
            cv.waitKey(0)
        elif event == cv.EVENT_MOUSEMOVE:
            print("Mouse move")
            cv.waitKey(1000)
    
    
    def mouse_demo():
        cv.namedWindow("Contuinue", cv.WINDOW_AUTOSIZE)
        cv.setMouseCallback("Contuinue", tempstop)
    
    
    if __name__ == '__main__':
        dir_list = os.listdir('./imgs')
        # print(dir_list)
        # mouse_demo()
        keyboard_demo()
    

    照片连续显示,

    鼠标移至图像上面 ,图像暂停

    按 “c” ,图像连续显示,按 “s”,图像单个显示 

     

  • 相关阅读:
    1040 Longest Symmetric String (25)
    1068 Find More Coins (30)
    1045 Favorite Color Stripe (30)
    1008 数组元素循环右移问题 (20)
    1007. 素数对猜想
    1005. 继续(3n+1)猜想 (25)
    1001. 害死人不偿命的(3n+1)猜想 (15)
    递归经典面试题_ 小例
    简单实现_控制台小时钟
    使用Timer组件_实现定时更改窗体颜色
  • 原文地址:https://www.cnblogs.com/xuwenwei/p/15089320.html
Copyright © 2011-2022 走看看