hdevelop 中 halcon使用gen_measure_rectangle2代码
时间: 2024-03-15 18:47:38 浏览: 200
在HDevelop中使用`gen_measure_rectangle2`函数实现矩形测量,可以按照以下步骤进行:
1. 打开HDevelop开发环境,创建一个新的程序。
2. 读取图像并显示:
```HDevelop
read_image(Image, 'test.jpg')
dev_set_window ('fit')
dev_display(Image)
```
3. 创建矩形测量区域:
```HDevelop
create_measure_rectangle2(Row, Column, Phi, Length1, Length2, ImageWidth, ImageHeight, &MeasureHandle)
dev_display(MeasureHandle)
```
其中,`Row`和`Column`表示矩形中心点的行列坐标,`Phi`表示矩形相对于X轴的旋转角度,`Length1`和`Length2`分别表示矩形的长和宽,`ImageWidth`和`ImageHeight`分别表示图像的宽和高,`MeasureHandle`表示测量区域的句柄。
4. 定义测量参数:
```HDevelop
MeasureThreshold := 20
MeasureTransition := 'positive'
MeasureSelect := 'all'
MeasureInterpolation := 'bicubic'
MeasureSigma := 1.0
MeasureAngle := 'use_polarity'
MeasureSubPixel := 'no_refinement'
MeasureRoi := 'no_pregeneration'
```
5. 执行矩形测量:
```HDevelop
gen_measure_rectangle2(MeasureHandle, Image, 'first', 'last', 1, MeasureTransition, MeasureSelect, MeasureThreshold, MeasureRoi, MeasureAngle, MeasureSubPixel, &ResultRow, &ResultColumn, &ResultPhi, &ResultLength1, &ResultLength2)
```
其中,`Image`表示输入图像,`ResultRow`、`ResultColumn`、`ResultPhi`、`ResultLength1`和`ResultLength2`分别表示测量结果中矩形中心点的行列坐标、旋转角度、长和宽。
6. 输出测量结果:
```HDevelop
disp_message(WindowHandle, 'Row: '+ResultRow.ToString(), 'window', 12, 12, 'black', 'true')
disp_message(WindowHandle, 'Column: '+ResultColumn.ToString(), 'window', 24, 12, 'black', 'true')
disp_message(WindowHandle, 'Phi: '+ResultPhi.ToString(), 'window', 36, 12, 'black', 'true')
disp_message(WindowHandle, 'Length1: '+ResultLength1.ToString(), 'window', 48, 12, 'black', 'true')
disp_message(WindowHandle, 'Length2: '+ResultLength2.ToString(), 'window', 60, 12, 'black', 'true')
```
其中,`WindowHandle`表示显示结果的窗口句柄。
完整代码如下:
```HDevelop
read_image(Image, 'test.jpg')
dev_set_window ('fit')
dev_display(Image)
create_measure_rectangle2(Row, Column, Phi, Length1, Length2, ImageWidth, ImageHeight, &MeasureHandle)
dev_display(MeasureHandle)
MeasureThreshold := 20
MeasureTransition := 'positive'
MeasureSelect := 'all'
MeasureInterpolation := 'bicubic'
MeasureSigma := 1.0
MeasureAngle := 'use_polarity'
MeasureSubPixel := 'no_refinement'
MeasureRoi := 'no_pregeneration'
gen_measure_rectangle2(MeasureHandle, Image, 'first', 'last', 1, MeasureTransition, MeasureSelect, MeasureThreshold, MeasureRoi, MeasureAngle, MeasureSubPixel, &ResultRow, &ResultColumn, &ResultPhi, &ResultLength1, &ResultLength2)
disp_message(WindowHandle, 'Row: '+ResultRow.ToString(), 'window', 12, 12, 'black', 'true')
disp_message(WindowHandle, 'Column: '+ResultColumn.ToString(), 'window', 24, 12, 'black', 'true')
disp_message(WindowHandle, 'Phi: '+ResultPhi.ToString(), 'window', 36, 12, 'black', 'true')
disp_message(WindowHandle, 'Length1: '+ResultLength1.ToString(), 'window', 48, 12, 'black', 'true')
disp_message(WindowHandle, 'Length2: '+ResultLength2.ToString(), 'window', 60, 12, 'black', 'true')
```
需要注意的是,本示例代码仅供参考,实际使用时需要根据具体情况进行修改。
阅读全文