初识Halcon二(窗口显示设定二)函数


gen_image_const (VarImageBig, 'byte', 800, 600)


* 创建网格线
for Row := 0 to 600 by 20
    gen_region_line (Line, Row, 0, Row, 800)
    paint_region (Line, VarImageBig, VarImageBig, 255, 'fill')
endfor

for Col := 0 to 800 by 20
    gen_region_line (Line, 0, Col, 600, Col)
    paint_region (Line, VarImageBig, VarImageBig, 255, 'fill')
endfor

dev_close_window()
dev_open_window_fit_image(VarImageBig, 0, 0, 800, 600, WindowHandle)
set_display_font(WindowHandle, 16, 'mono', 'true', 'false')

*在当前图形窗口中显示图像对象
dev_display (VarImageBig)

* 显示文字
Text:='1.当dev_disp_text算子使用默认参数时'
Text[1]:='文本在窗口位置(1212)内的黑色'
Text[2]:='一个橙色的盒子,盒子下面的阴影略深'
dev_disp_text (Text, 'window', 12, 12, 'black', [], [])
*停止程序运行,程序不会往下运行
stop()

* 显示文字的位置和颜色
dev_display (VarImageBig)
Text:='2.文本的位置和颜色可以通过'
Text[1]:='参数行、列和颜色。一些例子'
Text[2]:='这三个参数的不同值如下所示'
dev_disp_text(Text, 'image', 12, 12, 'black', [], [])
*将行和列设置为坐标值
dev_disp_text('Row=100\nColumn=60\nColor=\'black\'', 'window', 100, 60, 'black', [], [])
*将行和列设置为预定义的字符串值
dev_disp_text('Row=\'center\'\nColumn=\'right\nColor=\'red\'', 'window', 'center', 'right', 'red', [], [])
* 使用坐标值和预定义的字符串值.
dev_disp_text ('Row = 372.7\nColumn = \'center\'\nColor = \'blue\'', 'window', 372.7, 'center', 'blue', [], [])
* Use multiple colors within a multiline text.
dev_disp_text ('Row = \'bottom\'\nColumn = \'left\'\nColor = [\'forest green\', \'orange\', \'black\']', 'window', 'bottom', 'left', ['green','orange','black'], [], [])

dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()


* *****************************************************************************************************************
* 3. 盒子的外观
dev_display (VarImageBig)
Text := '3. 可以使用通用参数设置框的外观:'
Text[1] := '   - \'box\': 开关盒子 on/off'
Text[2] := '   - \'box_color\': 设置框的颜色和透明度'
Text[3] := '   - \'border_radius\': 设置盒子的圆度'
Text[4] := '   - \'box_padding\': 设置文本周围框的范围'
Text[5] := '   下面展示了一些例子。'
dev_disp_text (Text, 'window', 12, 12, 'black', [], [])
* 'box': switch the display of the box on/off.
dev_disp_text ('\'box\' = \'false\'', 'window', 200, 40, 'black', 'box', 'false')
* 'box_color': set the box color.
dev_disp_text ('\'box_color\' = \'sky blue\'', 'window', 300, 40, 'black', 'box_color', 'sky blue')
* 'box_color': it is valid to use colors with an alpha value (rgba) to
* display transparent boxes.
dev_disp_text ('\'box_color\' = \'#ff8d2644\'', 'window', 340, 40, 'black', 'box_color', '#f28d2644')
* 'border_radius': set the roundness of the box.
dev_disp_text ('\'border_radius\' = 0', 'window', 200, 400, 'black', 'border_radius', 0)
dev_disp_text ('\'border_radius\' = 10', 'window', 240, 400, 'black', 'border_radius', 10)
* 'box_padding': set the amount of padding around the text within the box.
dev_disp_text ('\'box_padding\' = 0', 'window', 300, 400, 'black', 'box_padding', 0)
dev_disp_text ('\'box_padding\' = 10', 'window', 340, 400, 'black', 'box_padding', 10)
* 
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* 4. 盒子阴影的外观.
dev_display (VarImageBig)
Text := '4. The appearance of the box\'s shadow can be set with generic parameters:'
Text[1] := '   - \'shadow\': switches the shadow on/off'
Text[2] := '   - \'shadow_color\': sets the color and transparency of the shadow'
Text[3] := '   - \'shadow_sigma\': sets the blurring of the shadow'
Text[4] := '   - \'shadow_dx\', \'shadow_dy\': sets the offset of the shadow'
Text[5] := '   Some examples are shown below.'
dev_disp_text (Text, 'window', 12, 12, 'black', [], [])
* 'shadow': 打开/关闭阴影。
dev_disp_text ('\'shadow\' = \'false\'', 'window', 200, 40, 'black', 'shadow', 'false')
* 'shadow_color': 设置阴影颜色.
dev_disp_text ('\'shadow_color\' = \'green\'', 'window', 300, 40, 'black', 'shadow_color', 'green')
* 'shadow_color': 使用具有alpha值的颜色是有效的 (rgba)
* 显示透明阴影.
dev_disp_text ('\'shadow_color\' = \'#f28d2688\'', 'window', 340, 40, 'black', 'shadow_color', '#f28d2688')
* '设置阴影的模糊.
dev_disp_text ('\'shadow_sigma\' = 0', 'window', 200, 400, 'black', 'shadow_sigma', 0)
dev_disp_text ('\'shadow_sigma\' = 2.5', 'window', 240, 400, 'black', 'shadow_sigma', 2.5)
* 'shadow_dx', “shadow_dy”:设置阴影的偏移量
dev_disp_text ('\'shadow_dx\' = -5, \'shadow_dy\' = -3', 'window', 300, 400, 'black', ['shadow_dx','shadow_dy'], [-5,-3])
dev_disp_text ('\'shadow_dx\' =  3, \'shadow_dy\' =  -3', 'window', 340, 400, 'black', ['shadow_dx','shadow_dy'], [3,-3])
* 
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
* 5. 坐标系统.
read_image (Image, 'clip')
dev_resize_window_fit_image (Image, 0, 0, 1024, 768)
*使用二进制阈值分割图像。
binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
*计算区域的连通分量。
connection (Region, ConnectedRegions)
*形状特征选择区域。'area':按区域
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5000, 99999)
dev_display (Image)
dev_set_colored (12)
dev_display (SelectedRegions)
*测得区域的面积和中心位置。面积是由区域的像素个数决定,返回的面积行列都为数组
*Area:像素面积 数组
*Row:行坐标 数组
*Column:列坐标 数组
area_center (SelectedRegions, Area, Row, Column)

* 以窗口坐标显示文本。此文本固定在指定的位置,即使图形窗口的内容被移动或缩放。
dev_disp_text ('Area: ' + Area, 'image', Row, Column, 'black', 'box_color', '#ffffff77')
* 
Text := '5. The coordinate system can be set with the parameter CoordSystem:'
Text[1] := '   - \'window\': Row and Column must be specified in window coordinates'
Text[2] := '               -> the displayed text is attached to the window'
Text[3] := '   - \'image\': Row and Column must be specified in image coordinates'
Text[4] := '              -> the displayed text is attached to the image'
* 以窗口坐标显示文本。此文本固定在指定的位置,即使图形窗口的内容被移动或缩放。

dev_disp_text (Text, 'window', 'top', 'left', 'black', [], [])
Text := ['Feel free to interactively move or scale the content of the','graphic window to experience the difference.']
dev_disp_text (Text, 'window', 'bottom', 'center', 'white', 'box_color', 'forest green')


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值