-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_data.py
55 lines (50 loc) · 1.02 KB
/
extract_data.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
# %%
import cv2
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
from moviepy.editor import VideoFileClip
from tqdm import tqdm
import umap
import pickle
# %%
video_path = Path('data/2024-07-23-20-49-52.mp4')
clip = VideoFileClip(str(video_path))
# %%
clip.duration
# %%
frames: list[np.ndarray] = []
times = np.linspace(0, clip.duration, int(clip.duration) * 10)
# %%
for t in tqdm(times):
frame = clip.get_frame(t)
frames.append(frame)
# %%
left = 850
top = 400
width = 224
img = frames[60][top:top+width, left:left+width]
plt.imshow(img)
# %%
data = np.array([
frame[top:top+width, left:left+width]
for frame in tqdm(frames)
])
# %%
for i, frame in zip(times, tqdm(data)):
cv2.imwrite(f'data/frames/{i:07.02f}.jpg', cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
# %%
fit = umap.UMAP()
u = fit.fit_transform(data.reshape(-1, width*width*3))
# %%
plt.scatter(u[:,0], u[:,1])
# %%
tosave = {
'imgs': data,
'u': u,
}
open('chrs.pickle', 'wb').write(pickle.dumps(tosave))
# %%
del fit
# %%
u.shape