ClassesClassesClassesClasses | | | | Operators

reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo (Operator)

Name

reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo — Reconstruct surface from calibrated multi-view stereo images.

Signature

reconstruct_surface_stereo(Images : : StereoModelID : ObjectModel3D)

Herror reconstruct_surface_stereo(const Hobject Images, const Hlong StereoModelID, Hlong* ObjectModel3D)

Herror T_reconstruct_surface_stereo(const Hobject Images, const Htuple StereoModelID, Htuple* ObjectModel3D)

Herror reconstruct_surface_stereo(Hobject Images, const HTuple& StereoModelID, Hlong* ObjectModel3D)

void HObjectModel3D::ReconstructSurfaceStereo(const HImageArray& Images, const HStereoModel& StereoModelID)

HObjectModel3D HStereoModel::ReconstructSurfaceStereo(const HImageArray& Images) const

void ReconstructSurfaceStereo(const HObject& Images, const HTuple& StereoModelID, HTuple* ObjectModel3D)

void HObjectModel3D::ReconstructSurfaceStereo(const HImage& Images, const HStereoModel& StereoModelID)

HObjectModel3D HStereoModel::ReconstructSurfaceStereo(const HImage& Images) const

void HOperatorSetX.ReconstructSurfaceStereo(
[in] IHUntypedObjectX* Images, [in] VARIANT StereoModelID, [out] VARIANT* ObjectModel3D)

void HObjectModel3DX.ReconstructSurfaceStereo(
[in] IHImageX* Images, [in] IHStereoModelX* StereoModelID)

IHObjectModel3DX* HStereoModelX.ReconstructSurfaceStereo([in] IHImageX* Images)

static void HOperatorSet.ReconstructSurfaceStereo(HObject images, HTuple stereoModelID, out HTuple objectModel3D)

void HObjectModel3D.ReconstructSurfaceStereo(HImage images, HStereoModel stereoModelID)

HObjectModel3D HStereoModel.ReconstructSurfaceStereo(HImage images)

Description

The operator reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo reconstructs a surface from multiple images ImagesImagesImagesImagesImagesimages, taken with a calibrated multi-view setup associated to a stereo model StereoModelIDStereoModelIDStereoModelIDStereoModelIDStereoModelIDstereoModelID. The reconstructed surface is stored in a HALCON 3D object model and a handle to it is returned in ObjectModel3DObjectModel3DObjectModel3DObjectModel3DObjectModel3DobjectModel3D.

Reconstruction algorithm

The underlying surface reconstruction algorithm is based on fusing the information obtained from multiple binocular stereo depth maps. For this, the algorithm internally calls a HALCON disparity operator (currently binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity) for each image pair from a predefined list of pairs. The disparity information is converted to X, Y, and Z coordinate images in the coordinate system of the from-camera. For this, reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo internally calls disparity_image_to_xyzdisparity_image_to_xyzDisparityImageToXyzdisparity_image_to_xyzDisparityImageToXyzDisparityImageToXyz. Then, for each 3D point, the normal vector is calculated. This is done by fitting a plane through the neighboring 3D points. In contrast to surface_normals_object_model_3dsurface_normals_object_model_3dSurfaceNormalsObjectModel3dsurface_normals_object_model_3dSurfaceNormalsObjectModel3dSurfaceNormalsObjectModel3d, the neighboring points are not determined in 3D but simply in 2D by using the neighboring points in the X, Y, and Z images. The normal vector of each 3D point is then set to the normal vector of the respective plane. In the next step, the X, Y, and Z images as well as the normal vectors are transformed into the common coordinate system that is specified in the camera setup model associated to the stereo model StereoModelIDStereoModelIDStereoModelIDStereoModelIDStereoModelIDstereoModelID. Finally, the transformed coordinate images are sub-sampled and stored in a common point cloud together with the points and normals extracted from other image pairs. Thus, the object model returned in ObjectModel3DObjectModel3DObjectModel3DObjectModel3DObjectModel3DobjectModel3D contains the coordinates and a normal for each reconstructed point.

The so-obtained point cloud can be additionally meshed in a post-processing step. The parameter 'point_meshing'"point_meshing""point_meshing""point_meshing""point_meshing""point_meshing" enables it. If the meshing is enabled, the object model returned in ObjectModel3DObjectModel3DObjectModel3DObjectModel3DObjectModel3DobjectModel3D contains the description of the mesh. Currently, the supported meshing algorithm is based on a Poisson solver (see below). It creates a water-tight mesh, therefore surface regions with missing data are covered by an interpolated mesh.

If only one image pair is processed and no point meshing is enabled, reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo stores a 'xyz_mapping' attribute in ObjectModel3DObjectModel3DObjectModel3DObjectModel3DObjectModel3DobjectModel3D, which reveals the mapping of the reconstructed 3D points to coordinates of the first image of the pair. This attribute is required by operators like segment_object_model_3dsegment_object_model_3dSegmentObjectModel3dsegment_object_model_3dSegmentObjectModel3dSegmentObjectModel3d or object_model_3d_to_xyzobject_model_3d_to_xyzObjectModel3dToXyzobject_model_3d_to_xyzObjectModel3dToXyzObjectModel3dToXyz (with Type='from_xyz_map'"from_xyz_map""from_xyz_map""from_xyz_map""from_xyz_map""from_xyz_map"). In contrast to the single pair case, if two or more image pairs are processed, reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo does not store the 'xyz_mapping' attribute, since single reconstructed points would originate from different image pairs. The presence of the attribute in the output object model can be verified by calling get_object_model_3d_paramsget_object_model_3d_paramsGetObjectModel3dParamsget_object_model_3d_paramsGetObjectModel3dParamsGetObjectModel3dParams with ParamName='has_xyz_mapping'"has_xyz_mapping""has_xyz_mapping""has_xyz_mapping""has_xyz_mapping""has_xyz_mapping".

Preparation and requirements

A camera setup model is associated with the stereo model StereoModelIDStereoModelIDStereoModelIDStereoModelIDStereoModelIDstereoModelID upon its creation with create_stereo_modelcreate_stereo_modelCreateStereoModelcreate_stereo_modelCreateStereoModelCreateStereoModel. The camera setup must contain calibrated information about the cameras, with which the images in the image array ImagesImagesImagesImagesImagesimages were acquired: the I-th image from the array corresponds to the camera with index I-1 from the camera setup; the number of images in the array must be the same as the number of cameras in the camera setup.

A well calibrated camera setup is the main requirement for a precise surface reconstruction, therefore special attention should be paid to obtaining a precise calibration of the cameras in the multi-view stereo setup used. HALCON provides calibration of a multi-view setup with the operator calibrate_camerascalibrate_camerasCalibrateCamerascalibrate_camerasCalibrateCamerasCalibrateCameras. The resulting calibrated camera setup can be accessed with a successive call to get_calib_dataget_calib_dataGetCalibDataget_calib_dataGetCalibDataGetCalibData. Alternatively, for camera setups with known parameters a calibrated camera setup can be created with create_camera_setup_modelcreate_camera_setup_modelCreateCameraSetupModelcreate_camera_setup_modelCreateCameraSetupModelCreateCameraSetupModel.

A bounding box is associated with the stereo model StereoModelIDStereoModelIDStereoModelIDStereoModelIDStereoModelIDstereoModelID and for the surface stereo reconstruction it is required that the bounding box is valid (see set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam for further details). The reconstruction algorithm needs the bounding box for two reasons. First, it uses the projection of the bounding box into both images of each image pair in order to estimate the values for MinDisparity and MaxDisparity, which in turn are used in the internal call to binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity. Secondly, the surface fragments lying outside the bounding box are clipped and are not returned in ObjectModel3DObjectModel3DObjectModel3DObjectModel3DObjectModel3DobjectModel3D. A too large bounding box results in a large difference between MinDisparity and MaxDisparity and this usually slows down the execution of binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity and reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo, respectively. A too small bounding box might result in clipping valid surface areas.

The objects in the scene should expose certain surface properties in order to make the scene suitable for the dense surface reconstruction. First, the surface reflectance should exhibit Lambertian properties as closely as possible (i.e., light falling on the surface is scattered such that its apparent brightness is the same regardless of the angle of view). Secondly, the surface should exhibit enough texture, but no repeating patterns.

The proper selection of image pairs (see set_stereo_model_image_pairsset_stereo_model_image_pairsSetStereoModelImagePairsset_stereo_model_image_pairsSetStereoModelImagePairsSetStereoModelImagePairs) has a important role for the general quality of the surface reconstruction. On the one hand, camera pairs with small base line (small distance between the camera centers) are better suited for the binocular stereo disparity algorithms. Hence, pairs with small base lines should be preferred for acquiring accurate depth information of the scene. On the other hand, the pairs should provide different points of view, such that if one pair does not see a certain area of the surface, it is covered by another pair. Please note that the number of pairs linearly affects the runtime of the operator. Therefore use "as many as needed and just as few as possible" image pairs in order to handle the trade-off between completeness of the surface reconstruction and reconstruction runtime.

Finally, ImagesImagesImagesImagesImagesimages should represent a static scene or they must be taken simultaneously, otherwise the reconstruction of the surface might be impossible.

A summary of the preparation of a stereo model for surface reconstruction:

  1. Obtain calibrated camera setup model (use calibrate_camerascalibrate_camerasCalibrateCamerascalibrate_camerasCalibrateCamerasCalibrateCameras or create_camera_setup_modelcreate_camera_setup_modelCreateCameraSetupModelcreate_camera_setup_modelCreateCameraSetupModelCreateCameraSetupModel and configure it)

  2. Create a stereo model with create_stereo_modelcreate_stereo_modelCreateStereoModelcreate_stereo_modelCreateStereoModelCreateStereoModel by selecting Method='surface_pairwise'"surface_pairwise""surface_pairwise""surface_pairwise""surface_pairwise""surface_pairwise"

  3. Configure the bounding box for the system with set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam (parameter ParamName='bounding_box'"bounding_box""bounding_box""bounding_box""bounding_box""bounding_box")

  4. (optional) Configure further stereo model parameters with set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam

  5. Configure the image pairs with set_stereo_model_image_pairsset_stereo_model_image_pairsSetStereoModelImagePairsset_stereo_model_image_pairsSetStereoModelImagePairsSetStereoModelImagePairs

  6. Acquire images with the calibrated cameras setup and collect them in an image array ImagesImagesImagesImagesImagesimages

  7. Perform surface reconstruction with reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo

  8. (optional) Steps 6. and 7. can be repeated for further scenes

Troubleshooting

The proper configuration of a stereo model is not always easy. If the reconstruction results are not satisfactory, please consult the following hints and ideas:

Run in persistence mode

If you enable the 'persistence'"persistence""persistence""persistence""persistence""persistence" mode of stereo model (call set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam with ParamName='persistence'"persistence""persistence""persistence""persistence""persistence") a successive call to reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo will store intermediate iconic results, which provide additional information.

Check the quality of the calibration

Improve quality of disparity images

After setting the stereo model 'persistence'"persistence""persistence""persistence""persistence""persistence" mode (see above), inspect the disparity and the score images for each image pair. They are returned by get_stereo_model_objectget_stereo_model_objectGetStereoModelObjectget_stereo_model_objectGetStereoModelObjectGetStereoModelObject with a camera index pair [From, To] specifying the pair of interest in the parameter PairIndex and the values 'disparity_image'"disparity_image""disparity_image""disparity_image""disparity_image""disparity_image" and 'score_image'"score_image""score_image""score_image""score_image""score_image" in ObjectName, respectively. If both images exhibit signifiant inperfection (e.g., the disparity image does not really resemble the shape of the object seen in the image), try to adjust the parameters used for the internal call to binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity (these are all parameters with a 'binocular_'"binocular_""binocular_""binocular_""binocular_""binocular_" prefix, which can be modified by set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam) until some improvement is achieved. In some cases, it might be easier to find the proper parameters by testing the affected image pair with binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity directly.

Inspect the used MinDisparity and MaxDisparity

After setting the stereo model 'persistence'"persistence""persistence""persistence""persistence""persistence" mode (see above), call get_stereo_model_paramget_stereo_model_paramGetStereoModelParamget_stereo_model_paramGetStereoModelParamGetStereoModelParam with ParamName='min_disparity'"min_disparity""min_disparity""min_disparity""min_disparity""min_disparity" and ParamName='max_disparity'"max_disparity""max_disparity""max_disparity""max_disparity""max_disparity", respectively. The returned tuples have the same order as the image pairs returned by get_stereo_model_image_pairsget_stereo_model_image_pairsGetStereoModelImagePairsget_stereo_model_image_pairsGetStereoModelImagePairsGetStereoModelImagePairs. Select the minimum and maximum disparity values corresponding to the image pair of interest and check if their difference is unusually large. Compare them with the parameters MinDisparity and MaxDisparity that return good results by using the affected image pair directly in binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity. The internal computation of those values can be corrected by adjusting the values for the bounding box of the stereo model (see set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam)

As already mentioned above, there is a trade-off between completeness of the surface reconstruction on the one hand and reconstruction runtime on the other. In order to improve this trade off, consider the following hints:

Sub-sampling in the rectification step

The stereo model parameter 'rectif_sub_sampling'"rectif_sub_sampling""rectif_sub_sampling""rectif_sub_sampling""rectif_sub_sampling""rectif_sub_sampling" (see set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam) controls the sub-sampling in the rectification step. Setting this factor to a value > 1.0 will reduce the resolution of the rectified images compared to the original images. This factor has a direct impact on the succeeding binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity performance, but it causes loss of image detail. The parameter 'rectif_interpolation'"rectif_interpolation""rectif_interpolation""rectif_interpolation""rectif_interpolation""rectif_interpolation" could have also some impact, but typically not a significant one.

Disparity parameters

Special attention should be paid to the following disparity parameters used for the internal calls to binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity :

MinDisparity and MaxDisparity

A too large difference between MinDisparity and MaxDisparity has direct impact on the performance of binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity. Check their values computed internally by reconstruct_surface_stereoreconstruct_surface_stereoReconstructSurfaceStereoreconstruct_surface_stereoReconstructSurfaceStereoReconstructSurfaceStereo (see above) and try to adapt the stereo model bounding box if needed.

NumLevels,MaskWidth,MaskHeight, Filter,SubDisparity

Each of these parameters of binocular_disparitybinocular_disparityBinocularDisparitybinocular_disparityBinocularDisparityBinocularDisparity have a corresponding stereo model parameter with the prefix 'binocular_'"binocular_""binocular_""binocular_""binocular_""binocular_", and have, some more or others less impact on the performance. Adapting them properly could improve the performance.

Sub-sampling of X,Y,Z data

You can use a larger sub-sampling step for the X,Y,Z data in the last step of the reconstruction algorithm by modifying ParamName='sub_sampling_step'"sub_sampling_step""sub_sampling_step""sub_sampling_step""sub_sampling_step""sub_sampling_step" with set_stereo_model_paramset_stereo_model_paramSetStereoModelParamset_stereo_model_paramSetStereoModelParamSetStereoModelParam. Increasing this step could have moderate performance improvement. However, the reconstructed data will be much sparser.

Note that if a 3D object model is no longer needed or should be overwritten, the memory has to be freed first by calling the operator clear_object_model_3dclear_object_model_3dClearObjectModel3dclear_object_model_3dClearObjectModel3dClearObjectModel3d.

Parallelization

Parameters

ImagesImagesImagesImagesImagesimages (input_object)  singlechannelimage-array objectHImageHImageHImageArrayHImageXHobject (byte)

An image array acquired by the camera setup associated to the stereo model.

StereoModelIDStereoModelIDStereoModelIDStereoModelIDStereoModelIDstereoModelID (input_control)  stereo_model HStereoModel, HTupleHTupleHStereoModel, HTupleHStereoModelX, VARIANTHtuple (integer) (IntPtr) (Hlong) (Hlong) (Hlong) (Hlong)

Handle of the stereo model.

ObjectModel3DObjectModel3DObjectModel3DObjectModel3DObjectModel3DobjectModel3D (output_control)  object_model_3d HObjectModel3D, HTupleHTupleHObjectModel3D, HTupleHObjectModel3DX, VARIANTHtuple (integer) (IntPtr) (Hlong) (Hlong) (Hlong) (Hlong)

Handle to the resulting surface.

Possible Predecessors

create_stereo_modelcreate_stereo_modelCreateStereoModelcreate_stereo_modelCreateStereoModelCreateStereoModel, get_calib_dataget_calib_dataGetCalibDataget_calib_dataGetCalibDataGetCalibData, set_stereo_model_image_pairsset_stereo_model_image_pairsSetStereoModelImagePairsset_stereo_model_image_pairsSetStereoModelImagePairsSetStereoModelImagePairs

Possible Successors

clear_object_model_3dclear_object_model_3dClearObjectModel3dclear_object_model_3dClearObjectModel3dClearObjectModel3d

Alternatives

reconstruct_points_stereoreconstruct_points_stereoReconstructPointsStereoreconstruct_points_stereoReconstructPointsStereoReconstructPointsStereo

References

M. Kazhdan, M. Bolitho, and H. Hoppe: “Poisson Surface Reconstruction.” Symposium on Geometry Processing (June 2006).

Module

3D Metrology


ClassesClassesClassesClasses | | | | Operators