在HDevelop中,除了tuples和iconic objects这两种变量类型之外,还有第三种变量类型:vector。
1 tuples int数组
2 iconic objects 图标对象:图像、区域和、XLD数据(统称,无法使用)
3 vector 和C++一样
// HTuple→VC 数据类型转换
HTuple hTuple = 1234;
int i = hTuple[0].I(); // i=1234
long l = hTuple[0].L(); // l=1234
long lNumber = hTuple.Num(); // lNumber=1,数据个数
double d = hTuple[0].D(); // d=1234.0000
hTuple = "1234";
CString strBuffer = hTuple[0].S(); // strBuffer="1234"
// VC→HTuple 数据类型转换
int ii = 1234;
double dd = 1234.1234;
CString strTemp = "Halcon";
HTuple hTuple2;
hTuple2[0] = ii; // hTuple2[0].I()=1234
hTuple2[1] = dd; // hTuple2[1].D()=1234.1234
hTuple2[2] = strTemp.GetBuffer(); // hTuple2[2].S()="Halcon"
i = hTuple2[0].I(); // i=1234
d = hTuple2[1].D(); // d=1234.1234
strBuffer = hTuple2[2].S(); // strBuffer="Halcon"
lNumber = hTuple2.Num(); // lNumber=3,数据个数
int string bool …
read_image (Mreut, 'mreut')
threshold (Mreut, Region, 190, 255)
*声明tuple
Areas := []
*写入tuple
for Radius := 1 to 3 by 1
dilation_circle (Region, RegionDilation, Radius)
area_center (RegionDilation, Area, Row, Column)
Areas[Radius-1] := Area
endfor
*访问tuple
a :=Areas[0]
b :=Areas[1]
c :=Areas[2]
一切变量都可以放进去
*声明vector
vec_test := {}
*赋值vector
for i :=1 to 5 by 1
vec_test.insert(i-1,i)
endfor
vec_test.insert(5,'草泥马')
*访问vector
a := vec_test.at(5)
b := vec_test.at(1)
a :=
[control教程]
C:/Program Files/MVTec/HALCON-20.11-Steady/doc/html/reference/operators/toc_control.html
*读取图像
read_image (Image, 'D:/projects/halcon/match/src/3.jpg')
threshold (Image, Regions, 0, 100)
gen_contour_region_xld (Regions, Contours, 'border')
*对于多个轮廓,一局轮廓长度进行排序,选择最大值
*计算长度
length_xld (Contours, Length)
*对这些长度排序
tuple_sort_index (Length, Indices)
*看看总共有几个元素
count_obj (Contours, Number)
*选择最大值
*Indices[Number-i]+1 表示第i大的
select_obj (Contours, ObjectSelected_max, Indices[Number-1]+1)
*最小,就是第一个
select_obj (Contours, ObjectSelected_min, Indices[0]+1)
tuple := [] //创建空数组
for i := 1 to 100 by 1 //建立步长为1的循环
tuple := [tuple,i*i] //将i方的值赋给数组的第i个元素
endfor //循环结束
*自动阈值分割(非黑即白)
bin_threshold (Image, Region)
*找到黑色区域
threshold (Image, Regions, 0, 112)
*闭运算,去噪点
closing_circle (Regions, RegionClosing, 100)
Ø 并:
union1()、union2();
Ø 交:
intersection();
Ø 差:
difference();
Ø 补:
complement();
gen_contour_region_xld (RegionClosing, Contours, 'border')
create_shape_model (Image_template, 5, rad(0), rad(360), rad(0.815), ['none','no_pregeneration'], 'use_polarity', [10,11,4], 3, ModelID)
find_shape_model (Image_target, ModelID, rad(0), rad(360), 0.5, 0, 0.5, 'least_squares', [5,1], 0.75, Row, Column, Angle, Score)