-
Halcon
学习笔记
1
、
Halcon
的自我描述
Program Logic
?
Each program
consists of a sequence of HALCON operators
?
The program can
be structured into procedures
?
The sequence
can be extended by using control operators like
if, for, repeat, or while
?
The results of
the operators are passed via variables
?
No implicit
data passing is applied
?
Input parameters of operators can be
variables or expressions
?
Output parameters are always variables
?
HDevelop has
no features to design a graphical user
interface
?
An
HDevelop
program
is
considered
as
a
prototypic
solution
of
the
vision
part
of
an
application
?
HDevelop is
typically not
used for the final application
< br>由此可以看出,
Halcon
的定位是一个类库,
有着完整、
快速实现函数,
同时提供了
HDevelop
作为快速开发的图形化(
I
DE
)界面;但是,
Halcon
程序
并不是一个完整的最终应用软件,
它没有用户界面,也不提供显示的数据(公用的数据格
式)
。
Halcon
的初学者也应当从参考
Halcon
的程序入手,熟悉
Halcon
类库,也即
HDevel
op-Based
Programming
;在此基础上,进
入
ORClass-Oriented Programming
。这也是
Halcon
推荐的开发
方
式:
The
vision
part
is
solved
with
HDevelop
,
and
the
application
is
developed
with
C++
or
Visual
Basic
。
2
、
HDe
velop
界面的学习
通过阅读
p>
Halcon
的
PPT
,学到了下面一些有用的信息:
?
文件——浏览示例,可以看到很多有用的例子;
?
程序窗体中,
可以浏览与编辑
Procedues
(过程)
,
这个其实就是自定义函数咯~还
可以自己修改这些
过程,并添加说明文档;
?
F4
——将函数语句注释掉;
F3
——激活;
?
本地过程(
Local
Procedue
)与外部过程(
Externel
Procedue
)
3
、基本语法结构
Halcon
的语法结构
类似于
Pascal
与
Visual Basic
,
大部分的语句是
Halcon
提供的算子,
此外也包含了少部分的
控制语句;
p>
不允许单独声明变量;
提供自动的内存管理(初始化、析构及
OverWrite
)
,但句柄则需要显示释放;
C++
(算子模式)
通过代码导出,
以
C++
为例
,
默认导出为算子型的语法结构,
而非面向对象的;
在此模式下,
全部函数声明为全局类型,数据类型只需要用
Hobject
、
HTuple
两类类型进行声明;
C++
(面向对象)
可以以面向对象的方式重写代码,也即利用类及类的成员函数;
在这种模式下,控制变量的类型仍未
HTuple
,而图形数据可以由多种类型,如
HImage
等;
其他语言(略)
4
、
Hal
con
数据结构
两类参数:图形参数
Iconic (image,
region, XLD)
与控制参数
Control
(string, integer, real,
handle)
< br>,在
Halcon
算子的参数中,依次为:输入图形参数
、输出图形参数、输入控制参数、
输出控制参数;并且其输入参数不会被算子改变。
p>
图形参数
Iconic
< br>:
Images
?
Multiple
channels
?
Arbitrary region of interest
?
Multiple pixel
types(byte, (u)int1
/
2
/
4,real, complex, direction,
cyclic, vector_field)
byte, uint2
int1, int2
direction
real
complex
cyclic
vector_field
//
灰度图像的标准编码
//Difference of two images or derivates
with integer precision
(
??)
p>
int4
//
两幅灰度图的频谱
//
图片边缘的梯度方向
//
边缘提取及特定灰度值的轮廓
//
图片频率分布
//Assigning one
(??)
//
连续图形的光学流分布
Regions
?
Efficient data structure (runlength
encoding)//
高效的数据结构
?
Extensive set
of operators
?
Fastest morphology on the market
图形编码中,需要了解
row
和
run
两个术语;也是
Halcon
Region
存储的方式
E
x
tended
L
ine
D
escription
(
XLD
)
?
Subpixel
accurate line and edge detection
?
Generic point
list based data structure
?
Handling of contours, polygons, lines,
parallels, etc.
此外,
Halcon
支持的类型还包括图形元组、控制变量元组及句柄:
元组的概念,
使得可以用一个变量传递数个对象,
可以
由重载后的函数来进行处理;
图
形元
组
的下标从
1
开始,控制变量元组下标从
0
开始
;
句柄则可以用来描述窗体、文
件等等,
句
柄不能是常量。
5
、
Hal
con
语言
输入控制参数可以是表达
式,但图形参数、输出参数均应为变量;
String
类型变量由单引号
’
括起来;此外还有一些特
殊字符;
Boolean
型变量包括
true ( = 1 )
、
false ( = 0 )
;不为零的整数将被认为
true
;但绝大多数的
Halcon
函数接受字符串型的表达:
’
true
’‘
false
’
,
而非逻辑型表达;
函数返回常量用于标识错误:
?
H_MSG_TRUE no
error
2
?
H_MSG_FALSE
l
ogical false
3
?
H_MSG_FAIL
operator did not succeed
5
可以放在
try
…
catch
…
endtry
块中,也可以用
dev_error_
var()
与
dev_set_check()
来捕获;
控制语句结构:
(与一般语言略有不同,它们也有输入输出变量)
?
if
...
endif / if
... else
... endif / if ...
elseif ... else ... endif
?
for
...
endfor
?
while
...
endwhile
?
repeat ... until
此外,也有关键字
break
、
continue
、
return
、
exit
、
stop
用来控制语句的执行;
赋值语句在
Halcon
中也被当作函数来使用:
标准赋值
?
assign(Expression, ResultVariable)
//
编辑形式,永远都是输入在前,输出在后
?
ResultVariable
:= Expression
//
代码形式
元组插入赋值
?
insert(Tuple,
NewValue, Index, Tuple)
//
编辑形式
?
Tuple[Index] :=
NewValue
//
代码形式
控制变量元组操作
?
[t,t]
concatenation of tuples
//
元组串联
?
|t|
number of elements//
元素数目
?
t[i]
selection of an
element//
选中的元素
?
t[i:j]
selection of a
part of a tuple//
選擇一個元組的一部分
(
i
和
J
是
in
dex
?
)
?
subset(t1,t2)
selection from t1 by indices in t2 //
p>
選擇從
T1
在
T2
图形元组操作对应函数
?
[]
gen_empty_obj
()//
创建一个空的元组
?
|t|
count_obj (p, num)//
统计一个元组中的对象。
?
[t1,t2]
concat_obj (p1,
p2, q)//
连接两个目标元组的图标。
?
t[i]
select_obj (p,
q, i+1)//
从一个目标元组中选择目标
?
t[i:j]
copy_obj (p, q,
i+1, j-i+1)
?
subset(t1,t2)
select_obj (p,
q, t2+1)
元组的数学运算,如:
A *
B
,令
m = |A|, n =
|B|
;
//
矩阵乘法?
若
m
、
< br>n
不相等,且都大于
1
,则错误
;否则返回三种情况:
?
m=n=1
,返回一个值;
?
m=n>1
,返回一个包含
m
个数的元组,值为两元组各对于值的操作结
果;
?
m
>1,n=1
,
返回一个包含
m
个数的元组,
值为第二个数与第一元组各值的操作结果;
Halcon
的数学运算
算术运算
?
a / a division
?
a % a
rest of the integer
division
?
a * a
m
ultiplication
?
v + v addition
and concatenation of
strings//
加法和字符串串联。
?
a - a
subtraction
?
-a
negation//
取反。
位运算
?
lsh(i,i)
left
shift
?
rsh(i,i)
right shift
?
i band i
bit-wise and
?
i bor i
bit-wise or
?
i bxor i
bit-wise xor
?
bnot i
bit-wise complement
字符串操作
?
v$$s
?
v +
v
?
strchr(s,s)
?
strstr(s,s)
?
strrchr(s,s)
?
strrstr(s,s)
?
strlen(s)
?
s{i}
?
s{i:i}
?
split(s,s)
比较操作符
?
t < t
?
t > t
?
t <= t
?
t >= t
?
t = t
?
t # t
逻辑操作符
?
not l
?
l
and l
?
l or l
?
l xor l
数学函数
?
sin(a)
?
cos(a)
?
tan(a)
conversion to string
//
字符串的格式化,有很丰富的参数
concatenation of strings and addition
search character in string
search substring
search
character in string (reverse)
search
substring (reverse)
length of string
selection of one character
selection of
substring//
选择子串
splitting to substrings
less
than
greater than
less or
equal
greater or equal
equal
not equal//
不等
negation
logical
’and’
logical
’or’
logical
’xor’
sine of a
cosine of a
tangent of a
?
asin(a)
arc sine of a
in the interval
[-
?
/
2,
?
/ 2], a
?
[-1, 1]
?
acos(a)
arc cosine a in
the interval
[-
?
/
2,
?
/
2], a
?
[-1, 1]
?
atan(a)
arc tangent a
in the interval
[-
?
/
2,
?
/
2], a
?
[-1, 1]
?
atan2(a,b)
arc tangent a/b in the
interval [-
?
,
?
]
?
sinh(a)
hyperbolic sine of a
?
cosh(a)
hyperbolic
cosine of a
?
tanh(a)
hyperbolic tangent of a
?
exp(a)
exponential
function
?
log(a)
natural
logarithm, a> 0
?
log10(a)
decade
logarithm, a> 0
?
pow(a1,a2)
power
?
ldexp(a1,a2)
a1 pow(2,a2)
其他操作(统计、随机数、符号函数等)
?
min(t)
minimum value
of the tuple
?
max(t)
maximum value of the tuple
?
min2(t1,t2)
element-wise minimum of two
tuples
?
max2(t1,t2)
element-wise maximum of two tuples
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
find(t1,t2)
indices of all occurrences of t1 within
t2
rand(i)
create random values from 0..1 (number
specified by i)
sgn(a)
element-wise sign of a
tuple
sum(t)
sum of all elements or
string concatenation
cumul(t)
cumulative histogram of a
tuple
mean(a)
mean value
deviation(a)
standard deviation
sqrt(a)
square root of a
deg(a)
convert radians
to degrees
rad(a)
convert degrees to radians
real(a)
convert integer to real
int(a)
convert a
real to integer
round(a)
convert real to integer
number(v)
convert string to a number
is_number(v)
test if value is a number
abs(a)
absolute value of a (integer or real)
fabs(a)
absolute value of a (always real)
ceil(a)
smallest integer value not smaller than
a
floor(a)
largest integer value not greater than
a
fmod(a1,a2)
fractional
part of a1
/a2, with the same sign as a1
sort(t)
sorting in increasing order
uniq(t)
eliminate duplicates of neighboring
values(typically used in combination
with sort)
sort_index(t)
return index instead of values
median(t)
Median
value of a tuple (numbers)
select_rank(t,v)
Select the
element (number) with the given rank
inverse(t)
reverse the order of the values
subset(t1,t2)
selection from
t1 by indices in t2
remove(t1,t2)
Remove of values with the given indices
environment(s)
value of an environment variable
ord(a)
ASCII number of a character
chr(a)
convert an ASCII number to a character
ords(s)
ASCII number of a tuple of strings
chrt(i)
convert a tuple of integers into a
string
6
、
Halcon
p>
名称解释
?
Operator: A procedure of
the HALCON library used in HDevelop or
one of the language
interfaces.//
算子:在
HDevelop
或语言接口之一使用<
/p>
HALCON
库的程序。
?
Procedure (of
HDevelop): A subroutine defined for the use inside
HDevelop.
?
Region: Result of a segmentation like
threshold. In other systems called blob, area,
binary
image, or island. Implemented
using runlength encoding.
?
XLD: Extended Line Description.
Universal data structure used to handle contour
based
data. Mainly used in the context
of subpixel precise measurement.//
用于处理
基于轮
廓数据的通用数据结构。主要用在子像素精确的测量的情况下。
< br>
-
-
-
-
-
-
-
-
-
上一篇:SAPWorkflow配置与管理手册
下一篇:航运缩略语