|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Mon Oct 2 19:37:56 2017
|
|
|
|
@author: Rémi
|
|
|
|
liste des touches:
|
|
'q' --> quitter
|
|
'a' --> accelerer la video
|
|
'r' --> ralentir la video
|
|
"fleche gauche" --> stopper ou faire reculer la video
|
|
"fleche droite" --> sopper ou faire avancer la video
|
|
"""
|
|
|
|
import numpy as np
|
|
import cv2
|
|
import time
|
|
|
|
|
|
print("Entrez le nom de la video")
|
|
video = input("exemple : clip4.avi \n")
|
|
vertical = int (input("Diviser la video en combien de zones verticales ? "))
|
|
horizontal = int(input("Diviser la video en combien de zones horizontales ? "))
|
|
|
|
print("\nListe des touches :\nq --> quitter\na --> accelerer la video\nr --> ralentir la video")
|
|
print("fleche gauche --> stopper ou faire reculer la video\nfleche droite --> sopper ou faire avancer la video")
|
|
|
|
vitesse = 0
|
|
cap = cv2.VideoCapture(video)
|
|
ret,frame = cap.read()
|
|
imager = 1
|
|
while(cap.isOpened() and cap.get(1)<cap.get(7)):
|
|
#arret au debut et a la fin
|
|
if (imager == -1 and cap.get(1) == 0):
|
|
imager = 0
|
|
if (imager == 1 and cap.get(1) == cap.get(7) -1):
|
|
imager = 0
|
|
|
|
# avancer
|
|
if (imager == 1):
|
|
ret = cap.set(1,cap.get(1)+1)
|
|
else:
|
|
# reculer
|
|
if (imager == -1):
|
|
ret = cap.set(1,cap.get(1)-1)
|
|
#sinon arret
|
|
|
|
ret,frame = cap.retrieve(frame)
|
|
time.sleep(vitesse)
|
|
|
|
font = cv2.FONT_HERSHEY_SIMPLEX
|
|
buf1 = int(np.shape(frame)[1]/vertical)
|
|
buf2 = int(np.shape(frame)[0]/horizontal)
|
|
|
|
for a in range (1,vertical):
|
|
cv2.line(frame, (buf1 * a, 0), (buf1 * a, np.shape(frame)[0]), (0,0,250), 4)
|
|
for b in range (1, horizontal):
|
|
cv2.line(frame, (0, buf2 * b), (np.shape(frame)[1],buf2 * b), (0,0,250), 4)
|
|
|
|
compteur = 1
|
|
for x in range(1,vertical + 1):
|
|
for y in range(1,horizontal + 1):
|
|
cv2.putText(frame,str(compteur),(buf1 * x - 20,buf2 * y - 5), font, 1,(155,155,155),2,cv2.LINE_AA)
|
|
compteur = compteur + 1
|
|
|
|
cv2.imshow('frame',frame)
|
|
|
|
touche = cv2.waitKey(1)
|
|
if touche & 0xFF == ord('q'):
|
|
break
|
|
#fleche gauche
|
|
if touche == 2424832:
|
|
if (imager == 1):
|
|
imager = 0
|
|
else:
|
|
if (imager == 0):
|
|
imager = -1
|
|
#fleche droite
|
|
if touche == 2555904:
|
|
if (imager == -1):
|
|
imager = 0
|
|
else:
|
|
if (imager == 0):
|
|
imager = 1
|
|
#accelerer
|
|
if (touche == ord('a')):
|
|
if (vitesse >0):
|
|
vitesse -=0.002
|
|
#ralentir
|
|
if (touche == ord('r')):
|
|
vitesse +=0.002
|
|
|
|
|
|
cap.release()
|
|
cv2.destroyAllWindows()
|