halcon获取匹配轮廓的坐标
时间: 2023-10-29 21:06:03 浏览: 99
要获取匹配轮廓的坐标,可以使用Halcon中的gen_contour_region_xld函数将匹配结果转换为轮廓,并使用get_contour_xld和get_contour_global_xld函数获取轮廓的坐标信息。具体的代码示例如下:
```python
# 获取匹配轮廓的坐标
match_result = find_shape_model(image, model_image, 0, 0, 0.5, 1, 0.5, 'use_polarity')
contours = gen_contour_region_xld(match_result)
x, y = get_contour_global_xld(contours, 'centroid')
row, col = get_contour_xld(contours)
```
其中,find_shape_model函数用于进行模板匹配,返回匹配结果;gen_contour_region_xld函数将匹配结果转换为轮廓;get_contour_global_xld函数获取轮廓的中心点坐标;get_contour_xld函数获取轮廓的所有点坐标。
相关问题
halcon 模板匹配轮廓
您好!对于Halcon模板匹配中的轮廓匹配,可以使用XLD(eXtended Line Data)来表示和处理匹配结果的轮廓。
在Halcon中,使用`find_shape_model()`函数进行模板匹配,并通过设置`GenParamName('matching')`为'contour'来使其返回轮廓匹配结果。然后,您可以使用`get_shape_matching_result()`函数获取匹配结果的XLD。
以下是一个示例代码:
```python
import halcon as ha
# 读取模板图像和待匹配图像
template_image = ha.read_image('template.jpg')
match_image = ha.read_image('match.jpg')
# 创建模板
model_id = ha.create_shape_model(template_image, 'auto', 0, 360, 'auto', 'none', 'use_polarity')
# 进行模板匹配
result_id = ha.find_shape_model(match_image, model_id, 0, 360, 0.5, 1, 0.5, 'contour')
# 获取匹配结果的轮廓
contours = ha.get_shape_matching_result(result_id, 'all', 0)
# 显示匹配结果
ha.disp_image(match_image)
ha.set_color('red')
ha.disp_xld(contours)
# 清除模板和结果
ha.clear_shape_model(model_id)
ha.clear_shape_model(result_id)
```
这是一个简单的示例,您可以根据实际情况进行修改和扩展。希望对您有帮助!如果您有其他问题,请随时提问。
halcon 模板匹配轮廓xld
您好!对于Halcon模板匹配中的轮廓匹配,可以使用XLD(eXtended Line Data)来表示和处理匹配结果的轮廓。
在Halcon中,使用`find_shape_model()`函数进行模板匹配,并通过设置`GenParamName('matching')`为'contour'来使其返回轮廓匹配结果。然后,您可以使用`get_shape_matching_result()`函数获取匹配结果的XLD。
以下是一个示例代码:
```python
import halcon as ha
# 读取模板图像和待匹配图像
template_image = ha.read_image('template.jpg')
match_image = ha.read_image('match.jpg')
# 创建模板
model_id = ha.create_shape_model(template_image, 'auto', 0, 360, 'auto', 'none', 'use_polarity')
# 进行模板匹配
result_id = ha.find_shape_model(match_image, model_id, 0, 360, 0.5, 1, 0.5, 'contour')
# 获取匹配结果的轮廓
contours = ha.get_shape_matching_result(result_id, 'all', 0)
# 显示匹配结果
ha.disp_image(match_image)
ha.set_color('red')
ha.disp_xld(contours)
# 清除模板和结果
ha.clear_shape_model(model_id)
ha.clear_shape_model(result_id)
```
这是一个简单的示例,您可以根据实际情况进行修改和扩展。希望对您有帮助!如果您有其他问题,请随时提问。