Operators |
gen_structured_light_pattern — Generate the pattern images to be displayed in a structured light setup.
gen_structured_light_pattern( : PatternImages : StructuredLightModel : )
gen_structured_light_pattern 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 StructuredLightModel using set_structured_light_model_param. Dependent on the set parameters of the StructuredLightModel, the number and the appearance of the pattern images vary.
In general, the pattern images can be divided into three groups of images:
Normalization images
Gray code images
Phase shift images
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_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. 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.
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 .
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.
Generating the normalization images:
As mentioned above, HALCON offers two different kinds of normalization images. By default, the 'normalization' method is set to '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_param has to be called using the method '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_param): 'pattern_width' , 'pattern_height' , 'min_stripe_width' and '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' 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
The parameter '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_param.
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_param by setting the 'pattern_type' to the value 'gray_code' .
The use of these images is described in the introduction to the chapter Inspection / Structured Light.
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.Generated pattern images.
Handle of the structured light model.
* 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) * Clean up clear_structured_light_model (StructuredLightModel)
The operator gen_structured_light_pattern returns the value 2 (H_MSG_TRUE) if the given parameters are valid. Otherwise, an exception will be raised.
set_structured_light_model_param
decode_structured_light_pattern
create_structured_light_model, get_structured_light_model_param, get_structured_light_object
3D Metrology
Operators |