-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_video.py
executable file
·75 lines (63 loc) · 2.2 KB
/
extract_video.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
import time
import sys
import os
import cv2
import numpy as np
import utm
def getGpsTime(filename):
timestamps = list()
index = list()
file = open('/home/kotei/road/11.29/GPS.txt', 'r')
gps=open('gps.log','w')
for line in file:
lin = line.split()
latitude = lin[1]
longitude = lin[2]
altitude= lin[3]
stat = lin[4]
index.append(lin[5])
timeTemp =2029 * 7* 86400.0 + float(lin[0]) + 315619200.000000
timeTemp = str( "%.6f" % timeTemp)
timestamps.append(timeTemp)
print (timeTemp)
utm_xyz=utm.from_latlon(float(latitude),float(longitude))
gps.write( timeTemp+' '+ str( "%.6f" % utm_xyz[0])+ ' '+ str( "%.6f" % utm_xyz[1])+' '+ altitude+ ' ' + stat +'\n')
gps.flush()
zipped = zip(index, timestamps)
gps = np.array(list(zipped))
return gps
def get(videoName, filename, timeList):
dir = os.path.splitext(videoName)[0]
if not os.path.exists(dir):
os.makedirs(dir)
videoCapture = cv2.VideoCapture(videoName)
fps = videoCapture.get(cv2.CAP_PROP_FPS)
success, frame = videoCapture.read()
count = 0
while success:
# cv2.imshow("Oto Video", frame)
success, frame = videoCapture.read()
cv2.waitKey(100000000)
if (count >= int(timeList[0, 0])):
print(count)
cameraindex = int(timeList[0, 0]) - count
filename = dir + "/" + timeList[cameraindex, 1] + ".png"
cv2.imwrite(filename, frame)
count += 1
print(count)
else:
# print(count)
count += 1
if __name__ == '__main__':
for path, names, files in os.walk(os.getcwd()):
for f in files:
if os.path.splitext(f)[1] in ['.txt']:
fileGps = os.path.join(path, f)
timeList = getGpsTime(fileGps)
video_files = list()
for path, names, files in os.walk(os.getcwd()):
for f in files:
if os.path.splitext(f)[1] in ['.avi', 'mp4']:
video_files.append(os.path.join(path, f))
for file in video_files:
get(file, fileGps, timeList)