|
|
|
@ -53,6 +53,7 @@ project_settings_defaults = {
|
|
|
|
|
'export_options' : 'scale=1920:-1,crop=1920:1080:0:102',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# TODO: replace hflip+vflip with flip option
|
|
|
|
|
camera_current_settings_defaults = {
|
|
|
|
|
'cam_w' : 800,
|
|
|
|
|
'cam_h' : 600,
|
|
|
|
@ -104,6 +105,7 @@ class webcam():
|
|
|
|
|
self.overlay = None
|
|
|
|
|
# Original frame for saving
|
|
|
|
|
self.og_frame = None
|
|
|
|
|
self.flip_img = bool(camera_settings['vflip'] or camera_settings['hflip'] )
|
|
|
|
|
self.onionskin = project_settings['onion_skin_onstartup']
|
|
|
|
|
self.onionskin_was_on = self.onionskin
|
|
|
|
|
self.liveview_only = False
|
|
|
|
@ -132,10 +134,12 @@ class webcam():
|
|
|
|
|
if not ret:
|
|
|
|
|
print(_("Failed to grab frame."))
|
|
|
|
|
return False
|
|
|
|
|
# Resize preview to fit screen
|
|
|
|
|
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
|
|
|
|
if self.flip_img:
|
|
|
|
|
overlay = cv2.flip(overlay, -1)
|
|
|
|
|
# Keep original pic in memory
|
|
|
|
|
self.og_frame = overlay.copy()
|
|
|
|
|
# Resize preview to fit screen
|
|
|
|
|
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
|
|
|
|
if self.liveview_only:
|
|
|
|
|
# Don't mix it
|
|
|
|
|
self.frame = overlay
|
|
|
|
@ -212,8 +216,7 @@ class webcam():
|
|
|
|
|
return self.camera_current_settings
|
|
|
|
|
|
|
|
|
|
def flip_image(self):
|
|
|
|
|
self.frame = cv2.flip(self.frame, -1)
|
|
|
|
|
self.og_frame = cv2.flip(self.og_frame, -1)
|
|
|
|
|
self.flip_img = not self.flip_img
|
|
|
|
|
|
|
|
|
|
def focus(self, direction:str='-'):
|
|
|
|
|
self.apply_setting(['lenspos'], 1)
|
|
|
|
@ -329,10 +332,10 @@ class picam():
|
|
|
|
|
# Same as in webcam() class
|
|
|
|
|
def capture_preview(self):
|
|
|
|
|
overlay = self.cam.capture_array("main")
|
|
|
|
|
# Resize preview to fit screen
|
|
|
|
|
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
|
|
|
|
# Keep original pic in memory
|
|
|
|
|
self.og_frame = overlay.copy()
|
|
|
|
|
# Resize preview to fit screen
|
|
|
|
|
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
|
|
|
|
if self.liveview_only:
|
|
|
|
|
# Don't mix it
|
|
|
|
|
self.frame = overlay
|
|
|
|
@ -448,7 +451,7 @@ class dslr():
|
|
|
|
|
self.onionskin_was_on = self.onionskin
|
|
|
|
|
self.liveview_only = False
|
|
|
|
|
self.lenspos = None
|
|
|
|
|
self.flip_img = False
|
|
|
|
|
self.flip_img = bool(camera_settings['vflip'] or camera_settings['hflip'] )
|
|
|
|
|
self.cam_busy = False
|
|
|
|
|
self.camera_current_config = None
|
|
|
|
|
self.cam = self.init_camera()
|
|
|
|
@ -473,7 +476,6 @@ class dslr():
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def find_file_ext(self, gp_name:str, full_path:str):
|
|
|
|
|
# TODO: use re to sub png with jpg ?
|
|
|
|
|
# extract dir path
|
|
|
|
|
dirname = os.path.dirname(full_path)
|
|
|
|
|
# extract filename from path
|
|
|
|
@ -499,7 +501,6 @@ class dslr():
|
|
|
|
|
if self.cam is None:
|
|
|
|
|
self.cam = self.init_camera()
|
|
|
|
|
if not self.cam_busy:
|
|
|
|
|
# CHECK: Should we init and close dslr for each frame ?
|
|
|
|
|
# Check battery level
|
|
|
|
|
battery_level = int(self.check_status_value(self.camera_current_config, 'batterylevel')[:-1])
|
|
|
|
|
if battery_level < 10:
|
|
|
|
@ -532,6 +533,7 @@ class dslr():
|
|
|
|
|
return False
|
|
|
|
|
# Flip image if needed
|
|
|
|
|
if self.flip_img:
|
|
|
|
|
# Re-open filen flip and save
|
|
|
|
|
frm = cv2.imread(img_path)
|
|
|
|
|
frm = cv2.flip(frm, -1)
|
|
|
|
|
cv2.imwrite(img_path, frm)
|
|
|
|
@ -602,7 +604,7 @@ class dslr():
|
|
|
|
|
return status
|
|
|
|
|
|
|
|
|
|
def flip_image(self):
|
|
|
|
|
self.flip_img = True
|
|
|
|
|
self.flip_img = not self.flip_img
|
|
|
|
|
|
|
|
|
|
def focus(self, direction:str='-'):
|
|
|
|
|
if direction == '-':
|
|
|
|
@ -616,7 +618,6 @@ class dslr():
|
|
|
|
|
self.camera_current_config = self.gp.check_result(self.gp.gp_camera_get_config(self.cam))
|
|
|
|
|
for setting in self.camera_current_settings:
|
|
|
|
|
self.camera_current_settings[setting]['value'] = self.camera_current_settings[setting]['default']
|
|
|
|
|
# TODO: use self.apply_setting() instead
|
|
|
|
|
self.apply_gphoto_setting(setting)
|
|
|
|
|
status = self.gp.check_result(self.gp.gp_camera_set_config(self.cam, self.camera_current_config))
|
|
|
|
|
|
|
|
|
@ -800,15 +801,8 @@ def get_frames_list(folder:str):
|
|
|
|
|
def get_frame_by_idx(folder:str, index:int):
|
|
|
|
|
# Refresh file list
|
|
|
|
|
existing_animation_files = get_frames_list(folder)
|
|
|
|
|
# Get last file
|
|
|
|
|
# Filename pattern is A.0001.JPG
|
|
|
|
|
if index and index in range(len(existing_animation_files)):
|
|
|
|
|
frm = cv2.imread(os.path.join(folder, existing_animation_files[index]))
|
|
|
|
|
frm = cv2.resize(frm, (project_settings['screen_w'], project_settings['screen_h']))
|
|
|
|
|
return frm
|
|
|
|
|
else:
|
|
|
|
|
return generate_text_image(_("Image not found."), project_settings['screen_w'], project_settings['screen_h'])
|
|
|
|
|
|
|
|
|
|
return existing_animation_files[index].split('.')
|
|
|
|
|
|
|
|
|
|
def get_last_frame(folder:str):
|
|
|
|
|
# Refresh file list
|
|
|
|
@ -826,8 +820,11 @@ def get_before_last_frame(folder:str):
|
|
|
|
|
return existing_animation_files[-2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_onionskin_frame(folder:str):
|
|
|
|
|
def get_onionskin_frame(folder:str, index:int=-1):
|
|
|
|
|
if index == -1:
|
|
|
|
|
prev_image = get_last_frame(folder)
|
|
|
|
|
else:
|
|
|
|
|
prev_image = get_frame_by_idx(folder, index)
|
|
|
|
|
prev_image = '.'.join(prev_image)
|
|
|
|
|
if os.path.exists(os.path.expanduser(os.path.join(savepath, prev_image))):
|
|
|
|
|
frm = cv2.imread(os.path.join(savepath, prev_image))
|
|
|
|
@ -913,6 +910,18 @@ def batch_rename(folder:str):
|
|
|
|
|
return get_frames_list(folder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def batch_rename_reversed(folder:str, from_index:int=0):
|
|
|
|
|
# initialize counter to 0
|
|
|
|
|
frame_list = get_frames_list(os.path.realpath(folder))
|
|
|
|
|
print(frame_list[from_index:])
|
|
|
|
|
counter = (".%04i." % x for x in count(len(frame_list), -1))
|
|
|
|
|
for i in reversed(frame_list[from_index:]):
|
|
|
|
|
if os.path.exists(os.path.join(folder, i)):
|
|
|
|
|
cnt = next(counter)
|
|
|
|
|
os.rename(os.path.join(folder, i), os.path.join(folder, "{}{}{}".format(project_letter, cnt, project_settings['file_extension'])))
|
|
|
|
|
return get_frames_list(folder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def offset_dictvalues(from_index=0):
|
|
|
|
|
dict_copy = dict(img_list)
|
|
|
|
|
for i in range(from_index, len(dict_copy)):
|
|
|
|
@ -945,6 +954,19 @@ def remove_frame(img_list:list, img_index:int):
|
|
|
|
|
else:
|
|
|
|
|
return img_list, 0, blank_image
|
|
|
|
|
|
|
|
|
|
def insert_frame(img_list:list, frame_name:str, img_index:int):
|
|
|
|
|
if len(img_list) > img_index:
|
|
|
|
|
folder_path = os.path.realpath(savepath)
|
|
|
|
|
# ~ frame_name = img_list[img_index]
|
|
|
|
|
frame_path = os.path.join(folder_path, frame_name)
|
|
|
|
|
# ~ if not os.path.exists(frame_path):
|
|
|
|
|
# ~ return img_list, img_index, blank_image
|
|
|
|
|
print(_("Inserting {}").format(frame_path))
|
|
|
|
|
# rename files and get new list
|
|
|
|
|
img_list = batch_rename_reversed(folder_path, img_index+1)
|
|
|
|
|
return img_list, img_index
|
|
|
|
|
else:
|
|
|
|
|
return img_list, 0
|
|
|
|
|
|
|
|
|
|
def testDevice(source):
|
|
|
|
|
cap = cv2.VideoCapture(source)
|
|
|
|
@ -1155,6 +1177,11 @@ def main(args):
|
|
|
|
|
# SPACE or numpad 0 pressed
|
|
|
|
|
elif (k%256 == 32) or (k%256 == 48) or (k%256 == 176):
|
|
|
|
|
print(_("Capture frame"))
|
|
|
|
|
# ~ img_name = return_next_frame_number(get_last_frame(savepath))
|
|
|
|
|
img_name = return_next_frame_number(img_list[index].split('.'))
|
|
|
|
|
if img_name in img_list:
|
|
|
|
|
insert_frame(img_list, img_name, index)
|
|
|
|
|
else:
|
|
|
|
|
img_name = return_next_frame_number(get_last_frame(savepath))
|
|
|
|
|
img_path = os.path.join(savepath, img_name)
|
|
|
|
|
capture_ok = cam.capture_frame(img_path)
|
|
|
|
@ -1164,9 +1191,8 @@ def main(args):
|
|
|
|
|
if len(img_list) and (img_list[index] == '{letter}.-001.{ext}'.format(letter=project_letter, ext=project_settings['file_extension'])):
|
|
|
|
|
img_list[index] = img_name
|
|
|
|
|
else:
|
|
|
|
|
# Move to last frame
|
|
|
|
|
index = len(img_list)
|
|
|
|
|
cam.frame = get_onionskin_frame(savepath)
|
|
|
|
|
index += 1
|
|
|
|
|
cam.frame = get_onionskin_frame(savepath, index)
|
|
|
|
|
cam.o_frame = cam.frame.copy()
|
|
|
|
|
else:
|
|
|
|
|
print(_("Error during capture. Try again."))
|
|
|
|
|