gphoto frame capture added back
This commit is contained in:
parent
d8cc388279
commit
fb842cdb69
114
frame_opencv.py
114
frame_opencv.py
|
@ -102,6 +102,8 @@ else:
|
||||||
camera_current_settings = {}
|
camera_current_settings = {}
|
||||||
|
|
||||||
def apply_cam_setting(cam_settings:dict, to_set:list=None):
|
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'
|
cmd = 'v4l2-ctl -d /dev/video0'
|
||||||
args = []
|
args = []
|
||||||
for setting in cam_settings:
|
for setting in cam_settings:
|
||||||
|
@ -295,6 +297,13 @@ def get_last_frame(folder:str):
|
||||||
# Get last file
|
# Get last file
|
||||||
# Filename pattern is A.0001.JPG
|
# Filename pattern is A.0001.JPG
|
||||||
return existing_animation_files[-1].split('.')
|
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):
|
def get_onionskin_frame(folder:str, index=None):
|
||||||
|
@ -462,14 +471,15 @@ def main(args):
|
||||||
|
|
||||||
global onionskin, liveview_only, playback, loop_playback, playhead, index, img_list, first_playback, camera_current_settings
|
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):
|
if not testDevice(0):
|
||||||
print(_("No camera device found. Exiting..."))
|
print(_("No camera device found. Exiting..."))
|
||||||
return 1
|
return 1
|
||||||
cam = cv2.VideoCapture(0)
|
cam = cv2.VideoCapture(0)
|
||||||
cam.set(cv2.CAP_PROP_FRAME_WIDTH, camera_settings['cam_w'])
|
cam.set(cv2.CAP_PROP_FRAME_WIDTH, camera_settings['cam_w'])
|
||||||
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, camera_settings['cam_h'])
|
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, camera_settings['cam_h'])
|
||||||
else:
|
elif project_settings['cam_type'] == "picam":
|
||||||
# Pi Cam V3 setup
|
# Pi Cam V3 setup
|
||||||
from picamera2 import Picamera2
|
from picamera2 import Picamera2
|
||||||
from libcamera import Transform
|
from libcamera import Transform
|
||||||
|
@ -501,6 +511,19 @@ def main(args):
|
||||||
# ~ 'FrameDurationLimits':(16666,83333,None)
|
# ~ 'FrameDurationLimits':(16666,83333,None)
|
||||||
})
|
})
|
||||||
# ~ cam.stop()
|
# ~ 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)
|
frame = get_onionskin_frame(savepath, index)
|
||||||
|
|
||||||
|
@ -538,37 +561,40 @@ def main(args):
|
||||||
onionskin = True
|
onionskin = True
|
||||||
loop_playback = False
|
loop_playback = False
|
||||||
|
|
||||||
if liveview_only:
|
# If cam is DLSR, we have no liveview/onionskin
|
||||||
# ~ onionskin = False
|
if project_settings['cam_type'] != "dslr":
|
||||||
if project_settings['cam_type'] == "showmewebcam":
|
if liveview_only:
|
||||||
ret, overlay = cam.read()
|
# ~ onionskin = False
|
||||||
if not ret:
|
if project_settings['cam_type'] == "showmewebcam" or project_settings['cam_type'] == "webcam" :
|
||||||
print(_("Failed to grab frame."))
|
ret, overlay = cam.read()
|
||||||
break
|
if not ret:
|
||||||
else:
|
print(_("Failed to grab frame."))
|
||||||
overlay = cam.capture_array("main")
|
break
|
||||||
# Resize preview
|
elif project_settings['cam_type'] == "picam"::
|
||||||
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
overlay = cam.capture_array("main")
|
||||||
cv2.imshow("StopiCV", overlay)
|
# Resize preview
|
||||||
# ~ else:
|
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
||||||
# ~ onionskin = True
|
cv2.imshow("StopiCV", overlay)
|
||||||
|
# ~ else:
|
||||||
if onionskin:
|
# ~ onionskin = True
|
||||||
if project_settings['cam_type'] == "showmewebcam":
|
|
||||||
ret, overlay = cam.read()
|
if project_settings['cam_type'] != "dslr":
|
||||||
if not ret:
|
if onionskin:
|
||||||
print(_("Failed to grab frame."))
|
if project_settings['cam_type'] == "showmewebcam":
|
||||||
break
|
ret, overlay = cam.read()
|
||||||
else:
|
if not ret:
|
||||||
overlay = cam.capture_array("main")
|
print(_("Failed to grab frame."))
|
||||||
og_frame = overlay.copy()
|
break
|
||||||
# Resize preview
|
elif project_settings['cam_type'] == "picam"::
|
||||||
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
overlay = cam.capture_array("main")
|
||||||
# Apply onionskin
|
og_frame = overlay.copy()
|
||||||
alpha = project_settings['onionskin_alpha_default']
|
# Resize preview
|
||||||
beta = (1.0 - alpha)
|
overlay = cv2.resize(overlay, (project_settings['screen_w'], project_settings['screen_h']))
|
||||||
overlay = cv2.addWeighted(frame, alpha, overlay, beta, 0)
|
# Apply onionskin
|
||||||
cv2.imshow("StopiCV", overlay)
|
alpha = project_settings['onionskin_alpha_default']
|
||||||
|
beta = (1.0 - alpha)
|
||||||
|
overlay = cv2.addWeighted(frame, alpha, overlay, beta, 0)
|
||||||
|
cv2.imshow("StopiCV", overlay)
|
||||||
|
|
||||||
if not playback and not onionskin and not liveview_only:
|
if not playback and not onionskin and not liveview_only:
|
||||||
cv2.imshow("StopiCV", frame)
|
cv2.imshow("StopiCV", frame)
|
||||||
|
@ -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'])
|
picam_config["transform"] = Transform(vflip=camera_current_settings['vertical_flip']['default'],hflip=camera_current_settings['horizontal_flip']['default'])
|
||||||
cam.configure(picam_config)
|
cam.configure(picam_config)
|
||||||
cam.start()
|
cam.start()
|
||||||
|
|
||||||
# Key e / keypad *
|
# Key e / keypad *
|
||||||
elif (k%256 == 101) or (k%256 == 42) or (k%256 == 170) :
|
elif (k%256 == 101) or (k%256 == 42) or (k%256 == 170) :
|
||||||
print(_("Export"))
|
print(_("Export"))
|
||||||
|
@ -699,20 +724,27 @@ def main(args):
|
||||||
else:
|
else:
|
||||||
cam.set_controls({'AeFlickerMode': 1, 'AeFlickerPeriod':10000})
|
cam.set_controls({'AeFlickerMode': 1, 'AeFlickerPeriod':10000})
|
||||||
print(camera_current_settings['anti_flicker']['value'])
|
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
|
# SPACE or numpad 0 pressed
|
||||||
elif (k%256 == 32) or (k%256 == 48) or (k%256 == 176):
|
elif (k%256 == 32) or (k%256 == 48) or (k%256 == 176):
|
||||||
print(_("Capture frame"))
|
print(_("Capture frame"))
|
||||||
img_name = return_next_frame_number(get_last_frame(savepath))
|
img_name = return_next_frame_number(get_last_frame(savepath))
|
||||||
img_path = os.path.join(savepath, img_name)
|
img_path = os.path.join(savepath, img_name)
|
||||||
if project_settings['file_extension'] == 'jpg':
|
if project_settings['cam_type'] == 'dslr':
|
||||||
cv2.imwrite(img_path, og_frame, [int(cv2.IMWRITE_JPEG_QUALITY), project_settings['jpg_quality']])
|
# 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:
|
else:
|
||||||
cv2.imwrite(img_path, og_frame)
|
# 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))
|
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'])):
|
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
|
img_list[index] = img_name
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue