2

I need a way to find the underlying 3D coordinates for each pixel of the camera in Python.

I to create a function like:

GetCoordinatesForPixel(xPixel, yPixel)

which returns a (X, Y, Z) vector.

I found the following threads:

How to get world coordinates of pixels? which is supposed to be a duplicate of this one: How to render world position pass

The latter solution works in that it procudes a render. However, I do not see a way to access those values in Python.

user1033657
  • 193
  • 2
  • 9
  • Did you look at this post http://blender.stackexchange.com/questions/7106/get-location-in-scene-for-pixel? You will have to play around with it a little, but this might be headed in the right direction. – BlendingJake Nov 05 '14 at 14:29
  • Why would you need to render multiple times? – gandalf3 Nov 05 '14 at 20:48
  • Once for the actual image I want to estimate on and once to get the ground truth values. @BlendingJake I tried to work with bpy_extras.view3d_utils but so far I am not really sure how to handle the arguments. But I may be able to figure it out:) – user1033657 Nov 06 '14 at 14:09
  • @user1033657 I wasn't able to find much info on it, but just keep playing and you'll probably get it. – BlendingJake Nov 06 '14 at 14:12
  • re-opening, @user1033657 would like to edit the question (to make it not a duplicate) – ideasman42 Dec 15 '14 at 17:53
  • Would this help? http://blender.stackexchange.com/questions/16472/how-can-i-get-the-cameras-projection-matrix – someonewithpc Dec 15 '14 at 21:24

1 Answers1

1

Blender's Python API currently doesn't expose access to the pixel value of render passes.

(You can access image pixels but renders's are a more complex structure).

However since you mention you need to store the values in a file, just save the OpenEXR file, this will store the values in a file.

ideasman42
  • 47,387
  • 10
  • 141
  • 223
  • Exactly how would you read these coordinates in .exr image tho? I just loaded an .exr image created from world position pass in Blender https://gofile.io/d/sN7OWF using python OpenEXR, and all the (r,g,b) values are integers, wouldn't they all be float if they represent global coordinates? – June Wang Nov 29 '21 at 12:51