halcon获取多个图像设备的数据

使用场景

当工控机连接多个相机设备时,需要灵活控制所有相机设备。下面实现借助halcon算子实现了如何通过相机的ip地址,设备编号等信息控制不同相机的方法。

相关算子

  • info_framegrabber():获取所有指定类型接口的图像设备信息;
  • open_framegrabber(): 打开并配置一个图像设备;
  • grab_image_start():开始抓取一个图像;
  • close_framegrabber(): 关闭图像设备;

相关代码

// A code block
*  自行去查看ValueList的结构
info_framegrabber('GigEVision2','info_boards',Information,ValueList)   
tuple_lenght(ValueList,lenght_aquipment)

device_list := [  ]
ip_list := [  ]

for index:=0 to lenght_aquipment-1 by 1
   tuple_split(ValueList[index], '|', Substrings)
   * 选择匹配device项
   tuple_regexp_select(Substrings,'device', Matches_device)
   * 选择匹配IP的项
   tuple_regexp_select(Substrings,'device_ip', Matches_device_ip)
   * 拆分IP地址
   tuple_split(Matches_device_ip, ':', Substrings_ip)
   tuple_select(ip_list, Lenght_aquipment, Selected)
   * 按照:拆分device
   tuple_split(Matches_device, ':', Substrings_device)	
   * 替换Device中的全部空格
   tuple_regexp_replace(Substrings_device[1], ['\\s*', 'replace_all'],'',Result_device)
   * 替换IP中的全部空格
   tuple_regexp_replace(Substrings_ip[1], ['\\s*', 'replace_all'],'',Result_device)
   
   * 将IP和Device保存,这样就保证了IP与Device是一一对应存储的
   ip_list[index] := Result_ip
   device_list[index] := Result_device
endfor

* 指定IP地址/device去打开对应的相机(指定IP,那么就需要去device_list中寻找对应的设备名称去打开相机)
try
   open_framegrabber(................, device_list[0],......)    // 打开第一个相机
   grab_image_start()                         // 开始抓取图像

catch(Exception)
   dev_get_window(windowhandle)
   disp_message()    // 将错误信息显示
   close_framegrabber()
endtry

close_framegrabber()


猜你喜欢

转载自blog.csdn.net/xiaochuideai/article/details/128238970
今日推荐