Integrating camera acquisition into pyControl

82 views
Skip to first unread message

João Pedro Junqueira

unread,
May 17, 2022, 10:47:09 PM5/17/22
to pyControl
Hello again everyone,

I currently use the attached python script to do video acquisition and record sync pulses from pyControl through OpenCV and our camera's  Python API.

So I was wondering if I could somehow wrap my script into a function and integrate
it as a module into one of pyControl's. Currently, we always use the Run Experiment tab, so it'd be good if I could set up acquisition and start streaming when the task is loaded, and start recording when I run it.

But since the run experiment module has a thread structure I'm worried I might somehow mess up the program If I just called my camera acquisition as a function somewhere along it.

Thank you for reading,
Joao.
start-acquisition.py

thoma...@neuro.fchampalimaud.org

unread,
May 20, 2022, 10:37:39 AM5/20/22
to pyControl
Hi Joao,

It should work fine to edit run_experiment_tab.py to get it to setup the camera and start and stop recording.  Some operations during experiment setup are multithreaded (connecting to pyboards and loading tasks onto them),  but  most of the code is single threaded - the only multithreaded bits are where  Run_experiment_tab.thread_map() is used to apply a function to multiple setups in parallel. 

I suggest that you edit the  Subjectbox class,  as there is one of these instantiated for each individual hardware setup, and they handle the run start and run stop for that setup.  If you look at the Subject_box.start_task method  you should be able to see how  to access the subject ID, setup ID and run start time, which I guess you will want for specifying the data file name. 

Let me know how you get on.

T

João Pedro Junqueira

unread,
May 26, 2022, 5:13:17 AM5/26/22
to pyControl
Hello!

Thank you for the info! Since I wanted the camera to stream (without recording) when the task was loaded but before the subjectboxes where instantiated,
I ended up placing the camera calls on the Run_experiment class. Maybe I didn't understand the subjectboxes class correctly? But it's fine for now, since
we only use one board at a time. I had to use multithreading for the camera capture, since as far as I know it's always done through while loops, and from
my understanding that would hang the rest of the program functions.

If anyone would like to do this kind of thing, I guess one could edit the bits from my Camera's API and use the rest of it.

Joao
run_experiment_tab.py
multithreadAcquisition.py

thoma...@neuro.fchampalimaud.org

unread,
May 26, 2022, 8:01:04 AM5/26/22
to pyControl
Hi Joao,

Glad to hear you've got something working.  In case you do want to make it work with multiple setups in future, the Subjectbox objects are instantiated in setup_experiment (line 182 in run_experiment_tab.py) so you can put code in them to be run at the time the task is loaded or when it is actually run.

 In future we would like to implement a proper API for letting users run arbitrary python code on the computer which can interact with pycontrol tasks.  Some development work has happened on that here, but we have not got it finished yet.

T
Reply all
Reply to author
Forward
0 new messages