Blob tracking, iterating through table rows with python for loop

blobtrack_totalarea.toe (5.0 KB)

Hi! I’ve been experimenting with python and TD quite a bit these last few months, and lately I’ve had this idea using blob tracking.

Basically, I want to calculate the total area of all the blobs on-screen, live. I’ve found a way using a bunch of expression chops. For each chops, I’m looking at the ‘blobtrack1_blobs’ table, and then verifying with an if statement if there is a row number x before multiplying the width and height values (I’ve uploaded my .toe file if you wanna see that).

This works, but i feel like there might be an easier and more concise way to do it (and also a way that accounts for an infinite number of rows, and not just how many chops i was able to fit in). I think a for loop would do the trick, for each rows that exists in the table, multiply the width column with the height column. The thing is I’ve never seen one in action in any tutorials or documentation, and I cant figure out how and where I can integrate it.

Is this even possible? Please help!

Hi @hd.maxi,

you can use a DAT To CHOP for this purpose:

you would want to “Select Rows” All but only “Selects Cols” by Values with “Col Select Values” set to width height.
The “Output” should be Channel per Column with the “First Row” being Names and “First Column” being Values.

You will now capture all values from each detected blob into 2 channels: width and height.
Append a Math to “Combine Channels” Multiply and use an Analyze CHOP after with “Function” set to Sum.


1 Like

Hey Markus!

Thank you so much for this solution, it’s so much easier than what I was trying to do! Everything runs surper smoothly now :slight_smile:

1 Like