Basically this is a normal tracking workflow but at the end you extract the centroid of the largest object and Zip it with the image where you want to draw the trajectory. Then I wrote a piece of drawing code in a PythonTransform like so:
import clr
clr.AddReference("OpenCV.Net")
from OpenCV.Net import *
# Accumulators for keeping history
trajectory = None
prevpoint = None
color = Scalar.Rgb(255,0,0)
thickness = 3
@returns(IplImage)
def process(value):
global trajectory, prevpoint
centroid = value.Item1
image = value.Item2
# Initialize trajectory image accumulator if needed
if trajectory is None:
trajectory = IplImage(image.Size, image.Depth, 3)
trajectory.SetZero()
# Draw point or line depending on whether there is a past history
if prevpoint is None:
CV.Circle(trajectory,Point(centroid),thickness,color,-1)
else:
CV.Line(trajectory,Point(prevpoint),Point(centroid),color,thickness)
# Draw trajectory on top of image
output = image.Clone()
mask = IplImage(image.Size, image.Depth, 1)
CV.CvtColor(trajectory,mask,ColorConversion.Bgr2Gray)
CV.Threshold(mask,mask,0,255,ThresholdTypes.Binary)
CV.Copy(trajectory,output,mask)
# Update history for next drawing
prevpoint = centroid
return output
# Reset accumulators
def unload():
global trajectory, prevpoint
trajectory = None
prevpoint = None
Thank you for your informative and swift reply!! I tried the workflow attached and it worked beautifully first time!! I couldn't be happier! Thank you so much, I just edited it to include a csv reader and timestamp and it works perfectly for my application!
--
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+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/b7521080-f26d-4f76-9bfe-2e62ad228138%40googlegroups.com.
This string generates an error: CV.Copy(trajectory,output,mask)
"Assertion failed: src.channels() == dist.channels()in function cvCopy, copy.cpp(576)"--
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+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/dbb7c99d-ff65-4b7b-b6cc-126621e05f15%40googlegroups.com.