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

Calibration: Add functions to access intrinsic camera parameters #113

Merged
merged 1 commit into from
Mar 30, 2021

Conversation

johan12345
Copy link
Contributor

Camera matrix and distortion coefficients in OpenCV-compatible format.
These values are already specific to the selected camera resolution (in contrast to those accessed through calibration_raw).

related to #35, #69

@codecov
Copy link

codecov bot commented Mar 22, 2021

Codecov Report

❗ No coverage uploaded for pull request base (develop@54281b4). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop     #113   +/-   ##
==========================================
  Coverage           ?   87.39%           
==========================================
  Files              ?       10           
  Lines              ?      682           
  Branches           ?        0           
==========================================
  Hits               ?      596           
  Misses             ?       86           
  Partials           ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54281b4...f63d978. Read the comment docs.

Camera matrix and distortion coefficients in OpenCV-compatible format.
These values are already specific to the selected camera resolution (in contrast to those accessed through calibration_raw).

related to etiennedub#35, etiennedub#69
@lpasselin
Copy link
Collaborator

lpasselin commented Mar 22, 2021

Thanks for the PR!

Can anyone else confirm the new functions work properly? (I will have access to my k4a later this week)

@ZdenekM
Copy link

ZdenekM commented Mar 23, 2021

I haven't tested the code yet, but it seems correct. I was using this conversion so far.

@pgrady3
Copy link

pgrady3 commented Mar 30, 2021

I've downloaded this pull request and can confirm that getting the color camera intrinsic and distortion parameters work. They allow undistorting with the OpenCV functions.

k4a = PyK4A(
    Config(
        color_resolution=pyk4a.ColorResolution.RES_1080P,
        depth_mode=pyk4a.DepthMode.WFOV_2X2BINNED,
        synchronized_images_only=False,
        camera_fps=pyk4a.FPS.FPS_15
    ),
)

k4a.start()

intrinsic = k4a.calibration.get_camera_matrix(pyk4a.calibration.CalibrationType.COLOR)
distortion = k4a.calibration.get_distortion_coefficients(pyk4a.calibration.CalibrationType.COLOR)

@lpasselin lpasselin merged commit 7ac5327 into etiennedub:develop Mar 30, 2021
@lpasselin lpasselin mentioned this pull request Apr 7, 2021
lpasselin added a commit that referenced this pull request Apr 8, 2021
- Use clang-format as CPP code formatter/linter (#105)
- Available devices count (#107)
- Recording support (#106)
- Capture color exposure and white balance properties (#110)
- Calibration: Add functions to access intrinsics (#113)
- Add 3d => 2d conversion function (#114)

* Run test with different python versions (#65)

* Add matrix to workflow

* Change python versions list

* Change python versions list

* Add k4a versions to matrix

* Typofix

* Drop k4a from matrix

* Add dataclasses requirement for python <3.7

* Fix python 3.6 test behavior

* Fix python 3.6 test behavior

* Restore fail-fast option

* fix conversion seconds to ns

* fix conversion seconds to ns

* fix timestamp ns to us

Co-authored-by: Louis-Philippe Asselin <[email protected]>

* fix install using pip --editable --user (#67)

* Codecov support (#64)

* Codecov support

* Add badge

* Order badges

* fix capture.transformed_depth_point_cloud (#73)

* version 1.0.1

* Added transformed_ir with transform_depth_image_to_color_camera_custom functionality (#76)

* Added transform_depth_image_to_color_camera_custom functionality

* keeping things c

* add interpolation option condition as a parameter

* returned the depth image

* unpack return value if not None so avoid error

* Image timestamp support (#88)

* Support for capture images timestamps

* Support for capture images timestamps

* Add more changes

* version 1.1.0

* fix lint

* readme fix wrong example version of SDK

* Use clang-format as CPP code formatter/linter (#105)

* Use clang-format as CPP code formatter/linter

* Add missed .clang-format

* Available devices count (#107)

* Add ability to querying devices count and read serial numbers

* Fix test

* Rename installed_count => connected_device_count

* Recording support (#106)

* Recording support

* Tests

* Small refactoring

* Add ability to querying devices count and read serial numbers

* Fix test

* Fix format

* Capture color exposure and white balance properties (#110)

* Add color_white_balance and exposure_usec properties to capture

* Add color_white_balance and exposure_usec properties to capture

Co-authored-by: Louis-Philippe Asselin <[email protected]>

* Calibration: Add functions to access intrinsics (#113)

Camera matrix and distortion coefficients in OpenCV-compatible format.
These values are already specific to the selected camera resolution (in contrast to those accessed through calibration_raw).

related to #35, #69

Co-authored-by: Johan von Forstner <[email protected]>

* version 1.2.0

Co-authored-by: Ilya Gruzinov <[email protected]>
Co-authored-by: Samuel Boulanger <[email protected]>
Co-authored-by: Johan von Forstner <[email protected]>
Co-authored-by: Johan von Forstner <[email protected]>
@wangmiaowei
Copy link

How to undistort the depth map? I just use opencv function but the results are bad
import numpy as np
import cv2
import open3d as o3d
w = 640
h = 576

intrinsic = np.array([[503.08432007, 0.,324.27612305],[ 0. ,503.16601562,330.65237427],
[ 0. ,0. ,1. ]])
dist_coeffs=np.array([ 2.06184745e-01,-1.28368318e-01,2.92664499e-05,2.75623443e-05,
-5.74961351e-03,5.43716311e-01,-1.30464926e-01,-3.45068611e-02])

newcameramatrix, _ = cv2.getOptimalNewCameraMatrix(
intrinsic, dist_coeffs, (w, h), 1, (w, h)
)
path1= "/home/SENSETIME/wangmiaowei/WMW_WORK/programs/2022_start/data_local_center/plant_3D/Pole/cylinder80mm1/depth/SN_1.png"
depth = cv2.imread(path1, cv2.IMREAD_UNCHANGED)
undistorted_image = cv2.undistort(
depth, intrinsic, dist_coeffs, None, newcameramatrix
)
depth=undistorted_image/1000
print('newcamera: ',newcameramatrix)
depth = o3d.geometry.Image(depth.astype('float32'))
cam = o3d.camera.PinholeCameraIntrinsic()
cam.intrinsic_matrix = intrinsic
pcd = o3d.geometry.PointCloud.create_from_depth_image(depth,cam)
o3d.visualization.draw_geometries([pcd])
o3d.io.write_point_cloud("/home/SENSETIME/wangmiaowei/WMW_WORK/programs/2022_start/data_local_center/plant_3D/Pole/cylinder80mm1/depth/SN_1.ply",pcd)

@zhanghua7099 zhanghua7099 mentioned this pull request Oct 17, 2023
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.

5 participants