-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.py
153 lines (132 loc) · 3.39 KB
/
util.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import yaml
import os
from moviepy.editor import VideoFileClip
from PyQt5 import QtCore
import matplotlib.pyplot as plt
def load_config(path="./config.yml"):
# 加载YAML文件
if not os.path.isfile(path):
print(f"error:你的{path}不存在,请创建,并且这样初始化")
# print("imgs_dir : ")
return 0
else:
with open(path, 'r', encoding='utf-8') as file:
config = yaml.safe_load(file)
return config
from PIL import Image
def split_gif_to_frames(gif_path):
# Open the GIF file
gif = Image.open(gif_path)
frames = []
try:
while True:
# Try to seek to the next frame
gif.seek(gif.tell() + 1)
# Copy the current frame into a new PIL Image object
frame_img = gif.copy()
# Append the PIL Image object to frames list
frames.append(frame_img)
except EOFError:
pass
return frames
def split_mp4_to_frames(mp4_path):
# Open the MP4 file
clip = VideoFileClip(mp4_path)
frames = []
for frame in clip.iter_frames():
# Convert numpy array frame to PIL Image
frame_img = Image.fromarray(frame)
# Append the PIL Image object to frames list
frames.append(frame_img)
return frames
def set_pos(pos,object):
for i in range(len(pos)):
pos[i] = int(pos[i])
object.setGeometry(QtCore.QRect(pos[0],
pos[1],
pos[2],
pos[3]))
def date_scrollation(date):
"""滚动时间month-day,每次往回滚动一天,遵守大小月,闰年,平年,月末
比如输入是2022-02-01,输出是2022-01-31"""
year,month,day = date.split("-")
year = int(year)
month = int(month)
day = int(day)
if month == 1:
if day == 1:
year -= 1
month = 12
day = 31
else:
day -= 1
elif month == 2:
if day == 1:
month -= 1
if year % 4 == 0:
day = 29
else:
day = 28
else:
day -= 1
elif month == 3:
if day == 1:
month -= 1
day = 28
else:
day -= 1
elif month == 4:
if day == 1:
month -= 1
day = 31
else:
day -= 1
elif month == 5:
if day == 1:
month -= 1
day = 30
else:
day -= 1
elif month == 6:
if day == 1:
month -= 1
day = 31
else:
day -= 1
elif month == 7:
if day == 1:
month -= 1
day = 30
else:
day -= 1
elif month == 8:
if day == 1:
month -= 1
day = 31
else:
day -= 1
elif month == 9:
if day == 1:
month -= 1
day = 31
else:
day -= 1
elif month == 10:
if day == 1:
month -= 1
day = 30
else:
day -= 1
elif month == 11:
if day == 1:
month -= 1
day = 31
else:
day -= 1
elif month == 12:
if day == 1:
month -= 1
day = 30
else:
day -= 1
return f"{year}-{month}-{day}"