#获取图像
read_image(Image,'E:/C/Halcon/1.jpg')
#读取整个文件夹的图像
#1列出指定路径下的文件
list_files('E:/C/Halcon',['files','follow_links'],ImageFiles)
#2选择符合条件的文件
tuple_regexp_select(ImageFiles,['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'],ImageFiles)
#3循环读取文件夹下的图像
for Index :=0 to |ImageFiles|-1 by 1
read_image(Image,ImageFiles[Index])
endfor
获取单独一张:
#获取图像
read_image(Image,'E:/C/Halcon/1.jpg')
获取一整个文件夹内容:
#读取整个文件夹的图像
#1列出指定路径下的文件
list_files('E:/C/Halcon',['files','follow_links'],ImageFiles)
#2选择符合条件的文件
tuple_regexp_select(ImageFiles,['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'],ImageFiles)
#3循环读取文件夹下的图像
for Index :=0 to |ImageFiles|-1 by 1
read_image(Image,ImageFiles[Index])
endfor
代码解释:
list_files('E:/C/Halcon',['files','follow_links'],ImageFiles)
list()方法是返回某个目录下的所有文件和目录的文件名,返回的是String数组
listFiles()方法是返回某个目录下所有文件和目录的绝对路径,返回的是File数组
函数原型:list_files(::Directory,Options:Files)
功能:列出目录中的所有文件
参数列表:
第1个参数Directory为输入变量,需要列出的目录名字
第2个参数Options为输入变量,默认值为files,建议值有:'files', 'directories', 'recursive', 'follow_links', 'max_depth 5'(遍历深度), 'max_files 1000'(最大读取文件个数)
第3个参数Files为输出变量,读取的文件
tuple_regexp_select(ImageFiles,['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'],ImageFiles)
原型:tuple_regexp_select( : : Data, Expression : Selection)
功能:文件格式筛选
参数列表:
Data:被选择的文件路径数组
Expression:文件格式的筛选规则
Selection:选择出的文件路径数组
获取实时图像
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] Sunplus Camera', 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
while (true)
grab_image_async (Image, AcqHandle, -1)
* Image Acquisition 01: Do something
endwhile
close_framegrabber (AcqHandle)
代码解释:
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] Sunplus Camera', 0, -1, AcqHandle)
原型:
open_framegrabber ( : : Name, HorizontalResolution,
VerticalResolution, ImageWidth, ImageHeight, StartRow, StartColumn,
Field, BitsPerChannel, ColorSpace, Generic, ExternalTrigger,
CameraType, Device, Port, LineIn : AcqHandle )
功能:打开图像采集设备
参数信息:
Name:图像采集设备的名称
HorizontalResolution和VerticalResolution:分别指预期的图像采集接口的水平分辨率和垂直分辨率
ImageWidth和ImageHeight:指预期图像的宽度部分和高度部分。默认0
StartRow和StartColumn:指显示预期图像的开始坐标 默认0
Field:预期图像是一半的图像或者是完整图像 默认default,
BitsPerChannel:每像素比特数和图像通道 默认-1
ColorSpace:输出的色彩格式的抓住图像{gray、raw、rgb、yuv、default}默认default,
Generic:通用参数与设备细节部分的具体意义。默认-1
ExternalTrigger:是否有外部触发
CameraType:使用相机的类型 默认default,
Device:图像获取设别连接到的设备,默认default,可使用onfo_framegrabber查询
Port:图像获取设别连接到的端口,默认-1
LineIn :相机输入的多路转接器
AcqHandle:图像获取设备的Handle
设置相机的其他参数:Set_framegrabber_param
grab_image_start (AcqHandle, -1)
异步采集:不需要 采集完了处理完了再采集下一次
grab_image:采集完了处理完了再采集下一次
外部触发采集图像:
多相机异步采集和多相机同步采集