gen_structured_light_patternT_gen_structured_light_patternGenStructuredLightPatternGenStructuredLightPattern (Operator)

Name

gen_structured_light_patternT_gen_structured_light_patternGenStructuredLightPatternGenStructuredLightPattern — 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()

Description

gen_structured_light_patterngen_structured_light_patternGenStructuredLightPatternGenStructuredLightPatternGenStructuredLightPattern generates the pattern images that need to be displayed 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 StructuredLightModelStructuredLightModelStructuredLightModelStructuredLightModelstructuredLightModel using set_structured_light_model_paramset_structured_light_model_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam. Dependent on the set parameters of the StructuredLightModelStructuredLightModelStructuredLightModelStructuredLightModelstructuredLightModel, the number and the appearance of the pattern images vary.

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

General information about the image types

Normalization images:

Decoding of Gray code images relies upon being able to know whether a pixel is in a region where a light stripe is reflected or where a dark stripe is reflected. To allow a robust decoding even for large variations in the surface reflectance, 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_patternDecodeStructuredLightPatternDecodeStructuredLightPatternDecodeStructuredLightPattern) 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. This can be achieved by displaying a series of images that uniquely encode the rows and columns of the monitor. 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_patternGenStructuredLightPatternGenStructuredLightPatternGenStructuredLightPattern. The patterns are typically displayed on the monitor 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 and the camera coordinates. To allow a decoding that is robust despite variations in the surface reflectance 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_patternGenStructuredLightPatternGenStructuredLightPatternGenStructuredLightPattern.

The main advantage of using phase shift images, is that in contrast to Gray code images subpixel-precise correspondences between the monitor 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 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_patternGenStructuredLightPatternGenStructuredLightPatternGenStructuredLightPattern 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_patternGenStructuredLightPatternGenStructuredLightPatternGenStructuredLightPattern 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_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam 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_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam): '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 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. However, 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_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam.

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_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam 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_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam 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_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam).

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

This operator modifies the state of the following input parameter:

The value of this parameter may not be shared across multiple threads without external synchronization.

Parameters

PatternImagesPatternImagesPatternImagesPatternImagespatternImages (output_object)  (multichannel-)image(-array) objectHImageHImageHobject * (byte)

Generated pattern images.

StructuredLightModelStructuredLightModelStructuredLightModelStructuredLightModelstructuredLightModel (input_control, state is modified)  structured_light_model HStructuredLightModel, HTupleHTupleHtuple (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_patternGenStructuredLightPatternGenStructuredLightPatternGenStructuredLightPattern 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_paramSetStructuredLightModelParamSetStructuredLightModelParamSetStructuredLightModelParam

Possible Successors

decode_structured_light_patterndecode_structured_light_patternDecodeStructuredLightPatternDecodeStructuredLightPatternDecodeStructuredLightPattern

See also

create_structured_light_modelcreate_structured_light_modelCreateStructuredLightModelCreateStructuredLightModelCreateStructuredLightModel, get_structured_light_model_paramget_structured_light_model_paramGetStructuredLightModelParamGetStructuredLightModelParamGetStructuredLightModelParam, get_structured_light_objectget_structured_light_objectGetStructuredLightObjectGetStructuredLightObjectGetStructuredLightObject

Module

3D Metrology