HALCON’s shape-based matching can create templates from both images and CAD data. You can import CAD files into HALCON with the operator read_contour_xld_dxf:
read_contour_xld_dxf (Contours, ‘cadfile.dxf’, [], [], DxfStatus)
The result is an XLD contour (see figure 1 below). To create a shape model from an XLD contour, you can use the operator create_shape_model_xld. The contour, however, needs to match the scale of the calibrated image. You might recall that the operators to calibrate images (image_to_world_plane/gen_image_to_world_plane_map) provide a parameter for the pixel size (in addition to the camera parameters and camera pose):
image_to_world_plane (Image, ImageWorld, CamParam, Pose, .. , PixelSize, .. )
The unit of PixelSize is ‘m’ per pixel. If the coordinates in the dxf file are given in ‘m’, you have to resize the contours as follows:
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_scale (HomMat2DIdentity, 1./PixelSize, 1./PixelSize, 0, 0, HomMat2DScale)
affine_trans_contour_xld (Contours, ContoursScaled, HomMat2DScale)
Subsequently, you can create the model with create_shape_model_xld:
create_shape_model_xld(ContoursScaled, …, ‘ignore_local_polarity’, MinContrast, ModelID)
Note that the model has to be created using the mode ‘ignore_local_polarity’, since no gray scale information is available. While you can use the model as is, it is generally recommended to adjust the polarity with set_shape_model_metric (see examples on the details of its usage).
Since no image is used to create the shape model, you also have to set the parameter MinContrast manually (that is contrast threshold applied to the search image). To estimate a suitable value, you can use the operator determine_shape_model_param while passing a test image. You can also adjust MinContrast with set_shape_model_param after the model has been created.