1
$\begingroup$

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.

enter image description here

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.

$\endgroup$
  • $\begingroup$ What have you tried so far? What have you got already? This sounds more like a general coding question rather than about Blender itself. $\endgroup$ – Duarte Farrajota Ramos May 31 '17 at 12:54
  • $\begingroup$ I'm voting to close this question as off-topic because it seems like a general coding question, rather than about Blender itself. $\endgroup$ – Duarte Farrajota Ramos May 31 '17 at 12:55
  • $\begingroup$ I think closing this question is unwarranted, as there is a clear, Blender-specific approach that easily answers this question (see my answer below). $\endgroup$ – dr. Sybren May 31 '17 at 20:21
  • $\begingroup$ I have so far not tried to solve this specific problem. I was reaching out to the community to get some ideas on how to pursue the solution to avoid getting into dead ends. It seems that @codemanx user who made the code I refer to in my post would be a great person to ask? $\endgroup$ – Erik Lönroth Jun 1 '17 at 12:40
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Thanx alot! This at least gives me a path forward. I was hoping to be able to do this with some linear algebra/projections or similar to take advantage over the inbuilt python support in Blender. But without knowing the internals, its a steep curve to learn how and what primitives to use to be able to calculate it in some efficient manner. After all, rendering the scene multiple times is heavy. $\endgroup$ – Erik Lönroth Jun 1 '17 at 12:39
  • $\begingroup$ Rendering this isn't heavy at all. This render pass is very cheap, and you don't need any other passes for this calculation. $\endgroup$ – dr. Sybren Jun 1 '17 at 15:16
  • $\begingroup$ BTW, please accept this answer as the answer. It'll mark your question as answered and give me some reputation points. $\endgroup$ – dr. Sybren Jun 5 '17 at 9:53
  • $\begingroup$ Hello. I'll try the method and see how far I get. $\endgroup$ – Erik Lönroth Jun 20 '17 at 12:43
  • $\begingroup$ I'm not able to produce a render with "Index Pass = 123". It turns out to be all grey all the time. Any hint on what I might be doing wrong? $\endgroup$ – Erik Lönroth Jun 20 '17 at 13:26
0
$\begingroup$

I was doing exactly the same thing, but my scene takes a lot more time to render, on top of my old machine to work on. So I used to check all the vertices of all the objects, if they are visible or not. First I would parse a single object in my scene, and check how many of the vertices are visible to camera(assuming the objects isn't occluded even a bit), second things is out of all those vertices, I did check how many vertices are actually visible(not occluded by other objects). All this is done using just a simple 2d array, which I also described in another question, here.

=> fraction of the object visible in rendered image =

Actually visible vertices / Total vertices supposed to be visible in case of no occlusion

Note: This approach might not be the best, but for the objects which has a good amount of vertices unlike cube/cuboids, this approach would do just fine, as it did for me. As for the computation expense, this is cheaper in comparison of complex scene rendering multiple times because of too many objects existing in it.

Let me know if any of you find any issue in here, it would be better for me as well to know any other flaws in this approach as I am still working with this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.