halcon的find_shape_model的输出的Score的计算原理
时间: 2024-04-07 15:30:49 浏览: 25
Halcon的find_shape_model函数的输出结果中,Score表示匹配的得分,其计算原理如下:
首先,对于模板和待匹配图像的每个匹配位置,Halcon会计算出一个局部相似度得分,表示模板在该位置与待匹配图像的相似度。这个得分是通过计算模板区域和待匹配图像区域之间的灰度差异来计算的。
然后,Halcon会将这些局部相似度得分进行汇总,得到一个全局相似度得分,表示模板与待匹配图像的相似度。这个得分是通过计算模板区域和待匹配图像区域之间的灰度差异的平均值来计算的。
最后,Halcon将全局相似度得分转换为一个匹配得分,即Score。这个得分的计算方法如下:
Score = (1 - GlobalScore) * 100
其中,GlobalScore是全局相似度得分,取值范围为0到1,表示模板与待匹配图像的相似度。Score的取值范围为0到100,表示匹配的得分,分数越高表示匹配越好,越接近100表示匹配非常好。
相关问题
find_shape_model(Image : : ModelID, AngleStart, AngleExtent, MinScore, NumMatches, MaxOverlap, SubPixel, NumLevels, Greediness : Row, Column, Angle, Score)作用
find_shape_model是HALCON中用于基于形状匹配的模板匹配的算子,它可以根据输入的模型ID和其他相关参数,在图像中找到与模板最相似的区域,并返回匹配结果的位置、旋转角度和相似度等信息。
具体来说,find_shape_model算子可以通过以下参数进行调用:
- Image:输入的待匹配图像。
- ModelID:用于匹配的模型的ID。
- AngleStart:旋转起始角度,用于指定旋转的起始角度。
- AngleExtent:旋转角度范围,用于指定旋转角度的范围。
- MinScore:最小相似度阈值,用于过滤相似度较低的匹配结果。
- NumMatches:最大匹配数量,用于限制匹配结果的数量。
- MaxOverlap:最大重叠度,用于过滤重叠度较高的匹配结果。
- SubPixel:亚像素精度,用于指定匹配结果的精度级别。
- NumLevels:金字塔层数,用于指定图像金字塔的层数。
- Greediness:贪婪程度,用于指定匹配结果的贪婪程度。
- Row:输出参数,匹配结果的行坐标。
- Column:输出参数,匹配结果的列坐标。
- Angle:输出参数,匹配结果的旋转角度。
- Score:输出参数,匹配结果的相似度。
在运行该算子时,它会根据输入的模型ID和其他相关参数,在图像中找到与模板最相似的区域,并返回匹配结果的位置、旋转角度和相似度等信息。AngleStart、AngleExtent和NumLevels用于指定模型在不同旋转角度下的特征信息,MinScore和MaxOverlap用于过滤匹配结果,SubPixel用于指定匹配结果的精度级别,Greediness用于指定匹配结果的贪婪程度,NumMatches用于限制匹配结果的数量,Row、Column、Angle和Score用于保存匹配结果的位置、旋转角度和相似度等信息。
需要注意的是,find_shape_model算子仅能处理基于形状匹配的模板匹配模型,且需要在create_shape_model算子中指定NumLevels参数。在使用该算子前,应该先创建模型并训练模型。
* This example shows how to use shape-based matching * in order to find a model region and use it for * further tasks. * Here, the additional task consists of reading text * within a certain region, wherefore the image has * to be aliged using the matching transformation. * * Initialization. dev_update_window ('off') dev_close_window () * Initialize visualization. read_image (ReferenceImage, 'board/board_01') get_image_size (ReferenceImage, Width, Height) initialize_visualization (Width / 2, Height / 2, WindowHandle, WindowHandleText) disp_continue_message (WindowHandle, 'black', 'true') disp_description_text (WindowHandleText) * * Define ROIs: * ROI for the shape model. dev_set_window (WindowHandle) dev_display (ReferenceImage) gen_rectangle1 (ROIModel, 60, 535, 185, 900) dev_display (ROIModel) * ROI for the text. gen_rectangle1 (ROIText, 445, 585, 590, 765) dev_display (ROIText) disp_model_message (WindowHandle) stop () * * Prepare the shape-based matching model. reduce_domain (ReferenceImage, ROIModel, ModelImage) * Create shape model and set parameters (offline step). create_generic_shape_model (ModelHandle) * Train the shape model. train_generic_shape_model (ModelImage, ModelHandle) * * Prepare the text model. create_text_model_reader ('auto', 'Industrial_0-9A-Z_Rej.omc', TextModel) * * We look for the reference transformation which we will need * for the alignment. We can extract it by finding the instance * on the reference image. * Set find parameters. set_generic_shape_model_param (ModelHandle, 'num_matches', 1) set_generic_shape_model_param (ModelHandle, 'min_score', 0.5) find_generic_shape_model (ReferenceImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DModel) * * Find the object in other images (online step). for i := 1 to 9 by 1 read_image (SearchImage, 'board/board_' + i$'02') find_generic_shape_model (SearchImage, ModelHandle, MatchResultID, Matches) get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', HomMat2DMatch) * Compute the transformation matrix. hom_mat2d_invert (HomMat2DMatch, HomMat2DMatchInvert) hom_mat2d_compose (HomMat2DModel, HomMat2DMatchInvert, TransformationMatrix) affine_trans_image (SearchImage, ImageAffineTrans, TransformationMatrix, 'constant', 'false') * * Visualization. dev_set_window (WindowHandle) dev_display (SearchImage) get_generic_shape_model_result_object (InstanceObject, MatchResultID, 'all', 'contours') dev_display (InstanceObject) * * Reading text and numbers on the aligned image. reduce_domain (ImageAffineTrans, ROIText, ImageOCR) find_text (ImageOCR, TextModel, TextResultID) get_text_object (Characters, TextResultID, 'all_lines') get_text_result (TextResultID, 'class', RecognizedText) * * Visualization. dev_set_window (WindowHandleText) dev_display (ImageAffineTrans) dev_set_colored (12) dev_display (Characters) disp_finding_text (Characters, WindowHandle, WindowHandleText, RecognizedText) wait_seconds (0.5) endfor disp_end_of_program_message (WindowHandle, 'black', 'true') stop () dev_close_window ()
这段代码是一个示例程序,演示了如何使用基于形状匹配的方法来找到一个模型区域,并将其用于进一步的任务。在这个示例中,额外的任务是在一个固定的区域内读取文本,在这种情况下,需要使用匹配变换来对图像进行对齐。
代码的具体步骤如下:
1. 初始化程序,并展示图像。
2. 定义形状模型和文本区域的ROI。
3. 准备形状模型。
4. 创建形状模型,并训练模型。
5. 准备文本模型。
6. 查找参考图像中的实例,并提取变换矩阵。
7. 在其他图像中查找实例,并计算变换矩阵。
8. 对齐图像,并在对齐后的图像中读取文本。
9. 可视化结果。
10. 结束程序。
这段代码主要使用了HALCON库中的形状匹配和文本识别功能,通过这些功能实现了对一个模型区域的识别和定位,并在其他图像中查找并对齐该模型区域。同时,代码还使用了HALCON库中的可视化功能,将结果展示给用户。