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

Transforming calibration parameters (intrinsics) #69

Closed
FelipeDelgadoR opened this issue Sep 24, 2020 · 5 comments
Closed

Transforming calibration parameters (intrinsics) #69

FelipeDelgadoR opened this issue Sep 24, 2020 · 5 comments

Comments

@FelipeDelgadoR
Copy link

Hi @etiennedub
I've got these values from the RGB camera:

"ModelParameters": [
0.49965196847915649,
0.50621724128723145,
0.47322136163711548,
0.63089394569396973,
0.44268873333930969,
-2.6038174629211426,
1.5527737140655518,
0.32462942600250244,
-2.4303467273712158,
1.4789470434188843,
0,
0,
-0.00035283574834465981,
0.00099612073972821236
]

I know that the first 2 are cx, cy, fx and fy and that they are normalized so I can't use them inside opencv as the intrinsic matrix...
Right now i'm using this configuration:
K4A_FRAMES_PER_SECOND_15
K4A_COLOR_RESOLUTION_1080P
K4A_DEPTH_MODE_WFOV_UNBINNED

You gave me this code to check it out, but I'm not sure if I understand it correctly
I'd appreciate if you give me some help on transforming these values, thanks again!

@FelipeDelgadoR
Copy link
Author

I found the function that defines the structure of the code:

typedef struct _k4a_camera_calibration_mode_info_t
{
unsigned int calibration_image_binned_resolution[2];
int crop_offset[2];
unsigned int output_image_resolution[2];
} k4a_camera_calibration_mode_info_t;

so basically when we use the 1080p resolution we got these values:

case K4A_COLOR_RESOLUTION_1080P:
{
k4a_camera_calibration_mode_info_t mode_info = { { 1920, 1440 }, { 0, 180 }, { 1920, 1080 } };

so basically according to this code we have to perform this operation:

float cx = params->param.cx * mode_info->calibration_image_binned_resolution[0];
float cy = params->param.cy * mode_info->calibration_image_binned_resolution[1];
float fx = params->param.fx * mode_info->calibration_image_binned_resolution[0];
float fy = params->param.fy * mode_info->calibration_image_binned_resolution[1];

cx -= mode_info->crop_offset[0];
cy -= mode_info->crop_offset[1];

And I got these values:

cx = 959.3317794799805
cy = 548.9528274536133
fx = 908.5850143432617
fy = 908.4872817993164

The values that we got from this "recording procedure" that open3d offers are:

cx = 958.831787109375
cy = 548.45281982421875
fx = 908.58502197265625
fy = 908.4873046875

So I think that I got it now...
but now I've stumbled upon another problem.
In the calibration json file I got these values (on the rgb camera):

"Rt": {
"Rotation": [
0.99998795986175537,
0.0047808918170630932,
-0.0010995579650625587,
-0.004640678409487009,
0.99457055330276489,
0.10396119207143784,
0.0015906151384115219,
-0.10395484417676926,
0.99458074569702148
],
"Translation": [
-0.032096963375806808,
-0.0019254388753324747,
0.0040484610944986343
]
},

According to me, this means the transformation matrix between the RGB camera and the DEPTH camera, is this right? what units are these? what is the structure of the matrix?

thanks in advance!

@etiennedub
Copy link
Owner

Hi @FelipeDelgadoR, I think you got it right for the intrinsics paramaters and as you said, it really depends on the resolution.

For the extrinsics parameters, those are not normalized and can be used directly in a 4x3 matrix. There is more information in the OpenCV documentation.
The form of the matrix is the following:
R[0], R[1], R[2], T[0],
R[3], R[4], R[5], T[1],
R[6], R[7], R[8], T[2]

Yes those the extrinsics parameters between both camera, the translation unit is in meter and for the rotation there is no unit because those are sin and cos values of the rotation by axis.

I hope it answer your question!

@FelipeDelgadoR
Copy link
Author

I was just thinking that after I posted the question, of course the T values are in meters!
Thanks @etiennedub! I'll close this issue...

@ZdenekM
Copy link

ZdenekM commented Nov 19, 2020

How can I get mode_info using pyk4a? I searched the code but could not find it... Many thanks.

Btw, it would be great to have a utility function to convert intrinsic parameters to the OpenCV format. I think more people would appreciate it :-)

johan12345 added a commit to johan12345/pyk4a that referenced this issue Mar 22, 2021
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
johan12345 added a commit to johan12345/pyk4a that referenced this issue Mar 22, 2021
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
johan12345 added a commit to johan12345/pyk4a that referenced this issue Mar 22, 2021
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
johan12345 added a commit to johan12345/pyk4a that referenced this issue Mar 22, 2021
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
@johan12345
Copy link
Contributor

@ZdenekM

Btw, it would be great to have a utility function to convert intrinsic parameters to the OpenCV format. I think more people would appreciate it :-)

FYI: I have opened a pull request adding such a function for accessing the intrinsic parameters in an OpenCV-compatible format: #113.

lpasselin pushed a commit that referenced this issue Mar 30, 2021
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 <johan.vonforstner@paradoxcat.com>
lpasselin added a commit that referenced this issue 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 <louisphilippeasselin@gmail.com>

* 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 <lpasselin@users.noreply.github.com>

* 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 <johan.vonforstner@paradoxcat.com>

* version 1.2.0

Co-authored-by: Ilya Gruzinov <igruzinov@yandex.ru>
Co-authored-by: Samuel Boulanger <samuelrdboulanger@gmail.com>
Co-authored-by: Johan von Forstner <johan.forstner@gmail.com>
Co-authored-by: Johan von Forstner <johan.vonforstner@paradoxcat.com>
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

4 participants