ncguilbeault/BonZeb

Error while running multi-animal tracking

aaronsathya opened this issue · 3 comments

Hi @ncguilbeault I am trying to adapt the multi-animal tracking example to track flies in a chamber. When I try to do this, I am getting the following error:

Runtime Error
'List[Array[Point2f]]' object has no attribute 'Item1'

The background subtraction is working really well - I tried running the different parts of the workflows separately and centroids are being generated, however, I think the issue is with the python script node in the SelectMany MultiAnimalTracking node with the following line:

for tail_points in value.Item1:
    tail_points_list = []
    for tail_point in tail_points:
      tail_points_list.append(str(tail_point))
    n_fish_list.append(str(tail_points_list))

There is no Item1 in the output from the the TrackMultipleAnimals SelectMany node within the MultiAnimalTracking SelectMany node. I am wondering how I can just get the centroid data written to the tracking_results.csv file. Thanks a lot for building BonZeb - it is a fantastic tool.

Hi @aaronsathya and thanks for your interest in BonZeb! It's always cool to learn how people are using it to do different things.

I've made an updated version of the workflow and attached it in a zip folder.

The key things that changed:

  • removed the Zip between the background subtracted image and the output of the BinaryRegionAnalysis, since this was only needed for the tail tracking algorithm and not necessary for centroid tracking
  • the output of the BinaryRegionAnalysis node is fed directly into a SelectMany, and Concat is used to create a new sequence for each element in the collection. This is how the ConnectedComponentCollection (output of the BinaryRegionAnalysis node) gets converted into individual elements of the type ConnectedComponent
  • each ConnectedComponent has a centroid, which gets selected and converted to a string using the Format operator
  • The centroids are then combined into a list using ToList and saved with a CsvReader.

I hope this helps.
multi-animal-tracking-updated.zip

That's great! Thanks much! Worked like a charm!

Hi @ncguilbeault sorry - I should have checked the results more carefully - I was trying to make some trajectory plots with the data and it looked odd. When I examined the results CSV closely I noticed that there was some "shifting" of the centroid data per object detected. Is this because there are objects (flies) entering or leaving the region of interest - and because of this the stream of centroids is being interrupted. Any ideas how to fix this? I've attached the trajectories plot and the csv (converted to an excel) with some examples of this shift color-coded.
results2024-02-27T14_18_18-COLORCODED.xlsx

trajectories