halcon学习笔记(3)——critical_points例子学习(图像分割Region)

来源:互联网 发布:域名过户需要多长时间 编辑:程序博客网 时间:2024/06/05 17:27

     例子在HDevelop自带例子里面,叫critical_points;目的是在所画的闭合区域内的进行检测图像中的鞍点,鞍点具体是什么我这里也不太了解;以后深入再叙述吧。话不多说先上例子:

例子中输入图像和处理后的图像是这样子:


左边是输入图像,白色的圈是鼠标画出的闭合区域,右边是图像分割后图像,并检测鞍点,就是图中黑白交错的圆圈;我使用的图形如下:

             

                                                                                 实验图片(1)

               

                                                                                 实验图片(2)

从上图可以大概知道鞍点特异性,当然鞍点不是这次重点,重点是检测给定区域内的项目,忽略区域外的区域;代码具体如下:

dev_update_window ('off')* ***** step: acquire image* ****read_image (Image, 'C:/Users/shanwenjun/Desktop/22.png')get_image_size (Image, Width, Height)dev_close_window ()dev_open_window (0, 0, Width, Height, 'black', WindowHandle)dev_set_part (0, 0, Height - 1, Width - 1)dev_set_line_width (3)dev_set_color ('blue')dev_set_draw ('margin')dev_display (Image)set_display_font (WindowHandle, 20, 'mono', 'true', 'false')* ***** step: draw region* ****disp_message (WindowHandle, 'Draw with the mouse the region of interest', 'window', -1, -1, 'blue', 'false')dev_set_color ('white')draw_region (Region, WindowHandle)dev_display (Region)disp_continue_message (WindowHandle, 'black', 'true')stop ()* ***** step: create ROI* ****reduce_domain (Image, Region, ImageReduced)disp_continue_message (WindowHandle, 'black', 'true')stop ()* ***** step: process image within ROI* ****critical_points_sub_pix (ImageReduced, 'facet', 1.5, 8, RowMin, ColumnMin, RowMax, ColumnMax, RowSaddle, ColSaddle)dev_clear_window ()dev_display (ImageReduced)dev_set_color ('yellow')for i := 0 to |RowSaddle| - 1 by 1    gen_cross_contour_xld (Cross, RowSaddle[i], ColSaddle[i], 25, 0.785398)    dev_display (Cross)endforstop ()dev_update_window ('on')


这里还是一句一句来:

dev_update_window ('off')* ***** step: acquire image* ****read_image (Image, 'C:/Users/shanwenjun/Desktop/22.png')get_image_size (Image, Width, Height)dev_close_window ()dev_open_window (0, 0, Width, Height, 'black', WindowHandle)dev_set_part (0, 0, Height - 1, Width - 1)dev_set_line_width (3)dev_set_color ('blue')dev_set_draw ('margin')dev_display (Image)set_display_font (WindowHandle, 20, 'mono', 'true', 'false')* ***** step: draw region* ****disp_message (WindowHandle, 'Draw with the mouse the region of interest', 'window', -1, -1, 'blue', 'false')
        这上面一段就赘述的,基本是图形界面显示一些基本常用语句,意思大概都如字面意思,具体可以查看F1函数说明,或者看我上一节的内容;这上面的意思大概是:显示一幅图像,然后显示一句话:Draw with the mouse the region of interest;然后你就用鼠标在图像上画圈吧,左键画,右键结束。


dev_set_color ('white')
*设置颜色;
 <span style="font-family: Arial, Helvetica, sans-serif;">draw_region (Region, WindowHandle)</span>
*设置Region画笔
dev_display (Region)
*显示所画的区域
 disp_continue_message (WindowHandle, 'black', 'true')
*显示一句话:按F5继续
stop ()
*暂停等待按F5
reduce_domain (Image, Region, ImageReduced)
*剪切只显示Region区域的图像
disp_continue_message (WindowHandle, 'black', 'true')
*显示一句话:按F5继续
<span style="font-size: 12px; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">stop ()</span>
*暂停等待按F5
critical_points_sub_pix (ImageReduced, 'facet', 1.5, 8, RowMin, ColumnMin, RowMax, ColumnMax, RowSaddle, ColSaddle)
*检测鞍点的函数,最后两个参数RowSaddle和ColSaddle是鞍点的xy坐标数组,前面的查看帮助文档吧,这个函数后面具体应该还会用到,原理现
*在不太清楚
dev_clear_window ()
*清空窗口
dev_display (ImageReduced)
*显示剪切后图像
dev_set_color ('yellow')
*设置颜色
for i := 0 to |RowSaddle| - 1 by 1
*循环读取鞍点    gen_cross_contour_xld (Cross, RowSaddle[i], ColSaddle[i], 25, 0.785398)
*叉子标记,用鞍点的坐标
dev_display (Cross)
*显示叉子
endfor
*结束循环
stop ()
*停止
dev_update_window ('on')
*停止更新窗口

这节重点要学习是上面的Region语句,图像分割,在图像检测中非常重要,因为可以缩小检测范围,提高检测速度和准确率,此次的Region只学习例子程序,Region还要在深入,比如画后的如何保存,每次都可在这个范围内检测等等。




0 0