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

new: camera pose from spherical coordinate system #20

Merged
merged 13 commits into from
Sep 24, 2023
Merged

Conversation

yxlao
Copy link
Owner

@yxlao yxlao commented Sep 23, 2023

Features

New: Convert spherical coordinates to camera extrinsic

ct.convert.spherical_to_T_towards_origin(radius, theta, phi)

The converted camera extrinsic has the following properties:

  • The camera is centered at the point specified by the spherical coordinates.
  • The camera points to the origin.
  • The camera's "up" direction aligns with the +Z axis (meaning, the angle is <= pi/2).

The spherical coordinates are defined using the ISO standard (Ref).

New: Convert Euler coordinates to rotation matrix

ct.convert.euler_to_R(yaw, pitch, roll)

Example

import camtools as ct
import numpy as np
import open3d as o3d
import itertools


def main():
    K = np.array(
        [
            [554.256, 0.0, 320],
            [0.0, 554.256, 240],
            [0.0, 0.0, 1.0],
        ]
    )

    resolution = 12
    radius = 1.0
    thetas = np.linspace(0, np.pi, resolution, endpoint=False)[1:]
    phis = np.linspace(0, 2 * np.pi, resolution, endpoint=False)

    Ts = [
        ct.convert.spherical_to_T_towards_origin(radius, theta, phi)
        for (theta, phi) in itertools.product(thetas, phis)
    ]
    Ks = [K for _ in range(len(Ts))]

    # Old API is ct.camera.create_camera_ray_frames
    cameras = ct.camera.create_camera_frames(Ks=Ks, Ts=Ts, center_line=False)
    axes = o3d.geometry.TriangleMesh.create_coordinate_frame(size=1.0)
    o3d.visualization.draw_geometries([cameras, axes])


if __name__ == "__main__":
    main()

sphere_camera

Some notes on creating gif:

# Speed up and then use Handbrake to generate MP4
mencoder -speed 2 -o sphere_camera_fast.webm -ovc copy sphere_camera.webm

# Convert webm to gif
wget https://github.com/ImageOptim/gifski/releases/download/1.11.0/gifski_1.11.0_amd64.deb
sudo dpkg -i gifski_1.11.0_amd64.deb
gifski sphere_camera_fast.webm -o sphere_camera.gif -r 12 --fast-forward 2 -Q 90 -H 480 --extra --repeat 0

@yxlao yxlao changed the title feat: camera pose from spherical coordinate system new: camera pose from spherical coordinate system Sep 24, 2023
@yxlao yxlao marked this pull request as ready for review September 24, 2023 09:26
@yxlao yxlao merged commit 713c228 into master Sep 24, 2023
3 checks passed
@yxlao yxlao deleted the yixing/polar branch September 24, 2023 09:27
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

Successfully merging this pull request may close these issues.

None yet

1 participant