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

converting fisheye to rectilinear image #27

Closed
TaheraTT opened this issue Apr 30, 2021 · 3 comments
Closed

converting fisheye to rectilinear image #27

TaheraTT opened this issue Apr 30, 2021 · 3 comments

Comments

@TaheraTT
Copy link

TaheraTT commented Apr 30, 2021

The code shared in projection.py gives cylindrical image as output. I am trying to convert the fisheye image to rectilinear image. Can someone guide me on how to do that.

@sleepywitti
Copy link
Contributor

Hello TaheraTT,
you need to add the corresponding projection/lens model to convert the images to rectilinear images.

Here is an example, how to do it:

class PinholeLens(Projection):
    def __init__(self, focal_length: typing.Union[float, list]):
        self.focal_length = focal_length if isinstance(focal_length, (float, int)) else focal_length[0]
        self.K = np.array([self.focal_length, self.focal_length, 1], dtype=float)

    def project_3d_to_2d(self, cam_points, invalid_value=np.nan):
        camera_points = ensure_point_list(cam_points, dim=3)
        camera_points = camera_points * self.K
        zs = camera_points[:, 2][:, np.newaxis]
        uv = np.divide(camera_points[:, 0:2], zs, where=(zs != 0))

        # mark points behind the camera (z <= 0) as invalid
        uv[camera_points[:, 2] <= 0] = [invalid_value, invalid_value]
        return uv

    def project_2d_to_3d(self, image_points: np.ndarray, norms: np.ndarray):
        image_points = ensure_point_list(image_points, dim=3)
        norms = ensure_point_list(norms, dim=1)

        xy_normed = image_points / self.K
        xy_normed_norm = np.linalg.norm(np.array(xy_normed), axis=1)
        z = norms / xy_normed_norm[:, np.newaxis]
        return z * xy_normed

Best regards,
Christian

@TaheraTT TaheraTT closed this as completed May 7, 2021
@TaheraTT
Copy link
Author

TaheraTT commented May 7, 2021

Thanks for the answer Christian. I am able to solve the issue now.

Best Regards
Tahera

@Mrr-Wang
Copy link

Thanks for the answer Christian. I am able to solve the issue now.

Best Regards Tahera

Hello Tahera,
How did you solve this problem ,specifically

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