Video_Digital - KravitzLab/KreedLabWiki GitHub Wiki

Below is code on how to create video clips with behavioral timestamps noted in a strip plot. In this example, a tumble feeder is flashing a blue LED when a mouse touches the feed bars. This code will take a large video file (multiple hours) and create small clips around each blue flash, and add a strip plot to the top to reflect timing of blue flashes. Click HERE for a full .py file of this code, broken into steps.

This is an example of the final video:

Step 1: ROI Setup

This section of code allows you to move your ROI within your video. The purpose of this was to limit the search for blue light flashes to the LED only. When you run this code on your video, it will produce a .jpg file showing your ROI as a red square. Change the values in the CONFIGURATION section until you are only capturing your visual trigger in the ROI.
image
image

Clip making

Once your ROI is set, copy and paste the values into this section of code. This code takes your larger video and creates smaller clips when the trigger is detected. Depending on the size of your video, this part can take a long time. Again, this code can be changed to create clips based on other inputs.

image

Blue light timestamp getter

Once you have clips made and you have selected a specific clip, you can run this code on it. This section of code will store the timestamps of your specific trigger. The purpose of this is to allow you to crop and edit your video after, and still have timestamps available for graphing. If you wanted to crop your trigger out of your video, run this code to save the timestamps of when they occur, and then clip the video using other software before appending the pulse graph.

Create graph based on timestamps and append to video

This is the final section of code, which is used to create a graph on top of your video, showing different parameters of your trigger. Here I am using it to show touches and meals. Touches are the raw trigger timestamps, while meals are classified based on the timepoints of those touches. This graph can be modified to show any data and allows for a lot of customization.

image