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

Fish eye distortion removal #131

Closed
carlsummer opened this issue Sep 21, 2023 · 2 comments
Closed

Fish eye distortion removal #131

carlsummer opened this issue Sep 21, 2023 · 2 comments

Comments

@carlsummer
Copy link

carlsummer commented Sep 21, 2023

Here is my code on how to remove the distortion of fish eyes

import numpy as np
import cv2

# 输入相机参数
camera_params = {
  "extrinsic": {
    "quaternion": [
      0.6202204286587283,
      -0.6042974885762495,
      0.36354706163082123,
      -0.34348900878254707
    ],
    "translation used in CARLA (CARLA reference)": [
      1.92,
      0.0,
      0.9
    ]
  },
  "intrinsic": {
    "aspect_ratio": 1.00021,
    "cx_offset": 0.329055,
    "cy_offset": -3.5506,
    "height": 966.0,
    "k1": 341.725,
    "k2": -26.4448,
    "k3": 32.7864,
    "k4": 0.50499,
    "model": "radial_poly",
    "poly_order": 4,
    "width": 1280.0
  },
  "name": "FV"
}


# 提取内参
intrinsic = camera_params["intrinsic"]
width = intrinsic["width"]
height = intrinsic["height"]
aspect_ratio = intrinsic["aspect_ratio"]
cx_offset = intrinsic["cx_offset"]
cy_offset = intrinsic["cy_offset"]
k1 = intrinsic["k1"]
k2 = intrinsic["k2"]
k3 = intrinsic["k3"]
k4 = intrinsic["k4"]

# 计算焦距
focal_u = width / (2 * aspect_ratio)
focal_v = height / 2

# 计算中心点
center_u = width / 2.0 + cx_offset
center_v = height / 2.0 + cy_offset

intrinsics = np.array([focal_u, 0, center_u, 0, focal_v, center_v, 0, 0, 1])
intrinsics = np.reshape(intrinsics, (3, 3))
dist_coeffs = np.array([k1, k2, k3, k4,0])

# 加载鱼眼图像
fisheye_image = cv2.imread(r"C:\Users\jkyjwb\Downloads\SynWoodScape_V0.1.1\SynWoodScape_V0.1.0\rgb_images\00000_FV.png")

undistorted_image = cv2.undistort(fisheye_image, intrinsics, dist_coeffs)

# 保存校正后的图像
cv2.imwrite("undistorted_image.jpg", undistorted_image)
@carlsummer
Copy link
Author

i use PinholeLens can solve,but,i wan't cv2.undistort(fisheye_image, intrinsics, dist_coeffs)
how i do?

def make_cylindrical_cam(cam: Camera):
    """generates a cylindrical camera with a centered horizon"""
    assert isinstance(cam.lens, RadialPolyCamProjection)
    # creates a cylindrical projection
    lens = PinholeLens(cam.lens.coefficients[0])
    rot_zxz = SciRot.from_matrix(cam.rotation).as_euler('zxz')
    # adjust all angles to multiples of 90 degree
    rot_zxz = np.round(rot_zxz / (np.pi / 2)) * (np.pi / 2)
    # center horizon
    rot_zxz[1] = np.pi / 2
    # noinspection PyArgumentList
    return Camera(
        rotation=SciRot.from_euler(angles=rot_zxz, seq='zxz').as_matrix(),
        translation=cam.translation,
        lens=lens,
        size=cam.size, principle_point=(cam.cx_offset, cam.cy_offset),
        aspect_ratio=cam.aspect_ratio
    )

@carlsummer
Copy link
Author

I understand that the model of opencv undo is different from yours, so I can only use the one you provided

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

1 participant