本文最后更新于:2024年1月14日 晚上

本文记录 Halcon 中的逻辑运算。

Tuple 逻辑运算符

  • 对于 Tuple 的逻辑运算,Halcon 支持一对一、 一对多、 多对多(需要数量相同),多对一的计算方式

逻辑

  • Halcon 支持标准正经的逻辑运算符:

    and, or, xor, not

  • 此类运算符将变量看做逻辑变量,0 表示 false, 非零为 true

1
2
3
4
5
6
7
A := true
B := false

C:= A and B
C:= A or B
C:= A xor B
C:= not B
  • 上述操作可用函数式操作代替

    tuple_and, tuple_or, tuple_xor, tuple_not

1
2
3
4
5
6
7
8
A := [8, 9, 13]
B := 3

tuple_band(A, B, C)
tuple_and(A, B, C)
tuple_or(A, B, C)
tuple_xor(A, B, C)
tuple_not(A, C)
  • 运算结果均为 0 (false), 1 (true)

按位逻辑

  • Halcon 支持对二进制的按位逻辑运算,运算符:

    band, bor, bxor, bnot

1
2
3
4
5
6
7
A := true
B := false

C:= A band B
C:= A bor B
C:= A bxor B
C:= bnot B
  • Tuple 的按位逻辑运算也有函数表示

    tuple_band, tuple_bor, tuple_bxor, tuple_bnot

  • 此类运算符要求 Tuple 中数据为整数,计算时按照数据二进制逐位进行逻辑运算

1
2
3
4
5
6
7
A := [8, 9, 13]
B := -35

tuple_and(A, B, C)
tuple_bor(A, B, C)
tuple_bxor(A, B, C)
tuple_bnot(A, C)

Tuple 关系运算

  • 逻辑运算的结果经常是关系运算得到的,Halcon 支持常规的关系运算符:

    #(不等于), >, <, ==

1
2
3
4
5
6
7
A := 3
B := 2

C := A # B
C := A > B
C := A < B
C := A == B

Image 逻辑运算

  • Halcon 支持尺寸相同的图像变量的按位逻辑运算,函数为:

    bit_or, bit_and, bit_not, bit_xor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
read_image (Image, 'printer_chip/printer_chip_01')

gen_rectangle1 (ROI_0, 100, 100, 200, 200)
gen_rectangle1 (ROI_1, 300, 300, 400, 400)

reduce_domain(Image, ROI_0, ImageReduced0)
reduce_domain(Image, ROI_1, ImageReduced1)

crop_domain(ImageReduced0, ImagePart0)
crop_domain(ImageReduced1, ImagePart1)

bit_or(ImagePart0, ImagePart1, ImageOr)
bit_and(ImagePart0, ImagePart1, ImageAnd)
bit_xor(ImagePart0, ImagePart1, ImageXor)
bit_not(ImagePart0, ImageNot)

Region 的交、并、补运算

姑且将 Region 的交并补操作算作逻辑运算

  • Halcon 中 Region 支持交、并、补的集合操作

    • 交集:

      1
      intersection(Region1, Region2 : RegionIntersection : : )
    • 并集:

      1
      2
      union1(Region : RegionUnion : : )
      union2(Region1, Region2 : RegionUnion : : )
    • 补集:

      1
      difference(Region, Sub : RegionDifference : : )

参考资料



文章链接:
https://www.zywvvd.com/notes/coding/halcon/halcon-logic-op/halcon-logic-op/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

Halcon 逻辑运算
https://www.zywvvd.com/notes/coding/halcon/halcon-logic-op/halcon-logic-op/
作者
Yiwei Zhang
发布于
2022年12月14日
许可协议