-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCBVR.py
More file actions
71 lines (59 loc) · 1.84 KB
/
CBVR.py
File metadata and controls
71 lines (59 loc) · 1.84 KB
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
import os
import cv2
import csv
import numpy as np
import time
import peakutils
import matplotlib.pyplot as plt
def print_diff(Array_1, Array_2):
plt.subplot(311)
plt.title('Original', fontsize=10)
ax = plt.gca()
ax.set_facecolor('xkcd:salmon')
plt.plot(Array_1 , 'r')
plt.subplot(312)
plt.title('Base-Line removal',fontsize = 10 )
ax = plt.gca()
ax.set_facecolor('xkcd:sky blue')
plt.plot(Array_2 , 'b')
plt.subplot(313)
plt.title('Diff', fontsize=10)
ax = plt.gca()
ax.set_facecolor('tab:olive')
plt.plot((Array_1 - Array_2), 'g')
def keyframeDetection(source, Thres):
# keyframePath = dest +'/keyFrames'
# if not os.path.exists(keyframePath):
# os.makedirs(keyframePath)
lastdiffMag = []
full_color = []
lastFrame = None
cap = cv2.VideoCapture(source)
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
# Read until video is completed
for i in range(length):
ret, frame = cap.read()
blur = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame_number = cap.get(cv2.CAP_PROP_POS_FRAMES) - 1
full_color.append(frame)
if frame_number == 0:
lastFrame = blur
_diff = cv2.subtract(blur, lastFrame)
diff_Num = cv2.countNonZero(_diff)
lastdiffMag.append(diff_Num)
lastFrame = blur
cap.release()
y = np.array(lastdiffMag)
base = peakutils.baseline(y, 2)
indices = peakutils.indexes(y - base, Thres, min_dist=1)
out = []
cnt = 1
# print_diff(y, base)
for x in indices:
# cv2.imwrite(os.path.join('DataSet/Videos', 'keyframe'+ str(cnt) +'.jpg'), full_color[x])
cnt +=1
out.append(full_color[x])
cv2.destroyAllWindows()
return np.array(out)
# out = keyframeDetection('DataSet/Videos/acrobacia.mp4', 0.5)
# x=0