gphoto frame capture added back
This commit is contained in:
parent
d8cc388279
commit
fb842cdb69
|
@ -102,6 +102,8 @@ else:
|
|||
camera_current_settings = {}
|
||||
|
||||
def apply_cam_setting(cam_settings:dict, to_set:list=None):
|
||||
# TODO: Refactor so that we can call with whatever camera type and setting, and have the work of determining how to apply it done here
|
||||
# This version should probably be kept and renamed construct_v4l2_cmd()
|
||||
cmd = 'v4l2-ctl -d /dev/video0'
|
||||
args = []
|
||||
for setting in cam_settings:
|
||||
|
@ -296,6 +298,13 @@ def get_last_frame(folder:str):
|
|||
# Filename pattern is A.0001.JPG
|
||||
return existing_animation_files[-1].split('.')
|
||||
|
||||
def get_before_last_frame(folder:str):
|
||||
# Refresh file list
|
||||
existing_animation_files = get_frames_list(folder)
|
||||
# Get last file
|
||||
# Filename pattern is A.0001.JPG
|
||||
return existing_animation_files[-2]
|
||||
|
||||
|
||||
def get_onionskin_frame(folder:str, index=None):
|
||||
prev_image = get_last_frame(folder)
|
||||
|
@ -462,14 +471,15 @@ def main(args):
|
|||
|
||||
global onionskin, liveview_only, playback, loop_playback, playhead, index, img_list, first_playback, camera_current_settings
|
||||
|
||||
if not project_settings['cam_type'] == "showmewebcam":
|
||||
# Initialise camera
|
||||
if project_settings['cam_type'] == "showmewebcam" or project_settings['cam_type'] == "webcam" :
|
||||
if not testDevice(0):
|
||||
print(_("No camera device found. Exiting..."))
|
||||
return 1
|
||||
cam = cv2.VideoCapture(0)
|
||||
cam.set(cv2.CAP_PROP_FRAME_WIDTH, camera_settings['cam_w'])
|
||||
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, camera_settings['cam_h'])
|
||||
else:
|
||||
elif project_settings['cam_type'] == "picam":
|
||||
# Pi Cam V3 setup
|
||||
from picamera2 import Picamera2
|
||||
from libcamera import Transform
|
||||
|
@ -501,6 +511,19 @@ def main(args):
|
|||
# ~ 'FrameDurationLimits':(16666,83333,None)
|
||||
})
|
||||
# ~ cam.stop()
|
||||
elif project_settings['cam_type'] == "dslr":
|
||||
camera = gp.check_result(gp.gp_camera_new())
|
||||
try:
|
||||
gp.check_result(gp.gp_camera_init(camera))
|
||||
# get configuration tree
|
||||
current_camera_config = gp.check_result(gp.gp_camera_get_config(camera))
|
||||
apply_camera_settings(camera, current_camera_config)
|
||||
if check_status(camera, current_camera_config) is False:
|
||||
print(_("Warning: Some settings are not set to the recommended value!"))
|
||||
except:
|
||||
camera = False
|
||||
else:
|
||||
print(_("No camera type was defined in config.toml"))
|
||||
|
||||
frame = get_onionskin_frame(savepath, index)
|
||||
|
||||
|
@ -538,14 +561,16 @@ def main(args):
|
|||
onionskin = True
|
||||
loop_playback = False
|
||||
|
||||
# If cam is DLSR, we have no liveview/onionskin
|
||||
if project_settings['cam_type'] != "dslr":
|
||||
if liveview_only:
|
||||
# ~ onionskin = False
|
||||
if project_settings['cam_type'] == "showmewebcam":
|
||||
if project_settings['cam_type'] == "showmewebcam" or project_settings['cam_type'] == "webcam" :
|
||||
ret, overlay = cam.read()
|
||||
if not ret:
|
||||
print(_("Failed to grab frame."))
|
||||
break
|
||||
else:
|
||||
elif project_settings['cam_type'] == "picam"::
|
||||
overlay = cam.capture_array("main")
|
||||
# Resize preview
|
||||
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
||||
|
@ -553,13 +578,14 @@ def main(args):
|
|||
# ~ else:
|
||||
# ~ onionskin = True
|
||||
|
||||
if project_settings['cam_type'] != "dslr":
|
||||
if onionskin:
|
||||
if project_settings['cam_type'] == "showmewebcam":
|
||||
ret, overlay = cam.read()
|
||||
if not ret:
|
||||
print(_("Failed to grab frame."))
|
||||
break
|
||||
else:
|
||||
elif project_settings['cam_type'] == "picam"::
|
||||
overlay = cam.capture_array("main")
|
||||
og_frame = overlay.copy()
|
||||
# Resize preview
|
||||
|
@ -660,7 +686,6 @@ def main(args):
|
|||
picam_config["transform"] = Transform(vflip=camera_current_settings['vertical_flip']['default'],hflip=camera_current_settings['horizontal_flip']['default'])
|
||||
cam.configure(picam_config)
|
||||
cam.start()
|
||||
|
||||
# Key e / keypad *
|
||||
elif (k%256 == 101) or (k%256 == 42) or (k%256 == 170) :
|
||||
print(_("Export"))
|
||||
|
@ -699,20 +724,27 @@ def main(args):
|
|||
else:
|
||||
cam.set_controls({'AeFlickerMode': 1, 'AeFlickerPeriod':10000})
|
||||
print(camera_current_settings['anti_flicker']['value'])
|
||||
# ~ elif (k%256 == 115) and project_settings['cam_type'] == "picam":
|
||||
# ~ # Set AfMode to Manual
|
||||
# ~ cam.set_controls({'AeFlickerMode': 0, 'AeFlickerPeriod': 8333})
|
||||
# Take pic
|
||||
# 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_path = os.path.join(savepath, img_name)
|
||||
if project_settings['cam_type'] == 'dslr':
|
||||
# Get file from DSLR camera
|
||||
new_frame_path = camera.capture(gp.GP_CAPTURE_IMAGE)
|
||||
new_frame = camera.file_get(
|
||||
new_frame_path.folder, new_frame_path.name, gp.GP_FILE_TYPE_NORMAL)
|
||||
print(_("Saving {}{}").format(new_frame_path.folder, new_frame_path.name))
|
||||
new_frame.save(img_path)
|
||||
else:
|
||||
# Cam is either webcam, showmewebcam or picam
|
||||
if project_settings['file_extension'] == 'jpg':
|
||||
cv2.imwrite(img_path, og_frame, [int(cv2.IMWRITE_JPEG_QUALITY), project_settings['jpg_quality']])
|
||||
else:
|
||||
cv2.imwrite(img_path, og_frame)
|
||||
print(_("File {} written.").format(img_path))
|
||||
|
||||
# Special case when we've no frame yet
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue