I am working on a project in which i used the panoramic camera with fisheye equisolid lens on Cycles render. For some tests, I need the projection model that uses by this camera to project a 3D point on a 2D image plane. Any help?
- 12,381
- 6
- 55
- 89
- 2,000
- 4
- 29
- 53
-
It so nervous to do not get this important information. We get just a naive black box! – BetterEnglish Nov 04 '15 at 21:44
-
Blender is open source, there is no black box :) – zeffii Jan 10 '16 at 09:35
-
@zeffii, thanks, could you tell me the link where I can find the details of panoramic camera projection model used in blender? – BetterEnglish Jan 11 '16 at 14:42
-
https://github.com/dfelinto/blender/search?utf8=%E2%9C%93&q=fisheye ( a convenient way to browse Blender's source) – zeffii Jan 11 '16 at 14:49
1 Answers
I needed to do this recently. I think the following code should do the trick.
p is our point in 3D space. Optionally one could set p = bpy.context.scene.cursor.location in order to locate a 3D point in the scene with the cursor and check its pixel (x,y) location in the rendered image.
camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene
f = camera.cycles.fisheye_lens
based on exaplanations in https://blender.stackexchange.com/a/38210 and https://docs.blender.org/manual/en/latest/render/cameras.html#camera
pixel_aspect_ratio = bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if camera.sensor_fit == 'VERTICAL':
# the sensor height is fixed (sensor fit is horizontal),
# the sensor width is effectively changed with the pixel aspect ratio
h = camera.sensor_height
w = pixel_aspect_ratio * h
else: # 'HORIZONTAL' and 'AUTO'
# the sensor width is fixed (sensor fit is horizontal),
# the sensor height is effectively changed with the pixel aspect ratio
w = camera.sensor_width
h = w / pixel_aspect_ratio
camera_ob = bpy.data.objects["Camera"]
p = camera_ob.matrix_world.inverted() * p
p.normalize()
Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x2 + p.y2)**(1/2)
theta = math.asin(l)
Equisolid projection
r = 2.0 * f * math.sin(theta / 2)
u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5
x = u * scene.render.resolution_x
y = v * scene.render.resolution_y
- 35,177
- 10
- 50
- 133
- 111
- 3