nerfstudio-project / viser

Web-based 3D visualization + Python
https://viser.studio/latest
Apache License 2.0
808 stars 47 forks source link

How to Prevent Image Distortion When the Camera Zooms In? #267

Closed JintaoLee-Roger closed 2 months ago

JintaoLee-Roger commented 2 months ago

Hello!

I encountered an issue while using Viser to render images in 3D space. As I demonstrated, I used three images and defined their positions and orientations using wxyz to form the layout shown below. These images represent seismic slices in three directions, allowing us to observe the 3D distribution of subsurface structures.

When the camera is far from the images, they appear normal. However, when I zoom in using the scroll wheel, the images become distorted. Is there a way to maintain the original shape of the images?

I suspect this might be due to the projection method. Previously, when using Vispy for rendering, I used the TurntableCamera and did not encounter this issue. Could there be another reason causing this?

image image
JintaoLee-Roger commented 2 months ago

The first image shows the situation when it is zoomed out. The second image is the zoomed-in version. Since the image was too large, I first reduced its size before uploading it. This is why the content in both images may appear to be similar in size.

brentyi commented 2 months ago

Hi!

This looks like perspective distortion. If you want it should help to decrease the FOV of the camera:

server = viser.ViserServer()

@server.on_client_connect
def _(client: viser.ClientHandle) -> None:
    client.camera.fov = np.pi / 4.0  # Or some other angle in radians

You could also add a slider for changing this via gui.add_slider() + a callback.

JintaoLee-Roger commented 2 months ago

Oh! It's fine.

It seems to have been caused by me accidentally setting fov to a negative number, which was resolved by using np.pi / 4.0.

Thank you very much.