Operator Reference

gen_structured_light_patternT_gen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern (Operator)

gen_structured_light_patternT_gen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern — Generate the pattern images to be displayed in a structured light setup.

Signature

gen_structured_light_pattern( : PatternImages : StructuredLightModel : )

Herror T_gen_structured_light_pattern(Hobject* PatternImages, const Htuple StructuredLightModel)

void GenStructuredLightPattern(HObject* PatternImages, const HTuple& StructuredLightModel)

HImage HStructuredLightModel::GenStructuredLightPattern() const

static void HOperatorSet.GenStructuredLightPattern(out HObject patternImages, HTuple structuredLightModel)

HImage HStructuredLightModel.GenStructuredLightPattern()

def gen_structured_light_pattern(structured_light_model: HHandle) -> HObject

Description

gen_structured_light_patterngen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern generates the pattern images that need to be displayed or projected in a structured light setup. Several parameters such as the width and height of the images, the pattern type and the minimal stripe width need to be set in advance in the model StructuredLightModelStructuredLightModelStructuredLightModelstructuredLightModelstructured_light_model using set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param. Dependent on the set parameters of the StructuredLightModelStructuredLightModelStructuredLightModelstructuredLightModelstructured_light_model, the number and the appearance of the pattern images vary.

In general, the pattern images can be divided into four groups of images:

  • Normalization images

  • Gray code images

  • Phase shift images

  • Single stripe images

General information about the image types

Normalization images:

Decoding of Gray code images relies upon being able to know whether a camera pixel observed a surface point illuminated by a white stripe or a dark stripe of the displayed or projected patterns. To allow a robust decoding even for large variations in surface reflectance or brightness, normalization images are used to simplify the process of identifying light and dark regions. The simplest but in most cases also sufficient approach is to generate one entirely black and one entirely white image. During the decoding of the acquired camera images (see decode_structured_light_patterndecode_structured_light_patternDecodeStructuredLightPatternDecodeStructuredLightPatterndecode_structured_light_pattern) all Gray code images are then compared with the mean of the dark and the bright image and a pixel within the image is classified as bright if its gray value is greater or equal the previously calculated mean.

Another approach is to use the Gray code images as explained in the next section and generate an inverted version of these images. A pixel is then classified as light, if its gray value in the first image is brighter than the gray value of the inverted version.

Gray code images:

Before performing any practical task such as detecting defects, the first step in any structured light measurement process is to find a mapping between the pixel plane of the camera and the pixel plane of the monitor or projector. This can be achieved by displaying a series of images that uniquely encode the rows and columns of the monitor or projector. Since Gray code images have some advantages compared to other pattern types, they are typically used for the encoding. An example of a series of vertical and horizontal Gray code images can be seen in the subsequent figure.

Image series of vertical and horizontal Gray code images as generated by gen_structured_light_patterngen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern. The patterns are typically displayed on the monitor or projector from the coarsest pattern to the finest one while the stripe width is halved at each level.

Although using Gray code images is a very simple, yet suitable approach, it comes with certain limitations. One drawback is that often many Gray code images are required to achieve a spatial resolution sufficient for practical applications. However, with increasingly finer resolution of the stripes, a correct decoding becomes harder and harder because of blurring effects introduced by the optics involved in the measurement process. To overcome these limitations, the third group of pattern images (phase shift images) can be generated.

Phase shift images:

Phase shift images usually use periodic patterns such as sine or cosine waves to reconstruct the phase and in combination with Gray code images the correspondences between the monitor or projector and the camera coordinates. To allow a decoding that is robust despite variations in the surface reflectance or brightness and has a relaxed noise influence, four phase shift images per orientation (vertical or horizontal) are generated. Each image is a cosine wave with phase shifts of , where .

Image series of vertical and horizontal phase shift images as generated by gen_structured_light_patterngen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern.

The main advantage of using phase shift images, is that in contrast to Gray code images subpixel-precise correspondences between the monitor or projector and the camera coordinates can be calculated. Since the images are periodic, the encoding is unique up to integer multiples of the period length. In order to achieve a unique encoding over the entire image, the combination with the Gray code image is necessary.

Single stripe images:

Single stripe images are dark with one bright stripe. The bright stripe is shifted over the images such that each monitor or projector pixel is contained in exactly one stripe. To decide which bright stripe is reflected in the area observed by a camera pixel, the brightest pixel value within the sequence of single stripe images is chosen during decoding. This allows a decoding that is robust despite variations in the surface reflectance.

Image series of vertical and horizontal single stripe images as generated by gen_structured_light_patterngen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern for 'pattern_type'"pattern_type""pattern_type""pattern_type""pattern_type" set to 'single_stripe'"single_stripe""single_stripe""single_stripe""single_stripe".

The Gray code sequence and phase are then used to refine the position within the found single stripe. Thus, while additional single stripe images are generated, the number of created Gray code images will typically decrease slightly.

Image series of vertical and horizontal Gray code images as generated by gen_structured_light_patterngen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern for 'pattern_type'"pattern_type""pattern_type""pattern_type""pattern_type" set to 'single_stripe'"single_stripe""single_stripe""single_stripe""single_stripe".

Information about the generation of the image types

Generating the normalization images:

As mentioned above, HALCON offers two different kinds of normalization images. By default, the 'normalization'"normalization""normalization""normalization""normalization" method is set to 'global'"global""global""global""global" which results in the generation of an entirely black and an entirely white image. To change the method such that each Gray code is additionally inverted, set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param has to be called using the method 'inverted_pattern'"inverted_pattern""inverted_pattern""inverted_pattern""inverted_pattern".

The main advantage of using a global normalization is that the number of images is significantly smaller while simultaneously providing satisfying results. Only in cases of partially specular surfaces, the other method might be more robust and should be chosen if the global normalization leads to wrong decoding results.

Generating the Gray code images:

The size, the number and the appearance of the Gray code images is dependent on the following parameters (see set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param): 'pattern_width'"pattern_width""pattern_width""pattern_width""pattern_width", 'pattern_height'"pattern_height""pattern_height""pattern_height""pattern_height", 'min_stripe_width'"min_stripe_width""min_stripe_width""min_stripe_width""min_stripe_width", and 'pattern_orientation'"pattern_orientation""pattern_orientation""pattern_orientation""pattern_orientation".

The first two parameters determine the size of the generated Gray code images and should usually be set to the size of the monitor or projector that is used to display the pattern images. The parameter 'min_stripe_width'"min_stripe_width""min_stripe_width""min_stripe_width""min_stripe_width" sets the width (in pixels) of the finest stripe of the pattern images that are generated. Additionally, all three parameters have a major influence on the number of created Gray code images.

Let be the maximum stripe width in vertical direction and be the maximum stripe width in horizontal direction. Then the number of Gray code images with stripes oriented in one of the two directions (either horizontal or vertical) is given by

The parameter 'pattern_orientation'"pattern_orientation""pattern_orientation""pattern_orientation""pattern_orientation" sets the orientation of the Gray code (and phase shift) images that are generated. By default, images with vertical stripes as well as images with horizontal stripes are created. It is also possible to generate images with stripes having only one of the two directions. For structured light models of type 'deflectometry', this is not recommended, because changes in the surface can then only be detected in one direction. Solely, if changes on the surface should be ignored or if defects are to be expected in only one direction, this parameter should be changed using set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param. In constrast, structured light models of type '3d_reconstruction' need both directions only during the calibration process (for further details please refer to the example program on structured light calibration). In the online process, setting 'pattern_orientation'"pattern_orientation""pattern_orientation""pattern_orientation""pattern_orientation" to 'vertical'"vertical""vertical""vertical""vertical" is recommended for speed, since fewer images are necessary than for 'both'"both""both""both""both" and reconstruct_surface_structured_lightreconstruct_surface_structured_lightReconstructSurfaceStructuredLightReconstructSurfaceStructuredLightreconstruct_surface_structured_light uses only the vertical correspondence image.

Generating the phase shift images:

Since phase shift images are suitable to overcome the practical limitations of Gray code images their generation is recommended and enabled by default.

In case that the accuracy using Gray code images only is sufficient, the creation of phase shift images can be deactivated using set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param by setting the 'pattern_type'"pattern_type""pattern_type""pattern_type""pattern_type" to the value 'gray_code'"gray_code""gray_code""gray_code""gray_code".

Generating the single stripe images:

In case that using Gray code and phase shift images only is not robust enough (this might happen, for example, on semi-specular surfaces), the creation of single stripe images can be activated using set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param by setting the 'pattern_type'"pattern_type""pattern_type""pattern_type""pattern_type" to the value 'single_stripe'"single_stripe""single_stripe""single_stripe""single_stripe".

The number and the appearance of the single stripe images depends on the parameter 'single_stripe_width'"single_stripe_width""single_stripe_width""single_stripe_width""single_stripe_width" which sets the width in pixels (see set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param).

While additional single stripe images are generated, the number of created Gray code images will typically decrease slightly. To calculate the number of Gray code images, 'max_stripe_width'"max_stripe_width""max_stripe_width""max_stripe_width""max_stripe_width" is replaced by 'single_stripe_width'"single_stripe_width""single_stripe_width""single_stripe_width""single_stripe_width" in the formula above.

The use of these images is described in the introduction to the chapter Inspection / Structured Light.

Execution Information

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Processed without parallelization.

This operator modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

Parameters

PatternImagesPatternImagesPatternImagespatternImagespattern_images (output_object)  (multichannel-)image(-array) objectHImageHObjectHObjectHobject * (byte)

Generated pattern images.

StructuredLightModelStructuredLightModelStructuredLightModelstructuredLightModelstructured_light_model (input_control, state is modified)  structured_light_model HStructuredLightModel, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Handle of the structured light model.

Example (HDevelop)

* Create the model
create_structured_light_model ('deflectometry', StructuredLightModel)
* Set the size of the monitor
set_structured_light_model_param (StructuredLightModel, \
                                  'pattern_width', 1600)
set_structured_light_model_param (StructuredLightModel, \
                                  'pattern_height', 1200)
* Set the smallest width of the stripes in the pattern
set_structured_light_model_param (StructuredLightModel, \
                                  'min_stripe_width', 8)
* Generate the patterns to project
gen_structured_light_pattern (PatternImages, StructuredLightModel)
* Decode the camera images
decode_structured_light_pattern (CameraImages, StructuredLightModel)

Result

The operator gen_structured_light_patterngen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatterngen_structured_light_pattern returns the value 2 ( H_MSG_TRUE) if the given parameters are valid. Otherwise, an exception will be raised.

Possible Predecessors

set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamset_structured_light_model_param

Possible Successors

decode_structured_light_patterndecode_structured_light_patternDecodeStructuredLightPatternDecodeStructuredLightPatterndecode_structured_light_pattern

See also

create_structured_light_modelcreate_structured_light_modelCreateStructuredLightModelCreateStructuredLightModelcreate_structured_light_model, get_structured_light_model_paramget_structured_light_model_paramGetStructuredLightModelParamGetStructuredLightModelParamget_structured_light_model_param, get_structured_light_objectget_structured_light_objectGetStructuredLightObjectGetStructuredLightObjectget_structured_light_object

Module

3D Metrology