Skip to content

Commit

Permalink
Add support for new overloads of intrinsics() function
Browse files Browse the repository at this point in the history
SDK 2.10.0 introduces two new overloads of the intrinsics() function:
- intrinsics(Camera, Settings)
- intrinsics(Camera, Settings2D)

The purpose of these is to provide intrinsics for cases where capture is
done with non-default settings that affect the intrinsics, like pixel
sampling.
  • Loading branch information
torbsorb authored and eskaur committed Aug 16, 2023
1 parent 860853d commit c0fac7a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
43 changes: 38 additions & 5 deletions modules/zivid/experimental/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,53 @@
import _zivid
from zivid.calibration import DetectionResult
from zivid.camera_intrinsics import _to_camera_intrinsics
from zivid.settings import Settings, _to_internal_settings
from zivid.settings_2d import Settings2D, _to_internal_settings2d


def intrinsics(camera):
"""Get intrinsic parameters of a given camera.
def intrinsics(camera, settings=None):
"""Get intrinsic parameters of a given camera and settings (3D or 2D).
These intrinsic parameters take into account the expected resolution of the point clouds captured
with the given settings. If settings are not provided, intrinsics appropriate for the camera's
default 3D capture settings is returned.
Note: This function returns intrinsics for a fixed temperature and aperture value. The only part
of Settings currently used by this function is <see cref="Settings::Sampling::Pixel"/>.
Args:
camera: A Camera instance
settings: Settings or Settings2D to be used to get correct intrinsics (optional)
Returns:
A CameraIntrinsics instance
Raises:
TypeError: If settings argument is not Settings or Settings2D
"""
return _to_camera_intrinsics(
_zivid.calibration.intrinsics(
camera._Camera__impl # pylint: disable=protected-access
if settings is None:
return _to_camera_intrinsics(
_zivid.calibration.intrinsics(
camera._Camera__impl # pylint: disable=protected-access
)
)
if isinstance(settings, Settings):
return _to_camera_intrinsics(
_zivid.calibration.intrinsics(
camera._Camera__impl, # pylint: disable=protected-access
_to_internal_settings(settings),
)
)
if isinstance(settings, Settings2D):
return _to_camera_intrinsics(
_zivid.calibration.intrinsics(
camera._Camera__impl, # pylint: disable=protected-access
_to_internal_settings2d(settings),
)
)
raise TypeError(
"Unsupported type for argument settings. Got {}, expected Settings or Settings2D.".format(
type(settings)
)
)

Expand Down
28 changes: 23 additions & 5 deletions src/Calibration/Calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

#include <vector>

namespace py = pybind11;

namespace ZividPython::Calibration
{
void wrapAsSubmodule(pybind11::module &dest)
void wrapAsSubmodule(py::module &dest)
{
using namespace Zivid::Calibration;

Expand All @@ -40,10 +42,26 @@ namespace ZividPython::Calibration
.def("calibrate_eye_in_hand", &Zivid::Calibration::calibrateEyeInHand)
.def("calibrate_eye_to_hand", &Zivid::Calibration::calibrateEyeToHand)
.def("calibrate_multi_camera", &Zivid::Calibration::calibrateMultiCamera)
.def("intrinsics",
[](ReleasableCamera &releasableCamera) {
return Zivid::Experimental::Calibration::intrinsics(releasableCamera.impl());
})
.def(
"intrinsics",
[](ReleasableCamera &releasableCamera) {
return Zivid::Experimental::Calibration::intrinsics(releasableCamera.impl());
},
py::arg("camera"))
.def(
"intrinsics",
[](ReleasableCamera &releasableCamera, const Zivid::Settings &settings) {
return Zivid::Experimental::Calibration::intrinsics(releasableCamera.impl(), settings);
},
py::arg("camera"),
py::arg("settings"))
.def(
"intrinsics",
[](ReleasableCamera &releasableCamera, const Zivid::Settings2D &settings_2d) {
return Zivid::Experimental::Calibration::intrinsics(releasableCamera.impl(), settings_2d);
},
py::arg("camera"),
py::arg("settings_2d"))
.def("estimate_intrinsics", [](ReleasableFrame &releasableFrame) {
return Zivid::Experimental::Calibration::estimateIntrinsics(releasableFrame.impl());
});
Expand Down
20 changes: 20 additions & 0 deletions test/calibration/test_intrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ def test_intrinsics(file_camera):
_check_camera_intrinsics(camera_intrinsics)


def test_intrinsics_with_settings_2d(file_camera):
from zivid.experimental.calibration import intrinsics
from zivid.settings_2d import Settings2D

camera_intrinsics = intrinsics(
camera=file_camera, settings=Settings2D(acquisitions=[Settings2D.Acquisition()])
)
_check_camera_intrinsics(camera_intrinsics)


def test_intrinsics_with_settings_3d(file_camera):
from zivid.experimental.calibration import intrinsics
from zivid.settings import Settings

camera_intrinsics = intrinsics(
camera=file_camera, settings=Settings(acquisitions=[Settings.Acquisition()])
)
_check_camera_intrinsics(camera_intrinsics)


def test_estimate_intrinsics(frame):
from zivid.experimental.calibration import estimate_intrinsics

Expand Down

0 comments on commit c0fac7a

Please sign in to comment.