Generating a ZMap
A ZMap is the projection of a point cloud or a mesh on a reference plane, with the distance coded as gray scale values:
□ | They are grayscale images, compatible with all Open eVision 2D libraries. |
□ | They are distortion free, with affine transformation from/to metric coordinate system. |
A depth map (left) and the corresponding ZMap (right),
with default generation parameters and undefined pixel filling enabled
All Open eVision 2D processing are available on ZMaps: filtering, thresholding, blob extraction, measuring with EasyGauge, model matching with EasyFind or EasyMatch…
The EZMapGenerator class implements the conversion from a point cloud or a mesh to a ZMap. With all parameters at default value, the Convert() method automatically chooses the projection plane, the orientation, the map size and the resolution.
Several methods are available to further control the conversion:
● | SetReferencePlane() defines a world space projection plane. The values of the ZMap pixels are the distance of the point cloud to that reference plane. |
By default, the reference plane crosses the origin and is perpendicular to the world Z axis. The plane is defined as a E3DPlane object.
● | SetOrientationVector() sets a world space vector representing the expected direction of the X (width) axis of the ZMap. |
The orientation vector allows to “rotate” the object around the normal of the reference plane.
● | SetOrigin() specifies the world position that is on the ZMap lower left pixel (0, 0). |
● | SetMapSize() defines the resolution (number of pixels in X and Y axis) of the generated ZMap. |
● | SetMapXYResolution() adjusts the X and Y resolution of the ZMap pixels, in world space unit per pixel (for example mm/pixel). This value is used to compute the ZMap size (width and height), depending on the projected size of the point cloud on the reference plane. |
● | SetMapZResolution() sets the Z resolution, in world space unit per pixel unit (gray value). The Z resolution is used to compute the transformation of the distance to the reference plan to the integer 8, 16 or 32 bits pixel value. |
● | EnableFillMode() and SetFillMode() control the options used to fill the "hole" in the ZMap. A hole exists when no 3D point is projected in the ZMap at a pixel position. |
The methods SetReferencePlane(), SetOrientationVector() and SetOrigin() are used to setup the transformation between the world space and the ZMap space. This transformation is rigid (distances are kept).
Alternatively, it is possible to directly set that transformation with the method SetWorldToZMapTransform() using a rigid matrix as parameter. In that case, the reference plane, the orientation vector and the origin parameters are ignored.
The projection of a point cloud on a ZMap,
showing 3 coordinate systems: the world space, the ZMap space and the pixel space.
The method Convert() performs the effective projection of a point cloud (EPointCloud) or a 3D object (EMesh) to the 8 bits and 16 bits ZMap.
When generating a ZMap from a point cloud, only individual points are projected on the ZMap. Depending on the point cloud density and the ZMap resolution, some regions of the ZMap may remain “undefined”. To get around this problem, adjust the resolution of the ZMap (SetMapXYResolution method) to remove “holes” on the ZMap.
By default, the point cloud to ZMap converter performs a filling algorithm. This process tries to replace undefined pixels with locally interpolated values.
Left: high resolution ZMap, the pixel scale exceeds the point cloud density
Center: the same generator parameters with the filling enabled
Right: a reduced ZMap scale/resolution, without filling
As a mesh defines a surface, its triangles are projected onto the ZMap plane. Thus, the generated image shows better continuity and less undefined pixels. However, the generation of a ZMap from an EMesh is slower than from an EPointCloud.