halcon gen_measure_rectangle2
时间: 2023-04-29 17:06:51 浏览: 213
b'halcon gen_measure_rectangle2'是Halcon图像处理软件中的一个函数,用于生成矩形测量对象。该函数可以通过指定矩形中心坐标、矩形方向、边长和角度来创建一个矩形测量对象,用于测量图像中矩形区域的特征值。
相关问题
halcon gen_measure_rectangle2实例
以下是一个使用`halcongen_measure_rectangle2`函数的示例代码:
```
read_image(Image, 'test.jpg')
Threshold(Image, Region, 128, 255)
Connection(Region, ConnectedRegions)
SelectShape(ConnectedRegions, SelectedRegions, 'area', 'and', [1000, 100000])
SmallestRectangle2(SelectedRegions, Row, Column, Phi, Length1, Length2)
gen_rectangle2(Rectangle, Row, Column, Phi, Length1, Length2)
gen_measure_rectangle2(Rectangle, Phi, 50, 50, 'positive', 'nearest_neighbor', Row1, Column1, Row2, Column2, Row3, Column3, Row4, Column4, Width, Height, RowC, ColumnC, Angle)
disp_image(Image)
dev_display(SelectedRegions)
dev_display(Rectangle)
dev_display_arrow(RowC, ColumnC, RowC + 50 * cos(Angle), ColumnC + 50 * sin(Angle), 3)
```
在这个示例中,我们首先读取一张图片,并对其进行二值化和连通性分析,筛选出面积在1000到100000之间的连通区域。然后,我们使用`SmallestRectangle2`函数找到这些区域的最小外接矩形,再使用`gen_measure_rectangle2`函数测量这个矩形的大小和方向。最后,我们将这些结果可视化显示出来。
需要注意的是,这个示例代码仅供参考,具体的使用方法和参数设置需要根据具体的需求而定。
halcon使用gen_measure_rectangle2代码
以下是Halcon中使用`gen_measure_rectangle2`函数实现矩形测量的示例代码:
```
#include "HalconCpp.h"
#include <iostream>
using namespace HalconCpp;
using namespace std;
int main()
{
// 读取图像
HImage image("test.jpg");
// 显示图像
DispObj(image, WindowHandle("test image"), 0, 0);
// 定义矩形测量区域的位置和大小
HTuple row = 100, column = 100, phi = 0, length1 = 200, length2 = 100;
// 创建矩形测量区域
HRegion rectangle = GenMeasureRectangle2(row, column, phi, length1, length2, image.Width(), image.Height());
// 显示矩形测量区域
DispObj(rectangle, WindowHandle("test image"), "blue");
// 定义测量参数
HTuple measureThreshold = 20, measureTransition = "positive", measureSelect = "all",
measureInterpolation = "bicubic", measureSigma = 1.0, measureAngle = "use_polarity",
measureSubPixel = "no_refinement", measureRoi = "no_pregeneration";
// 执行矩形测量
HTuple resultRow, resultColumn, resultPhi, resultLength1, resultLength2;
GenMeasureRectangle2(rectangle, image, "first", "last", 1, measureTransition,
measureSelect, measureThreshold, measureRoi, measureAngle,
measureSubPixel, &resultRow, &resultColumn, &resultPhi,
&resultLength1, &resultLength2);
// 输出测量结果
cout << "Row: " << resultRow.D() << endl;
cout << "Column: " << resultColumn.D() << endl;
cout << "Phi: " << resultPhi.D() << endl;
cout << "Length1: " << resultLength1.D() << endl;
cout << "Length2: " << resultLength2.D() << endl;
return 0;
}
```
在这个示例代码中,首先读取了一张图像,并显示在屏幕上。然后定义了矩形测量区域的位置和大小,并使用`GenMeasureRectangle2`函数创建了矩形测量区域,并将其显示在图像上。接着,定义了矩形测量的参数,并使用`GenMeasureRectangle2`函数执行矩形测量,并将测量结果保存在`resultRow`、`resultColumn`、`resultPhi`、`resultLength1`和`resultLength2`变量中。最后,将测量结果输出到控制台。
需要注意的是,本示例代码仅供参考,实际使用时需要根据具体情况进行修改。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)