Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An elegant way to install origin viser instead of modified viser #21

Closed
zjcs opened this issue Dec 25, 2023 · 4 comments
Closed

An elegant way to install origin viser instead of modified viser #21

zjcs opened this issue Dec 25, 2023 · 4 comments

Comments

@zjcs
Copy link

zjcs commented Dec 25, 2023

I notice that author modify the origin viser to capture the scene click pixel (actually, it is normal pixel). Here is an implemention via the origin viser, which can be used in click_cb function:

        camera = list(self.server.get_clients().values())[0].camera
        W = int(self.resolution_slider.value)
        H = int(W / self.aspect)
        WH = torch.Tensor([W, H])
        fxy = WH/2 / np.tan(camera.fov/2)
        # TODO: fxy from different fovx, fovy?
        dxyz = tf.SO3(camera.wxyz).inverse().as_matrix() @ pointer.ray_direction
        uv = fxy * torch.Tensor(dxyz[:2])/dxyz[2] + WH/2
        click_pos = uv / WH
@zjcs
Copy link
Author

zjcs commented Dec 25, 2023

By the way, it is a solution to #2

@buaacyw
Copy link
Owner

buaacyw commented Dec 26, 2023

Thanks for your contribution!

@zjcs
Copy link
Author

zjcs commented Dec 26, 2023

@buaacyw sorry to say that the above code has some bug when calucate fov via aspect, here is the right implemention:

    @self.server.on_scene_click
    def _(point):
           for client in self.server.get_clients().values():
                camera = client.camera
                ray_d = torch.Tensor(tf.SO3(camera.wxyz).inverse().as_matrix() @ point.ray_direction)
                # ray_d, the ray in the camera, x->right, y->down, z->far
                xy_norm = ray_d[:2]/ray_d[2]
                
                WH = torch.Tensor([self.resolution_slider.value, self.resolution_slider.value/camera.aspect]).int()
                tan_fov_2 = torch.Tensor([np.tan(camera.fov/2)*camera.aspect, np.tan(camera.fov/2)])
                fxy = WH/2 / tan_fov_2

                uv = (fxy * xy_norm  + WH/2).int()

                click_pos = uv / WH

@jimmychuang95
Copy link

@zjcs I modify the webui.py code as you provided, but the bounded box and SAM points still cannot be added into scene, what else should I need to change to let those functions work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants