halcon之形态学匹配

 
*dev_update_window ('off')
* 打开图像采集设备,本例程是文件类型,以序列方式打开
*open_framegrabber ('File', 1, 1, 0, 0, 0, 0, 'default', -1, 'default', -1, 'default', 'board/board.seq', 'default', -1, 1, FGHandle)

read_image (ReferPhoto, 'D:/image/33.png')
rgb1_to_gray (ReferPhoto, ModelImage)

read_image (TestPhoto, 'D:/image/44.png')
rgb1_to_gray (TestPhoto, SearchImage)

*从采集设备中获取一张图像
*grab_image (ModelImage, FGHandle)
*grab_image (ModelImage, ModelImage1)

*获取图像的第一个数据通道的指针
get_image_pointer1 (ModelImage, Pointer, Type, Width, Height)
*关闭图像窗口
*dev_close_window ()
*打开一个与图像等大小的背景为白色的窗口
*dev_open_window (0, 0, Width, Height, 'white', WindowHandle)
*设置图像显示到窗口哪个区域
*dev_set_part (0, 0, Height - 1, Width - 1)
*显示图像
*dev_display (ModelImage)
* colors and other settings for the visualization
*定义显示区域的颜色
*dev_set_color ('yellow')
*设置画区域的外边框
*dev_set_draw ('margin')
*设置画笔的宽度
dev_set_line_width (2)
*设置窗体显示字体的类型
*set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*显示继续进行的消息,字体为黑色,Press Run (F5) to continue
*disp_continue_message (WindowHandle, 'black', 'true')


*stop ()



* ------------------- start of the application ----------------
* step 1: select the model object


*Row1:=226.5
*Column1:=132.5
*Row2:=309.5
*Column2:=227.5

Row1:=240.688
Column1:= 201.268
Row2:=331.821
Column2:=361.653

*gen_rectangle1 (ROI_0, 226.5, 132.5, 309.5, 227.5)




*生成一个与坐标平行的矩形区域
gen_rectangle1 (ROI, Row1, Column1, Row2, Column2)
*显示此区域
dev_display (ROI)
*获取ROI区域
reduce_domain (ModelImage, ROI, ImageROI)
*显示继续进行的消息,字体为黑色,Press Run (F5) to continue
*disp_continue_message (WindowHandle, 'black', 'true')


*stop ()



* step 2: create the model
*创建形状模型数据,用来进行匹配
inspect_shape_model (ImageROI, ShapeModelImages, ShapeModelRegions, 8, 30)
*关闭窗口
*dev_clear_window ()
*设置区域显示为蓝色
*dev_set_color ('blue')
*显示形状模型区域
*dev_display (ShapeModelRegions)
*获取区域面积及中心数据
area_center (ShapeModelRegions, AreaModelRegions, RowModelRegions, ColumnModelRegions)
*形状模型区域个数
count_obj (ShapeModelRegions, HeightPyramid)
*
for i := 1 to HeightPyramid by 1
if (AreaModelRegions[i - 1] >= 15)
NumLevels := i
endif
endfor
*创建形状模型数据
create_shape_model (ImageROI, 'auto', 0, rad(360), 'auto', 'none', 'use_polarity', 30, 10, ModelID)
*获取形状模型的轮廓
get_shape_model_contours (ShapeModel, ModelID, 1)
*显示继续进行的消息,字体为黑色,Press Run (F5) to continue
*disp_continue_message (WindowHandle, 'black', 'true')



*stop ()



* step 3: find the object in other images
*for i := 1 to 35 by 1
*获取图像
*grab_image (SearchImage, FGHandle)
*read_image (TestPhoto, 'D:/image/4.png')
*rgb1_to_gray (TestPhoto, SearchImage)
    
    
*在图像中进行形状模型匹配
find_shape_model (SearchImage, ModelID, 0, rad(360), 0.7, 1, 0.5, 'least_squares', 0, 0.7, RowCheck, ColumnCheck, AngleCheck, Score)
*if (|Score| == 1)
*设置区域显示为yellow
*dev_set_color ('yellow')
*根据一个点和弧度进行刚体仿射转换
vector_angle_to_rigid (0, 0, 0, RowCheck, ColumnCheck, AngleCheck, MovementOfObject)
*将模型进行轮廓xld仿射变换
*affine_trans_contour_xld (ShapeModel, ModelAtNewPosition, MovementOfObject)
*显示搜索图像
*dev_display (SearchImage)
*显示匹配区域
*dev_display (ModelAtNewPosition)
*endif
*if (i != 20)
*disp_continue_message (WindowHandle, 'black', 'true')
*endif
*stop ()
*endfor
* ------------------- end of the application -----------------
* clean up
*清空模型数据
clear_shape_model (ModelID)
*设置更新窗口'on'
*dev_update_window ('on')
*关闭采集图像
 *close_framegrabber (FGHandle)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值