4

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?

someonewithpc
  • 12,381
  • 6
  • 55
  • 89
BetterEnglish
  • 2,000
  • 4
  • 29
  • 53

1 Answers1

1

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

quellenform
  • 35,177
  • 10
  • 50
  • 133