How do I calculate how much of a object is covered in a 2D image? I'm using code from here: Save the 2D bounding box of an object in rendered image to a text file

To calculate a bounding box coordinates for an object (say a human) in a rendered image. That works great.

I want however to expand this to be able to calculate how much of the object that is covered by other objects in the rendered image.



I want to do some research in AI/deep-learning as to try to train a neural network in detecting various computer generated objects in traffic. So any help here would be adding to that work.
In the "Render Layer" / "Passes" panel, enable the Object Index pass. You can then give each object, like your human object, a unique index using the "Pass Index" property in their "Relations" panel.

Once you've given each object of interest a unique "Pass Index", you can inspect that render pass after the image has rendered. Each pixel will have an RGB value equal to the "Pass Index". You can render twice, once with the obstructing objects and once without. Once you've done that, you can find your answer simply by counting counting pixels in each case; dividing the obstructed count by the unobstructed count will give you the unobstructed percentage.