Friday, January 6, 2017

OpenCV Mouse handler Mac Apple

# simple mouse capture demo on video creating image

#notes to myself:
# 1) destroyAllWindows works only if cv2.waitKey(1) placed after destroyAllWindows()
# 2) mouse click in global space cv2!!


#apple trackpad 1 finger left mouse button
# 2 fingers right mouse button. How is that intuitive?

import cv2
import numpy as np


def mouse_capture(event, x, y, flags, param):
    if event==cv2.EVENT_LBUTTONDOWN:
        print 'left mouse button'
    elif event==cv2.EVENT_RBUTTONDOWN:
        print 'right mouse button'
   

vc = cv2.VideoCapture('/Users/dc/videodemos/video_mouse.mov')

ret_code, first_frame = vc.read()

cv2.namedWindow('show_firstFrame')
cv2.setMouseCallback('show_firstFrame', mouse_capture)

print first_frame
while True:
    cv2.imshow('show_firstFrame', first_frame)
    waitKey = cv2.waitKey(10000) & 0xFF
    if waitKey == ord('q'):
        break

cv2.destroyAllWindows()
cv2.waitKey(1)
cv2.waitKey(1)
cv2.waitKey(1)

print 'done'

No comments:

Post a Comment