基于Halcon学习的基于相关性模板匹配【二】find_ncc_model_defocused_precision.hdev

*本示例的目的是检查ncc检测的偏差,当透镜焦点改变时,其参考模型的结果;
*在序列上迭代。这里使用的匹配方案是ncc模型。检测到的模型在x和y方向上的整体运动;
*最后(以像素为单位)进行了描述

dev_close_window ()
read_image (ImageRef, 'pcb_focus/pcb_focus_telecentric_061')
get_image_size (ImageRef, Width, Height)
dev_open_window_fit_image (ImageRef, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_update_off ()
dev_set_draw ('margin')
dev_set_color ('green')
dev_set_line_width (1)
* 

**创建ncc模型
gen_rectangle1 (ModelRegion, 81.5, 148.5, 419.5, 633.5)
reduce_domain (ImageRef, ModelRegion, TemplateImage)
dev_clear_window ()
dev_display (TemplateImage)
disp_message (WindowHandle, 'Creating the ncc model may take a few seconds ... ', 'window', 12, 12, 'black', 'true')
create_ncc_model (TemplateImage, 'auto', -rad(5), rad(10), 'auto', 'use_polarity', ModelID)

*禁用自动刷新窗口以实现无闪烁显示
*在显示每一个对象之后是否刷新窗口。如果该值设置为false,必须调用FlushBuffer函数刷新窗口。
set_window_param (WindowHandle, 'flush', 'false')

*在图像中查找ncc模型
area_center (ModelRegion, Area, ModelRow, ModelColumn)
Rows := []
Columns := []
for Index := 1 to 121 by 1
    read_image (Image, 'pcb_focus/pcb_focus_telecentric_' + Index$'03' + '.png')
    find_ncc_model (Image, ModelID, -rad(5), rad(10), 0.5, 1, 0.5, 'true', 0, Row, Column, Angle, Score)
    Rows := [Rows,Row]
    Columns := [Columns,Column]
    dev_display (Image)
    *显示匹配结果
    dev_display_ncc_matching_results (ModelID, 'green', Row, Column, Angle, 0)
    disp_message (WindowHandle, 'Finding ncc model in image:  ' + Index$'03', 'window', 12, 12, 'white', 'false')

    *刷新窗口中的内容。
    flush_buffer (WindowHandle)
endfor

* 如果需要与窗口进行交互(缩放与拖拽),则必须色设置该值为true
set_window_param (WindowHandle, 'flush', 'true')


dev_display (Image)
wait_seconds (1)

gen_contour_polygon_xld (Contour, Rows, Columns)
*按线段近似XLD轮廓。
*拟合直线
fit_line_contour_xld (Contour, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
gen_contour_polygon_xld (Regression, [RowBegin,RowEnd], [ColBegin,ColEnd])


*调整窗口大小,使像素显示为方形
Ratio := (394 - 389 + 1) / real(252 - 250 + 1)
dev_resize_window_fit_size (0, 0, Height * Ratio, Height, 640, 480)
dev_set_part (250, 389, 252, 394)
dev_display (ImageRef)
dev_set_color ('green')
dev_display (Contour)
dev_set_color ('yellow')
dev_display (Regression)
disp_message (WindowHandle, ['Deviation of ncc matches in (x,y)-direction','while defocusing lens'], 'image', 249.75, 389, 'white', 'false')
disp_message (WindowHandle, '  Deviation (green), Tukey\'s robust regression (yellow) in pixel', 'image', 251.75, 389.25, 'white', 'false')

* Close all handles
clear_ncc_model (ModelID)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值