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

Add PixelMapping #251

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Add PixelMapping #251

merged 1 commit into from
Dec 15, 2023

Conversation

torbsorb
Copy link
Contributor

Add wrapper for zivid.calibration.pixel_mapping() as well as zivid.experimental.PixelMapping

Comment on lines +69 to +75
.def(
"pixel_mapping",
[](ReleasableCamera &releasableCamera, const Zivid::Settings &settings) {
return Zivid::Experimental::Calibration::pixelMapping(releasableCamera.impl(), settings);
},
py::arg("camera"),
py::arg("settings"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is experimental in C++, and thus should really be in a experimental namespace in Python. It seems we have done a bad mistake for the other ones abvove here by not separating Experimental to a separate namespace/module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I guess this is internal code only and that the public part is infact experimental. Then it looks Ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is how we've done it before, with for example infield correction.

Comment on lines 21 to 23
@row_stride.setter
def row_stride(self, value):
self.__impl.row_stride = value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these setters? We dont have that in C++? Just the consturctor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, leave it to only getters for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +8 to +11
assert isinstance(pixel_mapping_handle.row_stride, int)
assert isinstance(pixel_mapping_handle.col_stride, int)
assert isinstance(pixel_mapping_handle.row_offset, float)
assert isinstance(pixel_mapping_handle.col_offset, float)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also check the exact values that are used, IMO. To ensure that it is mapped correctly in the pybind wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 12 to 15
def __init__(self, row_stride=1, col_stride=1, row_offset=0, col_offset=0) -> None:
self.__impl = _zivid.PixelMapping(
row_stride, col_stride, row_offset, col_offset
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do row_stride=1, col_stride=1, row_offset=0.0, col_offset=0.0 to be consistent with the types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required when mapping an index in a subsampled point cloud to e.g. a full resolution 2D image.
"""

def __init__(self, row_stride=1, col_stride=1, row_offset=0, col_offset=0) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't generally do type hints in this repo, so you can drop the "-> None".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@torbsorb torbsorb force-pushed the MISC-2023-12-03-add-pixel-mapping branch 2 times, most recently from 1bc2593 to 4c25ea5 Compare December 15, 2023 09:06
camera._Camera__impl, # pylint: disable=protected-access
_to_internal_settings(settings),
)
return PixelMapping(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a bit strange that we here have a _zivid.PixelMapping, but we don't pass that into the constructor, instead the constructor creates another _zivid.PixelMapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It constructs and returns zivid.experimental._pixel_mapping which is mapped to zivid.experimental.PixelMapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a chicken and egg story here, right Eskil?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that we really needed two constructors:

  • One for the user that takes the four numbers
  • One for us that takes a _zivid.PixelMapping

Since Python can't really overload constructors, we opted to only have the first one.
Open to better solutions, but I think this is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm fine with keeping this. We can find a cleaner solution in the future.

Copy link
Contributor

@johningve johningve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Add wrapper for `zivid.calibration.pixel_mapping()` as
well as `zivid.experimental.PixelMapping`
@torbsorb torbsorb force-pushed the MISC-2023-12-03-add-pixel-mapping branch from aedd840 to 5728960 Compare December 15, 2023 12:00
@torbsorb torbsorb merged commit 8ed4df6 into master Dec 15, 2023
21 checks passed
@torbsorb torbsorb deleted the MISC-2023-12-03-add-pixel-mapping branch December 15, 2023 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants