How to call Point2f in the python transform

1,956 views
Skip to first unread message

Nacho Sanguinetti

unread,
Mar 2, 2016, 9:24:07 AM3/2/16
to Bonsai Users
So, I just started working with Bonsai for a couple of projects and I'm still in the weeds regarding all the different languages involved (having had Null previous experience with any of them). 

I'm tracking 2 different animals at the same time. They can be in or out of the frame, their choice. So I use their different sizes to choose which one is which and I have the centroids for both animals. The result of this centroids is either a point in the image or a (n. def., n. def.). Now I want to plot online the trajectories of both animals on top of the same image. So I ziped both centroids and the Image and I adapted a python transform written by gonzalo in a different Forum thread. I am able to plot both trajectories BUT I get an artifact with the (n. def., n. def.). In this cases the python script reads the n. def., n.def. as 0,0. I want to script a condition to IF these points out. But I haven't been able to access the actual centroid  Point2f values (Point2f is not callable). I tried looking around but haven't found the right answer. 

I need something of the sort of

If centroid is (n. def., n. def)    or  If centroid is a float
      nothing
else
      track


Probably one of you knows how to solve this silly question.

Best

Nacho


goncaloclopes

unread,
Mar 2, 2016, 10:12:04 AM3/2/16
to Bonsai Users
If I got this problem correctly, maybe something like this script would work?

import clr
clr
.AddReference("OpenCV.Net")
from OpenCV.Net import *
from math import isnan

@returns(Point2f)
def process(value):
 
if isnan(value.X) or isnan(value.Y):
   
# not defined value
   
return Point2f(0,0)
 
else:
   
# defined value
   
return value

Let me know if this is in the direction of what you are looking for.
Cheers,

Nacho Sanguinetti

unread,
Mar 2, 2016, 10:57:58 AM3/2/16
to Bonsai Users
Solved! :) Now i can track a Shrew and a cricket online :)
Reply all
Reply to author
Forward
0 new messages