-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #251 from zivid/MISC-2023-12-03-add-pixel-mapping
Add PixelMapping
- Loading branch information
Showing
10 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ | |
infield_correction, | ||
Matrix4x4, | ||
data_model, | ||
PixelMapping, | ||
projection, | ||
ProjectedImage, | ||
presets, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from zivid.experimental._pixel_mapping import PixelMapping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Module for experimental pixel mapping. This API may change in the future.""" | ||
|
||
import _zivid | ||
|
||
|
||
class PixelMapping: | ||
"""Pixel mapping from subsampled to full resolution. | ||
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.0, col_offset=0.0): | ||
self.__impl = _zivid.PixelMapping( | ||
row_stride, col_stride, row_offset, col_offset | ||
) | ||
|
||
@property | ||
def row_stride(self): | ||
return self.__impl.row_stride() | ||
|
||
@property | ||
def col_stride(self): | ||
return self.__impl.col_stride() | ||
|
||
@property | ||
def row_offset(self): | ||
return self.__impl.row_offset() | ||
|
||
@property | ||
def col_offset(self): | ||
return self.__impl.col_offset() | ||
|
||
def __str__(self): | ||
return str(self.__impl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <Zivid/Experimental/PixelMapping.h> | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace ZividPython | ||
{ | ||
void wrapClass(pybind11::class_<Zivid::Experimental::PixelMapping> pyClass) | ||
{ | ||
pyClass.def(pybind11::init(), "Initializes all values to their defaults") | ||
.def(pybind11::init<int, int, float, float>()) | ||
.def("row_stride", &Zivid::Experimental::PixelMapping::rowStride) | ||
.def("col_stride", &Zivid::Experimental::PixelMapping::colStride) | ||
.def("row_offset", &Zivid::Experimental::PixelMapping::rowOffset) | ||
.def("col_offset", &Zivid::Experimental::PixelMapping::colOffset); | ||
} | ||
} // namespace ZividPython |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <Zivid/Experimental/PixelMapping.h> | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace ZividPython | ||
{ | ||
void wrapClass(pybind11::class_<Zivid::Experimental::PixelMapping> pyClass); | ||
} // namespace ZividPython |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
def test_pixel_mapping(file_camera): | ||
from zivid.experimental.calibration import pixel_mapping | ||
from zivid.settings import Settings | ||
|
||
pixel_mapping_handle = pixel_mapping( | ||
camera=file_camera, settings=Settings(acquisitions=[Settings.Acquisition()]) | ||
) | ||
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) | ||
assert pixel_mapping_handle.row_stride == 1 | ||
assert pixel_mapping_handle.col_stride == 1 | ||
assert pixel_mapping_handle.row_offset == 0.0 | ||
assert pixel_mapping_handle.col_offset == 0.0 | ||
|
||
blue_subsample2x2_settings = Settings() | ||
blue_subsample2x2_settings.acquisitions.append(Settings.Acquisition()) | ||
blue_subsample2x2_settings.sampling.pixel = Settings.Sampling.Pixel.blueSubsample2x2 | ||
pixel_mapping_handle = pixel_mapping( | ||
camera=file_camera, settings=blue_subsample2x2_settings | ||
) | ||
assert pixel_mapping_handle.row_stride == 2 | ||
assert pixel_mapping_handle.col_stride == 2 | ||
assert pixel_mapping_handle.row_offset == 0.0 | ||
assert pixel_mapping_handle.col_offset == 0.0 | ||
|
||
red_subsample2x2_settings = Settings() | ||
red_subsample2x2_settings.acquisitions.append(Settings.Acquisition()) | ||
red_subsample2x2_settings.sampling.pixel = Settings.Sampling.Pixel.redSubsample2x2 | ||
pixel_mapping_handle = pixel_mapping( | ||
camera=file_camera, settings=red_subsample2x2_settings | ||
) | ||
assert pixel_mapping_handle.row_stride == 2 | ||
assert pixel_mapping_handle.col_stride == 2 | ||
assert pixel_mapping_handle.row_offset == 1.0 | ||
assert pixel_mapping_handle.col_offset == 1.0 |