Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading, time
- import cv2
- import queue
- capFile = cv2.VideoCapture("f:\\roadtrip\\Roadtrip_01_720p.mp4 ")
- input_buffer = queue.Queue(20)
- fps = capFile.get(cv2.CAP_PROP_FPS)
- time_frame = 1 / fps
- stopped = False
- finished = False
- window_name = 'Video File'
- def clickListener(event, x, y, flags, param):
- global stopped
- if event==cv2.EVENT_LBUTTONUP:
- print("Stop/Resume video")
- stopped = not stopped
- def readFile():
- global finished
- while not finished:
- ret, frame = capFile.read()
- if not ret:
- finished = True
- while not finished:
- try:
- input_buffer.put(frame, timeout=1)
- break
- except queue.Full:
- pass
- def processingFile():
- cv2.namedWindow(window_name)
- cv2.setMouseCallback(window_name, clickListener)
- global finished
- while True:
- if not stopped:
- try:
- global frame
- frame = input_buffer.get(timeout=1)
- cv2.imshow(window_name, frame)
- #time.sleep(time_frame)
- except queue.Empty:
- if finished:
- break
- if (cv2.waitKey(1) & 0xFF) == ord('q'):
- finished = True
- break
- tReadFile = threading.Thread(target=readFile)
- tProcessingFile = threading.Thread(target=processingFile)
- tReadFile.start()
- tProcessingFile.start()
- tProcessingFile.join()
- with input_buffer.mutex:
- input_buffer.queue.clear()
- tReadFile.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement