-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCE-CSLDataPreProcess.py
More file actions
executable file
·91 lines (74 loc) · 3.02 KB
/
CE-CSLDataPreProcess.py
File metadata and controls
executable file
·91 lines (74 loc) · 3.02 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import random
import os
import numpy as np
import shutil
from tqdm import tqdm
import imageio
import cv2
import csv
import DataProcessMoudle
def seed_torch(seed=0):
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
def main(dataPath, saveDataPath):
fileTypes = sorted(os.listdir(dataPath))
framesList = []
fpsList = []
videoTimeList = []
resolutionList = []
for fileType in fileTypes:
filePath = os.path.join(dataPath, fileType)
saveFilePath = os.path.join(saveDataPath, fileType)
translators = sorted(os.listdir(filePath))
for translator in translators:
translatorPath = os.path.join(filePath, translator)
saveTranslatorPath = os.path.join(saveFilePath, translator)
videos = sorted(os.listdir(translatorPath))
for video in tqdm(videos):
videoPath = os.path.join(translatorPath, video)
nameString = video.split(".")
saveImagePath = os.path.join(saveTranslatorPath, nameString[0])
if not os.path.exists(saveImagePath):
os.makedirs(saveImagePath)
vid = imageio.get_reader(videoPath) # 读取视频
# nframes = vid.get_meta_data()['nframes']
nframes = vid.count_frames()
fps = vid.get_meta_data()['fps']
videoTime = vid.get_meta_data()['duration']
resolution = vid.get_meta_data()['size']
framesList.append(nframes)
fpsList.append(fps)
videoTimeList.append(videoTime)
resolutionList.append(resolution)
for i in range(nframes):
try:
image = vid.get_data(i)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (256, 256))
nameString = str(i)
for i in range(5 - len(nameString)):
nameString = "0" + nameString
imagePath = os.path.join(saveImagePath, nameString + ".jpg")
cv2.imencode('.jpg', image)[1].tofile(imagePath)
except:
print(nframes)
print(videoPath)
vid.close()
maxframeNum = max(framesList)
minframeNum = min(framesList)
maxVideoTime = max(videoTimeList)
minVideoTime = min(videoTimeList)
fpsSet = set(fpsList)
resolutionSet = set(resolutionList)
print(f"Max Frames Number:{maxframeNum}\n"
f"Min Frames Number:{minframeNum}\n"
f"Max Video Time:{maxVideoTime}\n"
f"Min Video Time:{minVideoTime}\n"
f"Fps Set:{fpsSet}\n"
f"Resolution Set:{resolutionSet}\n")
if __name__ == '__main__':
dataPath = "/home/lj/lj/program/python/DataSets/CE-CSL/video"
saveDataPath = "/home/lj/lj/program/python/DataSets/CE-CSL/video2"
seed_torch()
main(dataPath, saveDataPath)