-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathload.py
41 lines (29 loc) · 1.07 KB
/
load.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
from collections import defaultdict
import os
import shutil
from pathlib import Path
import numpy as np
from skimage import io
import cv2
def load_raw_image_collection(images_dir, target_size=(720, 1080)):
"""
Load images form given folder.
images_dir:
str
Path to the folder with images (frames)
return:
list
List of resized RGB-images
"""
images_list = sorted(x for x in Path(images_dir).iterdir() if x.suffix.lower() in ('.jpg', '.jpeg', '.png'))
_temp = io.imread(images_list[0])
orig_size = (_temp.shape[0], _temp.shape[1])
scale_factor = np.mean([orig_size[0] / target_size[0], orig_size[1] / target_size[1]])
print('Original size (y, x): ', orig_size)
print('Target size (y, x): ', target_size)
print('Scale factor (FOCAL LENGTH is needed to be DIVIDED BY IT):', scale_factor)
image_collection_raw = [
cv2.resize(io.imread(filename), (target_size[1], target_size[0]))
for filename in images_list
]
return image_collection_raw