freemocap / skellycam

The camera back-end for the `freemocap` project - or - An easy and efficient way to connect to one or more cameras and record synchronized videos💀📸
GNU Affero General Public License v3.0
19 stars 6 forks source link

[ADD] LSL trigger when recording is started #40

Closed JuliusWelzel closed 11 months ago

JuliusWelzel commented 11 months ago

I have added a simple LSL trigger when recording is started

jonmatthis commented 11 months ago

Cool! Thank you for this, we'll test it out on our end soon, but at first glance this looks nice and simple!

I've never used LSL, but I can imagine a ton of possible uses - thanks again for the contribution :)

philipqueen commented 11 months ago

Hi Julius, thanks for submitting this!

Skellycam was not able to open when I tried just running this after installing pylsl. I'll copy the error message below. On my computer (m1 mac, Monterey), getting it to run requires both brew installing lsl and setting an environment variable. That's fine for users who want the feature, but ideally we don't import pylsl at all if the user doesn't need it.

@jonmatthis might have a better idea on how to do this, but we should have some kind of conditional import of pylsl, potentially also in a try/except block with a good error message about downloading lsl.

jonmatthis commented 11 months ago

@philipqueen I think you forgot the error message

@JuliusWelzel - Thanks again for the work here!

As philip mentioned, I am in the latter phases of a significant overhaul/refactor/re-architecting of the skellycam package - I recently pushed those changes into the skellycam/development branch (there are also bunch of changes in jon/cleanup_UI_functionality that will probably be pulled into development within the next day or two)

Could you give that branch a shot and (a) see if it runs, and (b) try stuffing some LSL stuff in there somewhere?

I think you might could put those triggers you mentioned somewhere like backend.controller.camera_group_manager.start_recording and ...stop_recording? Or maybe in the backend.backend_loop?

I'd just try to stick them where ever you can get them to work and we can shuffle them around later once we've established proof of concept.

In general, try to put your changes any deeper than camera_group_manager - you can go in to camera_group if you absolutely need to, but things get weird and fragile down there - cameras are wild little beests and must be wrangled delicately ✨ 📸 ✨

JuliusWelzel commented 11 months ago

@jonmatthis Sure, I will update the code accordingly. Should I fork the development branch for this?

@philipqueen Could you provide the error message, so I can understand what process failed? Thanks :)

jonmatthis commented 11 months ago

Should I fork the development branch for this?

I think so - just be aware that things might might be kind of weird with the UI (buttons might not work or work properly etc). Should be functional enough for this kind of test though!

if the start/stop record buttons aren't hooked up yet (can't recall if they are... i think they are?) - go ahead and put the LSL stuff in the connect to cameras interaction and we can move it later

I'll try to remember to update when I pull the UI improvement branch into development, but keep an eye out for that merge in the likely event I forget 😅

philipqueen commented 11 months ago

@JuliusWelzel my apologies about that! Here is the error message:

  File "/Users/philipqueen/miniconda3/envs/cam_lsl/bin/skellycam", line 5, in <module>
    from skellycam.__main__ import main
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/__init__.py", line 32, in <module>
    from skellycam.gui.qt.widgets.skelly_cam_config_parameter_tree_widget import SkellyCamParameterTreeWidget
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/gui/qt/widgets/skelly_cam_config_parameter_tree_widget.py", line 9, in <module>
    from skellycam.gui.qt.skelly_cam_widget import SkellyCamWidget
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/gui/qt/skelly_cam_widget.py", line 18, in <module>
    from skellycam.gui.qt.workers.camera_group_thread_worker import CamGroupThreadWorker
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/gui/qt/workers/camera_group_thread_worker.py", line 13, in <module>
    from skellycam.gui.qt.workers.video_save_thread_worker import VideoSaveThreadWorker
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/gui/qt/workers/video_save_thread_worker.py", line 7, in <module>
    from skellycam.opencv.video_recorder.save_synchronized_videos import save_synchronized_videos
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/opencv/video_recorder/save_synchronized_videos.py", line 9, in <module>
    from skellycam.diagnostics.create_diagnostic_plots import create_diagnostic_plots
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/diagnostics/create_diagnostic_plots.py", line 7, in <module>
    from skellycam.diagnostics.plot_framerate_diagnostics import (
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/diagnostics/plot_framerate_diagnostics.py", line 13, in <module>
    from skellycam.opencv.group.camera_group import CameraGroup
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/opencv/group/camera_group.py", line 11, in <module>
    from skellycam.opencv.group.strategies.grouped_process_strategy import (
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/skellycam/opencv/group/strategies/grouped_process_strategy.py", line 3, in <module>
    import pylsl
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/pylsl/__init__.py", line 2, in <module>
    from .pylsl import IRREGULAR_RATE, DEDUCED_TIMESTAMP, FOREVER, cf_float32,\
  File "/Users/philipqueen/miniconda3/envs/cam_lsl/lib/python3.11/site-packages/pylsl/pylsl.py", line 1302, in <module>
    raise RuntimeError(err_msg + "\n " + __dload_msg)
RuntimeError: liblsl library '/usr/local/lib/liblsl.dylib' found but could not be loaded - possible platform/architecture mismatch.

 You can install the LSL library with conda: `conda install -c conda-forge liblsl`
or with homebrew: `brew install labstreaminglayer/tap/lsl`
or otherwise download it from the liblsl releases page assets: https://github.com/sccn/liblsl/releases
On modern MacOS (>= 10.15) it is further necessary to set the DYLD_LIBRARY_PATH environment variable. e.g. `>DYLD_LIBRARY_PATH=/opt/homebrew/lib python path/to/my_lsl_script.py`