2023年12月10日发(作者:昂克拉)
读取图片read_image
一、*读取连续几个图像*
*法一:创建一个文件路径数组,并做初始化*
ImagePath :=[]
ImagePath[0] :=\'F:/Halcon_video/picture/14年机器视觉与图像识别/IMG_\'
ImagePath[1] :=\'F:/Halcon_video/picture/14年机器视觉与图像识别/IMG_\' ImagePath[2] :=\'F:/Halcon_video/picture/14年机器视觉与图像识别/IMG_\'
ImagePath[3] :=\'F:/Halcon_video/picture/14年机器视觉与图像识别/IMG_\' ImagePath[4] :=\'F:/Halcon_video/picture/14年机器视觉与图像识别/IMG_\'
for i:=0 to 4 by 1
read_image(Image,ImagePath[i])
endfor
*法二:
for i:=1 to 5 by 1
read_image(Ima1,\'F:/Halcon_video/picture/14年机器视觉与图像识别/+i+.JPG\')
endfor
二、读取目录下的所有图像
利用“助手”->打开新的Image Acquisition,点击“资源”下的“选择路径”,找到所要读取的照片路径(F:/Halcon_video/picture/14年机器视觉与图像识别/),然后点击“代码生成”、“插入代码”
* Code generated by Image Acquisition 01
list_files (\'F:/Halcon_video/picture/14年机器视觉与图像识别\',
[\'files\',\'follow_links\'], ImageFiles) tuple_regexp_select (ImageFiles,
[\'.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)$\',\'ignore_case\'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])
* Do something
endfor
(主要的三个函数:
1、list_files:遍历指定文件夹下的所有文件
【制定的规则】\'files\', ----指定搜索的格式为文件
\'directories\', ------指定搜索的格式为文件夹
\'recursive\', ------指定可以遍历子文件夹里面的文件
\'follow_links\',----
\'max_depth 5\', -----指定遍历的深度(几层文件夹)
\'max_files 1000\'------指定遍历的最大文件数
2、tuple_regexp_select:选择符合规则的索引
【制定的规则】.--->. (表示转义)
()--->规则的集合比如我们要选择的bmp tif jpg格式的(bmp|jpg|tif)
.( bmp|jpg|tif)--->. bmp| .jpg | .tif
\'ignore_case\'----->忽略大小写
)
三、连接摄像机并读取图像
“助手”--->打开新的Image Acquisition--->点击“图像获取接口”,可在其下拉目录下选择DirectShow,也可点击后面的“检测”
在“代码生成”下选择“插入代码”,即可完成代码的生成
* Code generated by Image Acquisition 01
open_framegrabber (\'DirectShow\', 1, 1, 0, 0, 0, 0, \'default\', 8,
\'rgb\', -1, \'false\', \'default\', \'ThinkVantage Virtual Camera\', 0, -1,
AcqHandle)
grab_image_start (AcqHandle, -1)
while (true) grab_image_async (Image, AcqHandle, -1)
* Do something
endwhile
close_framegrabber (AcqHandle)
四、构建索引读取图像
“助手”--->打开新的Image Acquisition--->点击“图像获取接口”,选择“Files”,在“代码生成”下选择“插入代码”,即可完成代码的生成
* Code generated by Image Acquisition 02
open_framegrabber (\'File\', 1, 1, 0, 0, 0, 0, \'default\', -1, \'default\',
-1, \'false\',
\' F:/Halcon_video/picture/14年机器视觉与图像识别/in_seq\',
\'default\', 1, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
while (true)
grab_image_async (Image, AcqHandle, -1)
* Do something
endwhile
close_framegrabber (AcqHandle)
更多推荐
选择,读取,图像,点击
发布评论