Skip to content

Commit

Permalink
Support for overloads of calibration.intrinsics
Browse files Browse the repository at this point in the history
SDK 2.10.0 introduces two overloads of the
calibration.intrinsics API. One with settings and one with
settings_2d. This commit adds support in the Python wrapper
  • Loading branch information
torbsorb authored and eskaur committed Aug 16, 2023
1 parent a98dd84 commit 58b09ce
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
30 changes: 24 additions & 6 deletions modules/zivid/experimental/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@
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).
Args:
camera: A Camera instance
settings[optional]: Settings to be used to get correct intrinsics. Can be either a Settings or Settings2D instance
Returns:
A CameraIntrinsics instance
"""
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),
)
)
)


def estimate_intrinsics(frame):
Expand Down
17 changes: 15 additions & 2 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 @@ -43,7 +45,18 @@ namespace ZividPython::Calibration
.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 58b09ce

Please sign in to comment.