4
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ It so nervous to do not get this important information. We get just a naive black box! $\endgroup$ Commented Nov 4, 2015 at 21:44
  • $\begingroup$ Blender is open source, there is no black box :) $\endgroup$
    – zeffii
    Commented Jan 10, 2016 at 9:35
  • $\begingroup$ @zeffii, thanks, could you tell me the link where I can find the details of panoramic camera projection model used in blender? $\endgroup$ Commented Jan 11, 2016 at 14:42
  • $\begingroup$ github.com/dfelinto/blender/search?utf8=%E2%9C%93&q=fisheye ( a convenient way to browse Blender's source) $\endgroup$
    – zeffii
    Commented Jan 11, 2016 at 14:49

1 Answer 1

1
$\begingroup$

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.x**2 + p.y**2)**(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
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .