Circular crop and adding mouse click to the timestamp

434 views
Skip to first unread message

Charlotte Christensen

unread,
Jan 7, 2016, 5:38:07 AM1/7/16
to Bonsai Users
Hi everyone, 

I have run in to two challenges on my way to optimizing bonsai for my work. 

First I would like to be able to track an animal in a circular arena, meaning that I need to crop out all corners. Is there anyway that the Crop polygon can make circular crops instead of squares? 

Second I would also like to add a tag in the form of a mouse click both onto the video (like a little mark in the corner indicating that I've clicked) and to the csv position file. It would be great if the csv file could write a separate column indicating the mouse click next to the X,Y coordinate columns. 

I've added my workflow so far.

I'd really appreciate some input.

Best,
Charlotte
SavingVideoStopwatchTracking.bonsai

goncaloclopes

unread,
Jan 7, 2016, 6:03:07 AM1/7/16
to Bonsai Users
Hi Charlotte,

You can define circular regions with CropPolygon by adding more control points to the square. You do this by double-clicking inside the square, close to an edge. A new control point will appear in the edge which you can then move with right-click. If you add enough control points you can approximate a circle. It's a bit tedious, but should work. Maybe I will add an easier way for pre-drawing circles in the future.

As for the mouse-click, you can do this by sampling the current Mouse state with each frame grab. I've modified your workflow to do this. I'm showing the modified part below excluding the timestamp bit and segmentation nodes for simplicity:


Basically the problem is that you want to sample the current mouse state together with the camera. In Bonsai 2.2 you can do this directly using the Mouse source. If you feed it an input, Bonsai will read the current state when the input arrives. Then you just take the state of the left mouse button (or any other button) and Zip it together with the rest of the input.


Hope this makes sense. Let me know if you have any further issues.

SavingVideoStopwatchTracking.bonsai

Charlotte Christensen

unread,
Jan 23, 2016, 12:21:17 PM1/23/16
to Bonsai Users
Hi again,

I have again run into some problems with my tracking setup, and I wonder if you have any suggestions. I've used the polygon crop to create a circular crop (which is a little off on these pictures for some unknown reason), however, when trying to track the rat using the binary region analyses it seems that it tracks the black circle I've created and not the rat inside. Is there anyway to make it exclude the area outside the crop or to make this area black so the only thing that sticks out is the rat? 

I'll add my workflow as well so you can see my settings. 

Another thing I also noticed is that when I try to look into the regions in the polygon crop, the whole image of the video looks really wierd. It's almost like it's been split and mirrored. I really don't understand what's going on there. 


If you have any suggestions on how to make the tracking right, I'll be really greatful.

Thanks a lot,
Charlotte
Bonsai.JPG
VideoStopwatchTrackingCropPolygon.bonsai

goncaloclopes

unread,
Jan 24, 2016, 1:57:30 PM1/24/16
to Bonsai Users
Hi Charlotte,

You can use the FillValue property of CropPolygon to fix this. When you use CropPolygon, pixels outside the region of interest are filled with a pre-specified color, which is black by default. However, in this case you are tracking a dark object, so you probably want to use white rather than black for the FillColor. This should work if you set the FillColor property to something like 255,255,255,0.

Hope this helps!

Charlotte Christensen

unread,
Jan 25, 2016, 2:14:41 AM1/25/16
to Bonsai Users
Thanks a lot, again. 
This seems to have solved the problem. 
Reply all
Reply to author
Forward
0 new messages