|
|
|
@ -29,11 +29,15 @@ CameraPort = namedtuple(
|
|
|
|
'CameraPort', ['usbPath', 'devicePath'])
|
|
|
|
'CameraPort', ['usbPath', 'devicePath'])
|
|
|
|
|
|
|
|
|
|
|
|
# Short wrapper to allow use in a ``with`` context
|
|
|
|
# Short wrapper to allow use in a ``with`` context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VideoCaptureCtx():
|
|
|
|
class VideoCaptureCtx():
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.capture_dev = cv2.VideoCapture(*args, **kwargs)
|
|
|
|
self.capture_dev = cv2.VideoCapture(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
def __enter__(self):
|
|
|
|
return self.capture_dev
|
|
|
|
return self.capture_dev
|
|
|
|
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
def __exit__(self, *args):
|
|
|
|
self.capture_dev.release()
|
|
|
|
self.capture_dev.release()
|
|
|
|
|
|
|
|
|
|
|
|
@ -116,13 +120,13 @@ class USBCamPlugin(shepherd.plugin.Plugin):
|
|
|
|
confdef.add_def('stabilise_delay', shconf.IntDef(default=5, minval=1, maxval=30, optional=True,
|
|
|
|
confdef.add_def('stabilise_delay', shconf.IntDef(default=5, minval=1, maxval=30, optional=True,
|
|
|
|
helptext="Number of seconds to wait after starting each camera for exposure and white balance to settle"))
|
|
|
|
helptext="Number of seconds to wait after starting each camera for exposure and white balance to settle"))
|
|
|
|
|
|
|
|
|
|
|
|
array = confdef.add_def('trigger', shconf.TableArrayDef(
|
|
|
|
array = confdef.add_def('trigger', shconf.DictListDef(
|
|
|
|
helptext="Array of triggers that will use all cameras"))
|
|
|
|
helptext="Array of triggers that will use all cameras"))
|
|
|
|
array.add_def('hour', shconf.StringDef())
|
|
|
|
array.add_def('hour', shconf.StringDef())
|
|
|
|
array.add_def('minute', shconf.StringDef())
|
|
|
|
array.add_def('minute', shconf.StringDef())
|
|
|
|
array.add_def('second', shconf.StringDef(default="0", optional=True))
|
|
|
|
array.add_def('second', shconf.StringDef(default="0", optional=True))
|
|
|
|
|
|
|
|
|
|
|
|
camarray = confdef.add_def('camera', shconf.TableArrayDef(
|
|
|
|
camarray = confdef.add_def('camera', shconf.DictListDef(
|
|
|
|
helptext="List of cameras to try and connect to. Multiple ports may be listed, and any not connected will be skipped on each trigger."))
|
|
|
|
helptext="List of cameras to try and connect to. Multiple ports may be listed, and any not connected will be skipped on each trigger."))
|
|
|
|
camarray.add_def('name', shconf.StringDef(default="", optional=False,
|
|
|
|
camarray.add_def('name', shconf.StringDef(default="", optional=False,
|
|
|
|
helptext="Name of camera, appended to filename and added to overlay"))
|
|
|
|
helptext="Name of camera, appended to filename and added to overlay"))
|
|
|
|
@ -150,7 +154,7 @@ class USBCamPlugin(shepherd.plugin.Plugin):
|
|
|
|
|
|
|
|
|
|
|
|
self.gstlock = threading.Lock()
|
|
|
|
self.gstlock = threading.Lock()
|
|
|
|
|
|
|
|
|
|
|
|
if self.config["save_directory"] is "":
|
|
|
|
if self.config["save_directory"] == "":
|
|
|
|
self.save_directory = os.path.join(self.root_dir, "usbcamera")
|
|
|
|
self.save_directory = os.path.join(self.root_dir, "usbcamera")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.save_directory = self.config["save_directory"]
|
|
|
|
self.save_directory = self.config["save_directory"]
|
|
|
|
@ -237,7 +241,7 @@ class USBCamPlugin(shepherd.plugin.Plugin):
|
|
|
|
if self.config["append_id"]:
|
|
|
|
if self.config["append_id"]:
|
|
|
|
image_filename = image_filename + " " + self.id
|
|
|
|
image_filename = image_filename + " " + self.id
|
|
|
|
|
|
|
|
|
|
|
|
if camera_name is not "":
|
|
|
|
if camera_name != "":
|
|
|
|
image_filename = image_filename+" "+camera_name
|
|
|
|
image_filename = image_filename+" "+camera_name
|
|
|
|
image_filename = image_filename + ".jpg"
|
|
|
|
image_filename = image_filename + ".jpg"
|
|
|
|
image_filename = os.path.join(self.save_directory, image_filename)
|
|
|
|
image_filename = os.path.join(self.save_directory, image_filename)
|
|
|
|
@ -252,48 +256,46 @@ class USBCamPlugin(shepherd.plugin.Plugin):
|
|
|
|
|
|
|
|
|
|
|
|
with self.gstlock:
|
|
|
|
with self.gstlock:
|
|
|
|
|
|
|
|
|
|
|
|
#gst_str = ('v4l2src device='+device_path+' ! '
|
|
|
|
# gst_str = ('v4l2src device='+device_path+' ! '
|
|
|
|
# 'videoconvert ! appsink drop=true max-buffers=1 sync=false')
|
|
|
|
# 'videoconvert ! appsink drop=true max-buffers=1 sync=false')
|
|
|
|
|
|
|
|
|
|
|
|
#vidcap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
|
|
|
|
# vidcap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)
|
|
|
|
|
|
|
|
|
|
|
|
fmts = get_capture_formats(device_path)
|
|
|
|
fmts = get_capture_formats(device_path)
|
|
|
|
|
|
|
|
|
|
|
|
with VideoCaptureCtx(device_path, cv2.CAP_V4L2) as vidcap:
|
|
|
|
with VideoCaptureCtx(device_path, cv2.CAP_V4L2) as vidcap:
|
|
|
|
if "MJPG" in fmts:
|
|
|
|
if "MJPG" in fmts:
|
|
|
|
size = get_largest_resolution(fmts["MJPG"])
|
|
|
|
size = get_largest_resolution(fmts["MJPG"])
|
|
|
|
set_camera_format_opencv(vidcap, "MJPG", size[0], size[1])
|
|
|
|
set_camera_format_opencv(vidcap, "MJPG", size[0], size[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# stream only starts after first grab
|
|
|
|
# stream only starts after first grab
|
|
|
|
|
|
|
|
|
|
|
|
print("Starting cam")
|
|
|
|
print("Starting cam")
|
|
|
|
read_flag, frame = vidcap.read()
|
|
|
|
read_flag, frame = vidcap.read()
|
|
|
|
delay_start = time.time()
|
|
|
|
delay_start = time.time()
|
|
|
|
while (time.time() - delay_start) < self.config["stabilise_delay"]:
|
|
|
|
while (time.time() - delay_start) < self.config["stabilise_delay"]:
|
|
|
|
vidcap.grab()
|
|
|
|
vidcap.grab()
|
|
|
|
#time.sleep(self.config["stabilise_delay"])
|
|
|
|
# time.sleep(self.config["stabilise_delay"])
|
|
|
|
# clear old buffer
|
|
|
|
# clear old buffer
|
|
|
|
#print("Flushing capture")
|
|
|
|
# print("Flushing capture")
|
|
|
|
#vidcap.grab()
|
|
|
|
# vidcap.grab()
|
|
|
|
print("Reading")
|
|
|
|
print("Reading")
|
|
|
|
read_flag, frame = vidcap.read()
|
|
|
|
read_flag, frame = vidcap.read()
|
|
|
|
#print("Changing to YUYV")
|
|
|
|
# print("Changing to YUYV")
|
|
|
|
#if "YUYV" in fmts:
|
|
|
|
# if "YUYV" in fmts:
|
|
|
|
# size = get_largest_resolution(fmts["YUYV"])
|
|
|
|
# size = get_largest_resolution(fmts["YUYV"])
|
|
|
|
# set_camera_format_opencv(vidcap, "YUYV", size[0], size[1])
|
|
|
|
# set_camera_format_opencv(vidcap, "YUYV", size[0], size[1])
|
|
|
|
#print("Reading again")
|
|
|
|
# print("Reading again")
|
|
|
|
#read_flag, frame2 = vidcap.read()
|
|
|
|
# read_flag, frame2 = vidcap.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if read_flag:
|
|
|
|
if read_flag:
|
|
|
|
self._process_image(frame, camera_name)
|
|
|
|
self._process_image(frame, camera_name)
|
|
|
|
#self._process_image(frame2, camera_name+"(2)")
|
|
|
|
# self._process_image(frame2, camera_name+"(2)")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Could not read camera "+camera_name +
|
|
|
|
print("Could not read camera "+camera_name +
|
|
|
|
" on USB port "+device_path)
|
|
|
|
" on USB port "+device_path)
|
|
|
|
|
|
|
|
|
|
|
|
def run_cameras(self, name_suffix = ""):
|
|
|
|
def run_cameras(self, name_suffix=""):
|
|
|
|
connected_cams = OrderedDict(get_connected_cameras())
|
|
|
|
connected_cams = OrderedDict(get_connected_cameras())
|
|
|
|
|
|
|
|
|
|
|
|
for defined_name, defined_usb_path in self.defined_cams.items():
|
|
|
|
for defined_name, defined_usb_path in self.defined_cams.items():
|
|
|
|
@ -317,7 +319,7 @@ class USBCamPlugin(shepherd.plugin.Plugin):
|
|
|
|
|
|
|
|
|
|
|
|
def camera_job(self):
|
|
|
|
def camera_job(self):
|
|
|
|
self.hooks.pre_cam()
|
|
|
|
self.hooks.pre_cam()
|
|
|
|
self.run_cameras()
|
|
|
|
self.run_cameras()
|
|
|
|
self.hooks.post_cam()
|
|
|
|
self.hooks.post_cam()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|