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

camera_calibration: Improve YAML formatting, make config dumping methods static #438

Merged
merged 2 commits into from
Aug 13, 2019

Conversation

valgur
Copy link
Contributor

@valgur valgur commented Jul 26, 2019

Some more minor improvements:

  • Added from __future__ import print_function to make sure the printed output looks as expected, rather than e.g. ('D = ', [0.8272, ...]) on Python 2.
  • Improved matrix formatting in the YAML output by making use of array formatting from Numpy.
  • Reduced precision for camera and projection matrices to 3 in the YAML output since everything
    past 1 decimal place is mostly excessive.
  • Made calibration config dumping methods static to allow them to be used conveniently from elsewhere as well.

What the YAML output looks like after these changes:

image_width: 480
image_height: 640
camera_name: narrow_stereo/left
camera_matrix:
  rows: 3
  cols: 3
  data: [502.992,   0.   , 250.226,
           0.   , 503.221, 245.983,
           0.   ,   0.   ,   1.   ]
distortion_model: rational_polynomial
distortion_coefficients:
  rows: 1
  cols: 8
  data: [6.798071, 140.213354, -0.003831, -0.002863, 1485.092992, 6.747936, 141.145419, 1475.894951]
rectification_matrix:
  rows: 3
  cols: 3
  data: [1., 0., 0.,
         0., 1., 0.,
         0., 0., 1.]
projection_matrix:
  rows: 3
  cols: 4
  data: [507.04 ,   0.   , 248.912,   0.   ,
           0.   , 505.216, 243.459,   0.   ,
           0.   ,   0.   ,   1.   ,   0.   ]

@SteveMacenski
Copy link
Member

Reduced precision for camera and projection matrices to 3

I disagree with that, this may be used in really high resolution camera situations were there may be more meaningful sig figs to look at. If we have some numbers, I'm not sure its up to the printing area to truncate them. While I'd generally agree there may be some value to cut off at 3 actually seems too few. I'd think ~5-6 being the minimum before truncating

@valgur
Copy link
Contributor Author

valgur commented Aug 1, 2019

Ok, I can undo the camera/projection matrix rounding. Just to be clear, I assume you meant 5-6 figures after the decimal point rather than significant figures?

Makes sure the printed output looks as expected, rather than e.g.
('D = ', [0.8272, ...])
on Python 2.
* Improves matrix formatting in YAML, for example:
  data: [502.99207,   0.     , 250.22621,
           0.     , 503.22066, 245.98286,
           0.     ,   0.     ,   1.     ]
* Reduced decimal figures for camera and projection matrix values from 8 to 5.
* Making the methods static allows them to be used from elsewhere as well
  to dump calibration info.
@valgur
Copy link
Contributor Author

valgur commented Aug 6, 2019

Set the number of decimal digits for intrinsic and projection matrices to 5.

image_width: 480
image_height: 640
camera_name: narrow_stereo/left
camera_matrix:
  rows: 3
  cols: 3
  data: [502.99207,   0.     , 250.22621,
           0.     , 503.22066, 245.98286,
           0.     ,   0.     ,   1.     ]
distortion_model: rational_polynomial
distortion_coefficients:
  rows: 1
  cols: 8
  data: [6.798071, 140.213354, -0.003831, -0.002863, 1485.092992, 6.747936, 141.145419, 1475.894951]
rectification_matrix:
  rows: 3
  cols: 3
  data: [1., 0., 0.,
         0., 1., 0.,
         0., 0., 1.]
projection_matrix:
  rows: 3
  cols: 4
  data: [507.04044,   0.     , 248.912  ,   0.     ,
           0.     , 505.21561, 243.45872,   0.     ,
           0.     ,   0.     ,   1.     ,   0.     ]

@SteveMacenski
Copy link
Member

@valgur looks good, yeah you got my meaning sorry for the late response, I've been caught up in another repo.

This all looks good to me now, have you tried loading this output yaml and make sure it works for the other application?

Then I'll merge

@valgur
Copy link
Contributor Author

valgur commented Aug 13, 2019

I tested loading the YAML output as a CameraInfo message with camera_info_manager and camera_info_manager_py. Both return correct results.
Besides that, I have also been using similarly-formatted calibration files in deployed code without any ill effects.

@SteveMacenski SteveMacenski merged commit 49cb230 into ros-perception:melodic Aug 13, 2019
@SteveMacenski
Copy link
Member

Sounds good!

@valgur valgur deleted the yaml-formatting branch August 13, 2019 17:11
wep21 pushed a commit to wep21/image_pipeline that referenced this pull request Oct 17, 2021
…ods static (ros-perception#438)

* Add `from __future__ import print_function`

Makes sure the printed output looks as expected, rather than e.g.
('D = ', [0.8272, ...])
on Python 2.

* Improve YAML formatting, make some methods static

* Improves matrix formatting in YAML, for example:
  data: [502.99207,   0.     , 250.22621,
           0.     , 503.22066, 245.98286,
           0.     ,   0.     ,   1.     ]
* Reduced decimal figures for camera and projection matrix values from 8 to 5.
* Making the methods static allows them to be used from elsewhere as well
  to dump calibration info.
JWhitleyWork pushed a commit that referenced this pull request Nov 11, 2021
…ods static (#438)

* Add `from __future__ import print_function`

Makes sure the printed output looks as expected, rather than e.g.
('D = ', [0.8272, ...])
on Python 2.

* Improve YAML formatting, make some methods static

* Improves matrix formatting in YAML, for example:
  data: [502.99207,   0.     , 250.22621,
           0.     , 503.22066, 245.98286,
           0.     ,   0.     ,   1.     ]
* Reduced decimal figures for camera and projection matrix values from 8 to 5.
* Making the methods static allows them to be used from elsewhere as well
  to dump calibration info.
JWhitleyWork pushed a commit that referenced this pull request Apr 14, 2022
…ods static (#438)

* Add `from __future__ import print_function`

Makes sure the printed output looks as expected, rather than e.g.
('D = ', [0.8272, ...])
on Python 2.

* Improve YAML formatting, make some methods static

* Improves matrix formatting in YAML, for example:
  data: [502.99207,   0.     , 250.22621,
           0.     , 503.22066, 245.98286,
           0.     ,   0.     ,   1.     ]
* Reduced decimal figures for camera and projection matrix values from 8 to 5.
* Making the methods static allows them to be used from elsewhere as well
  to dump calibration info.
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.

2 participants