[v2.0-alpha6] Implementing resizing frame function + modifying max. default video height (16K) + code reordering

This commit is contained in:
2024-06-24 02:47:03 +02:00
parent c64d303fe3
commit 801ca04299

View File

@@ -8,7 +8,7 @@ Designed for contribution to street-level imagery projects like Mapillary or Pan
__author__ = "Lucas MATHIEU (@campanu)" __author__ = "Lucas MATHIEU (@campanu)"
__license__ = "AGPL-3.0-or-later" __license__ = "AGPL-3.0-or-later"
__version__ = "2.0-alpha5" __version__ = "2.0-alpha6"
__maintainer__ = "Lucas MATHIEU (@campanu)" __maintainer__ = "Lucas MATHIEU (@campanu)"
__email__ = "campanu@luc-geo.fr" __email__ = "campanu@luc-geo.fr"
@@ -60,9 +60,13 @@ ini_file_err = False
## Default values ## Default values
locale = 'en_us' locale = 'en_us'
min_frame_samp = 0.5 min_frame_samp = 0.5
max_frame_samp = float(60) max_frame_samp = 60.0
min_timelapse_fps = 1 min_timelapse_fps = 1
max_timelapse_fps = 15 max_timelapse_fps = 15
min_frame_height = 480
max_frame_height = 9000
min_time_offset = -10.0
max_time_offset = 10.0
## Platform-dependent commands ## Platform-dependent commands
if platform.system() == 'Windows': if platform.system() == 'Windows':
@@ -154,6 +158,13 @@ else:
print('{}\n'.format(locale_toml['ui']['paths']['path_err'])) print('{}\n'.format(locale_toml['ui']['paths']['path_err']))
True True
### Video metadatas extraction
video = cv2.VideoCapture(video_path)
video_fps = video.get(cv2.CAP_PROP_FPS)
video_width = video.get(cv2.CAP_PROP_FRAME_WIDTH)
video_height = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
video_total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
### GPS track file ### GPS track file
while True: while True:
try: try:
@@ -195,7 +206,6 @@ else:
else: else:
### Frame sampling parameter ### Frame sampling parameter
while True: while True:
try: try:
frame_sampling = float(input(locale_toml['ui']['parameters']['frame_samp'].format(min_frame_samp, frame_sampling = float(input(locale_toml['ui']['parameters']['frame_samp'].format(min_frame_samp,
@@ -211,8 +221,8 @@ else:
True True
## Frame height parameter ## Frame height parameter
min_frame_height = 480 if video_height <= max_frame_height:
max_frame_height = 6000 max_frame_height = int(round(video_height, 0))
while True: while True:
try: try:
@@ -221,6 +231,8 @@ else:
if max_frame_height >= frame_height >= min_frame_height: if max_frame_height >= frame_height >= min_frame_height:
break break
elif frame_height == 0:
break
else: else:
print(locale_toml['ui']['parameters']['frame_height_err'].format(min_frame_height, max_frame_height)) print(locale_toml['ui']['parameters']['frame_height_err'].format(min_frame_height, max_frame_height))
True True
@@ -242,9 +254,6 @@ else:
video_rec_timezone = input(locale_toml['ui']['parameters']['rec_timezone']) video_rec_timezone = input(locale_toml['ui']['parameters']['rec_timezone'])
### Time offset parameter ### Time offset parameter
min_time_offset = -10.0
max_time_offset = 10.0
while True: while True:
try: try:
time_offset = float(input(locale_toml['ui']['parameters']['time_offset'].format(min_time_offset, max_time_offset))) time_offset = float(input(locale_toml['ui']['parameters']['time_offset'].format(min_time_offset, max_time_offset)))
@@ -258,7 +267,9 @@ else:
print(locale_toml['ui']['parameters']['time_offset_err'].format(min_time_offset, max_time_offset)) print(locale_toml['ui']['parameters']['time_offset_err'].format(min_time_offset, max_time_offset))
True True
### User-defined metadata ## User-defined metadata
print('\n{}'.format(locale_toml['ui']['info']['tags_title']))
make = input(locale_toml['ui']['metadatas']['make']) make = input(locale_toml['ui']['metadatas']['make'])
model = input(locale_toml['ui']['metadatas']['model']) model = input(locale_toml['ui']['metadatas']['model'])
author = input(locale_toml['ui']['metadatas']['author']) author = input(locale_toml['ui']['metadatas']['author'])
@@ -266,12 +277,6 @@ else:
# Video metadatas formatting # Video metadatas formatting
print('\n{}'.format(locale_toml['processing']['reading_metadatas'])) print('\n{}'.format(locale_toml['processing']['reading_metadatas']))
video = cv2.VideoCapture(video_path)
video_fps = video.get(cv2.CAP_PROP_FPS)
video_width = video.get(cv2.CAP_PROP_FRAME_WIDTH)
video_height = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
video_total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
video_file_name = os.path.basename(video_path) video_file_name = os.path.basename(video_path)
video_file_size = byte_multiple(os.stat(video_path).st_size) video_file_size = byte_multiple(os.stat(video_path).st_size)
video_duration = video_total_frames / video_fps video_duration = video_total_frames / video_fps
@@ -310,6 +315,14 @@ for i in tqdm(range(cv2_tqdm_range), unit=cv2_tqdm_unit):
video.set(cv2.CAP_PROP_POS_MSEC, t) video.set(cv2.CAP_PROP_POS_MSEC, t)
ret, frame = video.read() ret, frame = video.read()
### Image resizing
if frame_height != 0:
resize_factor = video_height / frame_height
image_height = frame_height
image_width = int(round(video_height * resize_factor), 0)
frame = cv2.resize(frame, (image_width, image_height), interpolation=cv2.INTER_LANCZOS4)
frame_name = '{:05d}'.format(i) frame_name = '{:05d}'.format(i)
image_name = "{}_f{}.jpg".format(video_file_name.split('.')[0], frame_name) image_name = "{}_f{}.jpg".format(video_file_name.split('.')[0], frame_name)
image_path = "{}/{}".format(output_folder, image_name) image_path = "{}/{}".format(output_folder, image_name)