Hello Bonsai community,
I am new to Bonsai but have enjoyed figuring it out with the great workshop videos and forum posts. However, I ran into a problem that I couldn't resolve but feel like it should be rather trivial. I am using Bonsai together with Arduino to read in two analog inputs. What I want to do is plot the trajectory of a point that uses the analog values as its X and Y coordinates. Basically using analog1 as x value and analog2 as y value of a point that is drawn in a visualizer online. I found a python script that draws the centroid trajectory of a detected object from a video input. But it wants point2f input, which I understand needs floating numbers, and my zip of X/Y is a tuple of doubles. I couldn't figure out how to change the code to work with my input data, or change my datatype to feed into the code.
Thank you in advance for your help!
cheers,
Alice
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