十二.图像获取与相关参数(halcon)(

图像获取程序例1.

1.set_system( : : SystemParameter, Value : )

设置系统参数

2.open_framegrabber Name, HorizontalResolution,VerticalResolution, ImageWidth, ImageHeight, StartRow, StartColumn,Field, BitsPerChannel, ColorSpace, Generic, ExternalTrigger,CameraType, Device, Port, LineIn : AcqHandle )

     打开并配置图像采集设备

输入控制:

   Name:图像采集设备的名称

   HorizontalResolution和VerticalResolution预期的图像采集接口的水平分辨率和垂直分辨率

   ImageWidth和ImageHeight指预期图像的宽度部分和高度部分。

   StartRow和StartColumn指显示预期图像的开始坐标

   Field预期图像是一半的图像或者是完整图像

   BitsPerChannel每像素比特数和图像通道

   ColorSpace获取图像的输出形式{gray、raw、rgb、yuv、default}

   Generic通用参数与设备细节部分的具体意义。

   ExternalTrigger是否有外部触发

   CameraType使用相机的类型

   Device图像获取设别连接到的设备

   Port图像获取设别连接到的端口

   LineIn :相机输入的多路转接器

   AcqHandle:图像获取设备的Handle

3.grab_image( : Image : AcqHandle : )

AcqHandle指定的图像获取设备中获取图像,输出为获得的图像

4.set_framegrabber_param( : : AcqHandle, Param, Value : )

AcqHandle指定的图像获取设备设置参数

Param : 'color_space', 'continuous_grabbing', 'external_trigger', 'grab_timeout', 'image_height', 'image_width', 'port', 'start_column', 'start_row', 'volatile'

注意:能够设置的参数不仅仅是上述建议的参数。也可以一次设定多个参数值。

例如:set_framegrabber_param (AcqHandle, 'port', Port0)

set_framegrabber_param (AcqHandle, ['image_width','image_height'], [256, \256])

对DaHengCams能设置的常用额外参数包括:

'adc_level' ---设置A/D转换的级别;

'color_space' ---设置颜色空间

'gain' ---设置相机增益

'grab_timeout' ---设置采集超时终止的时间

'resolution' ---设定相机的采相分辨率,MOD0为最大的分辨率。

'shutter' ---设定相机的曝光时间。

'shutter_unit' ---设定相机曝光时间的单位。

'white_balance' ---相机是否打开白平衡模式,默认为关闭白平衡

 

5.info_framegrabber( : : Name, Query : Information, ValueList)

查询指定的图像采集接口的信息。

Name为图像采集设备的名称

Query为需要查询的参数名称

Information是指输出的文本信息

ValueList为该图像采集接口的参数值

6.get_image_pointer1(Image : : : Pointer, Type, Width, Height)

获取一个图像通道的指针,输出指针以及图像类型和尺寸。

7.dev_set_part( : : Row1, Column1, Row2, Column2 : )

修改图像显示部分的尺寸。

8.close_all_framegrabbers( : : : )

关闭图像采集设备。

9.count_seconds( : : : Seconds)

测试算子实行时间

* general configuration of HDevelop
set_system ('do_low_error', 'true')  //设置系统参数,在输出窗口只立即显示图像//
dev_update_window ('off')
stop ()
* step 1: connect to the image acquisition device
* -> Please adapt the following lines for your own image acquisition device.
AcqName := 'DaHengCam'
open_framegrabber (AcqName, 1, 1, 0, 0, 0, 0, 'default', -1, 'gray', -1, 'false', 'ntsc', 'default', -1, -1, AcqHandle)     //打开并配置图像采集设备//
stop ()
* step 2: grab a first image and adjust the window size
grab_image (Image, AcqHandle)                            //获取图像//
get_image_pointer1 (Image, Pointer, Type, Width, Height) //获取图像通道指针//
dev_close_window ()
dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle) //开新窗口//
dev_set_part (0, 0, Height-1, Width-1)
dev_display (Image)
stop ()
* step 3: grab and process images in a loop (exit with left mouse button)
dev_open_window (0, Width/2 + 8, Width/2, Height/2, 'black', WindowHandleProcess)
dev_set_colored (12)
dev_open_window (Height/2 + 68, 0, Width/2, Height/16, 'light gray', WindowHandleButton)
dev_set_part (0, 0, Height/16 - 1, Width/2 -1)
write_string (WindowHandleButton, ' click here with left mouse button to exit loop')//写字符

                                                                                     进入窗口//
dev_set_window (WindowHandle)
dev_set_part (0, 0, Height-1, Width-1)
Button := 0
while (Button # 1)
    grab_image (Image, AcqHandle) 

    dev_set_window (WindowHandle)
    dev_display (Image)
    * -> process image (segment with an automatically determined threshold)
    auto_threshold (Image, Regions, 4)//高斯平滑图像并利用直方图分割图像输出区域//
    connection (Regions, ConnectedRegions)
    dev_set_window (WindowHandleProcess)
    dev_display (ConnectedRegions)
    * -> check for a click into the window (error handling switched off, otherwise the cursor must always be in the window)
    dev_set_check ('~give_error')
    get_mposition (WindowHandleButton, Row, Column, Button)
    dev_set_check ('give_error')
endwhile
dev_set_window (WindowHandleButton)
dev_close_window ()
dev_set_window (WindowHandleProcess)
dev_close_window ()
stop ()
* clean up
dev_update_window ('on')
close_all_framegrabbers ()

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值