分享

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

 行走在理想边缘 2016-08-17
图像获取程序例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 imageacquisition 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 mousebutton)
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, 'lightgray', WindowHandleButton)
dev_set_part (0, 0, Height/16 - 1, Width/2 -1)
write_string (WindowHandleButton, ' click here with left mousebutton 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 determinedthreshold)
auto_threshold (Image, Regions, 4)//高斯平滑图像并利用直方图分割图像输出区域//
connection (Regions, ConnectedRegions)
dev_set_window (WindowHandleProcess)
dev_display (ConnectedRegions)
* -> check for a click into the window (error handling switchedoff, 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条评论

    发表

    请遵守用户 评论公约

    类似文章 更多