New user - video triggered recording

1,504 views
Skip to first unread message

Charles Latchoumane

unread,
Apr 27, 2015, 4:38:13 AM4/27/15
to bonsai...@googlegroups.com
hi all,

Sorry about the new questions. I have been playing around with Bonsai for about 2 days now. I can acquire and write from camera, trigger arduino digital pin out from key stroke, but i cant seem to find a node that would gate the video recording the way i want.

Trigger could be a arduino digital in or a keystroke verified by equal node, i would like to start acquisition and use the ttl or key stroke to start saving video to file and simultaneously send a ttl through arduino for synchronizing my recording with the open ephys recording gui.

I am only asking about how to integrate the keystroke/ttl in to start the writing? Sorry again if my question seem stupid.

Charles

goncaloclopes

unread,
Apr 27, 2015, 3:53:45 PM4/27/15
to bonsai...@googlegroups.com
Hi Charles,

Welcome to the Bonsai forums!
I believe you may be looking for the TriggeredWindow node. This node allows you to chop a data sequence into segments aligned on arbitrary events (i.e. keystroke/arduino input). You can then use SelectMany to start and stop recordings for each of these events.

This example is actually described in more detail in the Bonsai paper (figure 3E):

However, for precise electrophysiology alignment I would follow a slightly different strategy. Basically, the problem is that there is a non-negligible time between the keystroke, the command being received by the Arduino and the TTL turning on (> 1ms).

To have a more precise alignment point, I would add an LED coupled to the TTL sync pulse in a place where the camera can see it. Then using Bonsai I would Crop out the section of the image around this LED, Sum the values of all the pixels in the ROI and set a Condition with GreaterThan to detect when the sync pulse is actually triggered. This I would then send as the second input to TriggeredWindow.

In this way, you can capture in the camera image the precise moment where the TTL pulse comes on, as best as you can possibly detect with the camera and the start of your video will be precisely aligned to this moment.

Hope this helps, but let us know if you have further questions!
Best,
Gonçalo

Charles Latchoumane

unread,
Apr 27, 2015, 9:52:49 PM4/27/15
to bonsai...@googlegroups.com
THnak you so much for your comments.

I got a workflow that seems to do what I want now but it was as trivial as I expected. However I do think that Bonsai is really well made and not it makes more sense to me.

I would like to share my design so that anybody could use it, and maybe you could bring some improvements to it.

My issues were:
1. when we focus (crop) on the LED turning on and perform the sum followed by greater, that sequence is continuous and generate many triggers for the triggeredwindow node. As a result many pieces of videos are produced.
2. I then needed a way to generate a trigger only when the "greater than node" produced a change (slope) that was using the node "distinc until changed"
3. I needed to have that change trigger only following me pushing the button to turn the LED light, that is combining the LED ON (arduino digitalOUtput node) and the response from greaterthan node after distinct. The first sequence should be arduino output (we turn on), and gated by greater than sensing a change in LED

So far it works for me, and this method gates all input triggering windows without my will (apparently arduino outputs some trigger related to the connection PC host and board just as the connection is established).

Thanks again for your help. 
Koreign
KeyStroke_trigger_Arduino_Video.bonsai
Keystroke_arduinoVideo.bmp

goncaloclopes

unread,
Apr 27, 2015, 10:24:16 PM4/27/15
to bonsai...@googlegroups.com
I'm really sorry that I didn't explain well enough the Condition node and made this more difficult than it needed to be!

Condition is a special type of nested workflow that you can create when you group multiple nodes together using the right-click context menu. Different from the NestedWorkflow and SelectMany nodes, Condition uses the nested workflow to define a boolean flag for each data item that determines whether each value is allowed to pass or not.

In other words, Condition is essentially a filter on the data, and you can select using the nested workflow which values from the continuous stream you want to allow and which ones you want to drop, exactly what you needed! So in your case you could just group the GreaterThan node inside a Condition and it should work as intended. For every value the Condition will evaluate the GreaterThan node and when it returns true, it will send the value as output; if it is false, it will drop the value.

You can find some examples in the crash course video:

Nevertheless, your alternative solution was really clever and it looks like you learned a lot about Bonsai in the process, so don't worry because everything you learned from this example will be useful in the future!

Also thanks for going through the reasoning process. One of the challenges with Bonsai is also with improving how to explain to new users how the framework actually works so this kind of feedback is always useful.

Hope you can get your setup working and let me know if you have further questions.
Cheers,
Gonçalo

Charles Latchoumane

unread,
Apr 29, 2015, 8:33:37 PM4/29/15
to bonsai...@googlegroups.com
HI, 

  I see, well yeah the condition node didn't have much documentation and it is less intuitive than nestedworkflow, since we cannot see the implicit process that takes care of the input (or can we ?). I will rework my workflow with condition definitively

  Another problem I had with my workflow is that it would generate a piece of movie (from the start) and one after I ended my actual recording. I guess I need to add somekind of condition here too for the writing of the movie.

  Thanks a lot for the advises~

Koreign

Gonçalo Lopes

unread,
Apr 30, 2015, 8:03:02 AM4/30/15
to bonsai...@googlegroups.com
By "seeing the implicit process" do you mean visualizing the state of the nodes inside Condition? If so, you can actually do this by opening the condition and double-clicking on any node inside.

You can open the Condition by double-clicking on it while the workflow is stopped. If it is running, double-clicking will visualize the output of the condition node itself, but you can still force opening of the nested editor by Control+double-click or Control-Enter, or simply right-clicking on the node and choosing the "Show Default Editor" option (this is general for all nested nodes by the way).

Regarding the generation of the movie, if you want to ignore the first chunk (before the key is pressed) you can simply add a Skip(1) node after the TriggeredWindow. You can think of TriggeredWindow as splitting the input data stream into chunks (the windows) aligned on the secondary input events. Since it doesn't drop any data, it immediately creates one of these chunks when the stream starts, and then keeps splitting whenever a new event arrives. If you Skip the first chunk, you will get rid of the first clip.

Hope this helps,
G


--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
Visit this group at http://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/4da7707b-bc29-40a7-a418-4c14d844c57f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages