Skip to content

Instantly share code, notes, and snippets.

@sundharvs
Created November 26, 2019 04:50
Show Gist options
  • Save sundharvs/5ceb287dbf4c911997d8181cf73bd34a to your computer and use it in GitHub Desktop.
Save sundharvs/5ceb287dbf4c911997d8181cf73bd34a to your computer and use it in GitHub Desktop.
Reaction Time Physics Project - Sundhar Vinodh Sangeetha, Parth Sharma, Tom Durie, Sid Mane
import cv2
import time
import keyboard
import pygame
videos = [["./CLIPS/1.mp4",28],['./CLIPS/2.mp4',691],['./CLIPS/3.mp4',236], ['./CLIPS/4.mp4',919], ['./CLIPS/5.mp4',390], ['./CLIPS/6.mp4',923]]
def play(vidnumber):
pygame.init()
pygame.joystick.init()
rudder = pygame.joystick.Joystick(0) #change from 1 to 0 on laptop
rudder.init()
cap = cv2.VideoCapture(videos[vidnumber-1][0])
cv2.namedWindow('Driving Sim',cv2.WINDOW_AUTOSIZE)
unpressed = -1
while True:
ret_val, frame = cap.read()
cv2.imshow('Driving Sim', frame)
for event in pygame.event.get():
if event.type == pygame.QUIT:
cv2.destroyAllWindows()
framenumber = cap.get(cv2.CAP_PROP_POS_FRAMES)
totalframes = cap.get(cv2.CAP_PROP_FRAME_COUNT)
if((keyboard.is_pressed('o') or rudder.get_axis(0)>-1) and (unpressed<1)):
if(unpressed == 0):
print(str(framenumber-videos[vidnumber-1][1]))
print("---------")
unpressed += 1
key = cv2.waitKey(16)
if key == 27:
cv2.destroyAllWindows()
break # esc to quit
if key == 32:
vidnumber += 1
play(vidnumber) # press space to change clip
if framenumber == totalframes:
vidnumber += 1
time.sleep(10)
play(vidnumber)
cv2.destroyAllWindows()
if __name__ == '__main__':
play(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment