find_shape_model (BinaryImage, 'shape_model', 0, 0, 0.5, 1, 0.5, 'least_squares', 6, Row, Column, Angle, Scale, Score)
时间: 2023-10-07 22:10:08 浏览: 39
这是一个 MATLAB 函数调用语句,用于在二值图像中查找形状模型。该函数的参数解释如下:
- BinaryImage:二值化图像
- 'shape_model':形状模型名称,用于将其保存在磁盘上以备以后使用
- 0、0、0.5、1、0.5:形状模型的参数,它们分别是最小规模、最大规模、规模步长、最小方向、最大方向
- 'least_squares':用于匹配形状模型和图像的匹配度量方法
- 6:形状模型的特征数
- Row、Column、Angle、Scale、Score:输出参数,分别是匹配结果的行坐标、列坐标、旋转角度、缩放比例和匹配得分。
该函数的作用是在二值图像中查找形状模型,并返回形状模型在图像中的匹配结果。
相关问题
halcon缺陷检测例程
以下是一个简单的 Halcon 缺陷检测例程。
首先,我们需要加载 Halcon 库和图像:
```
load_object_model ('shape_model', 'shape_model.sao')
read_image (Image, 'product_image.jpg')
```
接下来,我们需要对图像进行预处理,以便更容易地检测缺陷。这包括灰度化、平滑和二值化:
```
gray_image (Image, GrayImage)
gauss_filter (GrayImage, GaussImage, 5)
threshold (GaussImage, BinaryImage, 100, 255)
```
然后,我们可以使用形状模板匹配来检测缺陷。我们使用 `find_shape_model` 函数来查找形状模板,并将结果存储在 `Row` 和 `Column` 中:
```
find_shape_model (BinaryImage, 'shape_model', 0, 0, 0.5, 1, 0.5, 'least_squares', 6, Row, Column, Angle, Scale, Score)
```
最后,我们可以在原始图像上绘制出检测到的缺陷的框:
```
gen_rectangle2 (Rectangle, Row, Column, Angle, 50, 50)
dev_set_color ('red')
dev_display (Image)
dev_display_rectangle2 (Rectangle, Angle, Row, Column)
```
完整的例程如下:
```
load_object_model ('shape_model', 'shape_model.sao')
read_image (Image, 'product_image.jpg')
gray_image (Image, GrayImage)
gauss_filter (GrayImage, GaussImage, 5)
threshold (GaussImage, BinaryImage, 100, 255)
find_shape_model (BinaryImage, 'shape_model', 0, 0, 0.5, 1, 0.5, 'least_squares', 6, Row, Column, Angle, Scale, Score)
gen_rectangle2 (Rectangle, Row, Column, Angle, 50, 50)
dev_set_color ('red')
dev_display (Image)
dev_display_rectangle2 (Rectangle, Angle, Row, Column)
```
使用halcon生成旋转中心标定代码
以下是使用Halcon生成旋转中心标定代码的示例:
```
* 初始化
dev_open_window(0, 0, 800, 600, 'black', WindowHandle)
dev_set_window(WindowHandle)
* 读取图像
read_image(Image, 'image.bmp')
* 预处理图像
gray_image(Image, ImageGray)
threshold(ImageGray, Region, 128, 255)
connection(Region, ConnectedRegions)
select_shape(ConnectedRegions, SelectedRegions, ['area'], 'and', [200, 999999])
* 执行旋转中心标定
find_shape_model(SelectedRegions, ModelID, 0, 0, 0.5, 1, 0.5, 'least_squares')
get_shape_model_contours(ModelContours, ModelID, 1)
gen_region_contour(ModelRegion, ModelContours)
find_scaled_shape_model(Image, ModelID, 0, 0, 0.5, 1.5, 0.5, 0, 0.5, 'least_squares', 6, 0.75, Row, Column, Angle, Score)
gen_cross_contour_xld(Cross, Row, Column, 30, Angle)
concat_obj(ModelRegion, Cross, ResultRegion)
* 显示结果
dev_display(ResultRegion)
```
代码中的 `find_shape_model` 和 `find_scaled_shape_model` 函数用于执行旋转中心标定。`ModelID` 是旋转中心模板的 ID,可以使用 `create_shape_model` 函数创建。`Row`、`Column`、`Angle` 和 `Score` 是标定结果,分别表示旋转中心的行坐标、列坐标、旋转角度和匹配得分。最后,将标定结果用 `gen_cross_contour_xld` 函数生成十字线,并用 `concat_obj` 函数将旋转中心标定结果和十字线拼接成一个区域对象用于显示。