Compare commits
6 Commits
v2.0-alpha
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
| 904ba30817 | |||
| 21361341f8 | |||
| a273dbd161 | |||
| 0cb9d1e877 | |||
| 8579b26955 | |||
| 7049547815 |
@@ -8,7 +8,7 @@ Designed for contribution to street-level imagery projects like Mapillary or Pan
|
||||
|
||||
__author__ = "Lucas MATHIEU (@campanu)"
|
||||
__license__ = "GPL-3.0-or-later"
|
||||
__version__ = "2.0-alpha10"
|
||||
__version__ = "2.0-alpha12"
|
||||
__maintainer__ = "Lucas MATHIEU (@campanu)"
|
||||
__email__ = "campanu@luc-geo.fr"
|
||||
|
||||
@@ -94,6 +94,7 @@ def video_metadata_reader(video_path: str):
|
||||
video_md['width'] = video.get(cv2.CAP_PROP_FRAME_WIDTH)
|
||||
video_md['height'] = video.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
||||
video_md['frame_number'] = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
||||
video = None
|
||||
|
||||
return video_md
|
||||
|
||||
@@ -273,20 +274,20 @@ try:
|
||||
raise ValueError
|
||||
else:
|
||||
frame_sampling = float(setting_toml['process_settings']['frame_sampling'])
|
||||
print("> {}".format(locale_toml['ui']['toml_setting']['classic_mode'].format(frame_sampling)))
|
||||
|
||||
if min_frame_samp <= frame_sampling <= max_frame_samp:
|
||||
video_start_datetime_obj = setting_toml['video']['start_datetime']
|
||||
print("> {}".format(locale_toml['ui']['toml_setting']['classic_mode'].format(frame_sampling)))
|
||||
else:
|
||||
raise ValueError
|
||||
|
||||
video_start_datetime_obj = setting_toml['video']['start_datetime']
|
||||
video_rec_timezone = str(setting_toml['video']['rec_timezone'])
|
||||
|
||||
if 'time_offset' in setting_toml['process_settings']:
|
||||
time_offset = setting_toml['process_settings']['time_offset']
|
||||
|
||||
if time_offset != 0:
|
||||
if min_time_offset >= time_offset >= max_time_offset:
|
||||
if min_time_offset <= time_offset <= max_time_offset:
|
||||
time_offset = float(time_offset)
|
||||
else:
|
||||
raise ValueError
|
||||
@@ -371,13 +372,14 @@ try:
|
||||
timelapse = input(locale_toml['ui']['parameters']['timelapse'].format(user_agree, user_disagree)).upper()
|
||||
|
||||
if timelapse == user_agree:
|
||||
timelapse = True
|
||||
|
||||
# Timelapse framerate parameter
|
||||
while True:
|
||||
try:
|
||||
timelapse_fps = int(input(locale_toml['ui']['parameters']['timelapse_fps'].format(min_timelapse_fps,
|
||||
max_timelapse_fps)))
|
||||
if max_timelapse_fps >= timelapse_fps >= min_timelapse_fps:
|
||||
frame_sampling = float(1 / timelapse_fps)
|
||||
break
|
||||
else:
|
||||
print('\n{}'.format(locale_toml['ui']['parameters']['timelapse_fps_err'].format(min_timelapse_fps,
|
||||
@@ -386,7 +388,6 @@ try:
|
||||
except ValueError:
|
||||
print('\n{}'.format(locale_toml['ui']['parameters']['timelapse_fps_err'].format(min_timelapse_fps, max_timelapse_fps)))
|
||||
True
|
||||
|
||||
else:
|
||||
# Frame sampling parameter
|
||||
while True:
|
||||
@@ -487,24 +488,25 @@ try:
|
||||
|
||||
i = 0
|
||||
|
||||
if timelapse == user_agree:
|
||||
frame_interval = frame_sampling / video_fps
|
||||
if timelapse == True:
|
||||
frame_sampling = float(1 / video_fps)
|
||||
frame_interval = float(1 / timelapse_fps)
|
||||
else:
|
||||
frame_interval = frame_sampling
|
||||
|
||||
cv2_tqdm_unit = locale_toml['ui']['unit']['cv2_tqdm']
|
||||
cv2_tqdm_range = int(video_duration / frame_interval)
|
||||
cv2_tqdm_range = int(video_duration / frame_sampling)
|
||||
|
||||
for i in tqdm(range(cv2_tqdm_range), unit=cv2_tqdm_unit):
|
||||
t = frame_interval * i * 1000
|
||||
t = frame_sampling * i * 1000
|
||||
video.set(cv2.CAP_PROP_POS_MSEC, t)
|
||||
ret, frame = video.read()
|
||||
|
||||
# Image resizing
|
||||
if frame_height != 0:
|
||||
resize_factor = video_height / frame_height
|
||||
if frame_height != video_height:
|
||||
resize_factor = frame_height / video_height
|
||||
image_height = frame_height
|
||||
image_width = int(round(video_height * resize_factor, 0))
|
||||
image_width = int(round(video_width * resize_factor, 0))
|
||||
|
||||
frame = cv2.resize(frame, (image_width, image_height), interpolation=cv2.INTER_LANCZOS4)
|
||||
|
||||
@@ -512,10 +514,10 @@ try:
|
||||
image_name = "{}_f{}.jpg".format(video_file_name.split('.')[0], frame_name)
|
||||
image_path = "{}/{}".format(output_folder, image_name)
|
||||
|
||||
cv2.imwrite(image_path, frame, [cv2.IMWRITE_JPEG_QUALITY, 88, cv2.IMWRITE_JPEG_PROGRESSIVE, 1, cv2.IMWRITE_JPEG_SAMPLING_FACTOR, 0x411111])
|
||||
cv2.imwrite(image_path, frame, [cv2.IMWRITE_JPEG_QUALITY, 88, cv2.IMWRITE_JPEG_PROGRESSIVE, 1, cv2.IMWRITE_JPEG_SAMPLING_FACTOR, 0x221111])
|
||||
|
||||
# Time tags formatting
|
||||
time_shift = i * frame_sampling
|
||||
time_shift = i * frame_interval
|
||||
current_datetime_obj = video_start_datetime_obj + timedelta(seconds=time_shift)
|
||||
current_datetime = current_datetime_obj.strftime('%Y:%m:%d %H:%M:%S')
|
||||
current_subsec_time = int(int(current_datetime_obj.strftime('%f')) / 1000)
|
||||
@@ -533,12 +535,10 @@ try:
|
||||
|
||||
exif_tags = {
|
||||
piexif.ExifIFD.DateTimeOriginal: current_datetime,
|
||||
piexif.ExifIFD.SubSecTimeOriginal: str(current_subsec_time),
|
||||
piexif.ExifIFD.OffsetTimeOriginal: video_rec_timezone
|
||||
}
|
||||
|
||||
if current_subsec_time > 0:
|
||||
exif_tags[piexif.ExifIFD.SubSecTime] = str(current_subsec_time)
|
||||
|
||||
image_exif['0th'] = image_tags
|
||||
image_exif['Exif'] = exif_tags
|
||||
|
||||
|
||||
Reference in New Issue
Block a user