forked from shaiunterslak/videoToSlides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvidToSlides.py
86 lines (70 loc) · 2.06 KB
/
vidToSlides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'''
Created on 12 May 2019
@author: shai
'''
import os
import numpy as np
import cv2
from django.conf.locale import el
from cv2 import imwrite
import sys
def isBlack():
a= []
dif = cv2.imread("tempDif.jpg")
for outter in dif:
for pix in outter:
total = int(pix[0])+int(pix[1])+int(pix[2])
if total<150:
pix[0]=pix[1]=pix[2]=0
new_total = int(pix[0])+int(pix[1])+int(pix[2])
a.append(new_total)
tempMax = 0;
for el in a:
if el>tempMax:
tempMax = el
else:
continue
if(tempMax>0):
return False
else: return True
def isEqual(cur,prev):
difference = cv2.subtract(cur,prev)
cv2.imwrite("tempDif.jpg",difference)
dif = cv2.imread("tempDif.jpg",0)
if(isBlack()):
os.remove("tempDif.jpg")
return True
else:
os.remove("tempDif.jpg")
return False
filename = sys.argv[1]
cap = cv2.VideoCapture(filename)
try:
if not os.path.exists(filename[0:4]):
os.makedirs(filename[0:4])
except OSError:
print("Error")
currentFrame = 0
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
noUnique = 0
while(currentFrame<length):
cap.set(1, currentFrame)
ret, frame = cap.read()
if currentFrame ==0:
firstName = filename[0:4]+'/slide'+str(currentFrame)+'.jpg'
cv2.imwrite(firstName,frame)
else:
nameCur = filename[0:4]+'/slide'+str(currentFrame)+'.jpg'
cv2.imwrite(nameCur,frame)
cur = cv2.imread(nameCur)
namePrev = filename[0:4]+'/slide'+str(currentFrame-500)+'.jpg'
prev = cv2.imread(namePrev)
noSeconds = (currentFrame/25)
noMinutes = round((noSeconds/60),2)
if isEqual(cur,prev):
os.remove(namePrev)
else:
print("Frame number ", currentFrame, "is a new frame that appears about ",noMinutes, " minutes in" )
noUnique +=1
currentFrame +=500
print("There were ", noUnique, "unique frames identified.")