比较常用的几个图像获取的例子,之前刚刚学习halcon的时候写的,作为入门的第一步,还是值得再分享一下的。
*=================分割线1================== *图像获取的基本代码(1) *读取路径下的图片,image1 read_image(image1,'F:/Halcon test/barcode/image/1.png')
*=================分割线2================== *图像获取的基本代码(2) *读取路径下的多张图片,image2 imagepath :=[] *建立一个图像读取的数组,命名为imagepath。 imagepath[0]:='F:/Halcon test/barcode/image/2.png' imagepath[1]:='F:/Halcon test/barcode/image/3.png' imagepath[2]:='F:/Halcon test/barcode/image/4.png' imagepath[3]:='F:/Halcon test/barcode/image/5.png' *读取4张图片的路径 for i:=0 to 3 by 1 read_image(image2,imagepath[i]) endfor
*=================分割线3================== *图像获取的基本代码(3) *读取文件夹下的某些图片,image3 for i:=1 to 5 by 1 read_image(image3,'F:/Halcon test/barcode/image/'+i+'.png') endfor
*=================分割线4================== *图像获取的基本代码(4) *读取文件夹下的所有图片和文件夹,image4 * Code generated by Image Acquisition 01 list_files ('F:/Halcon test/barcode/image', ['files','directories','recursive','max_depth 2','follow_links'], ImageFiles) tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)$','ignore_case'], ImageFiles) *'ignore_case':忽略大小写 *'\\.' --> '.' for Index := 0 to |ImageFiles| - 1 by 1 read_image (Image4, ImageFiles[Index]) * Do something endfor
*=================分割线5================== *图像获取的基本代码(5) *连接摄像机读取图像,image5 * Code generated by Image Acquisition 02 open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '0', -1, -1, AcqHandle) grab_image_start (AcqHandle, -1) while (true) grab_image_async (Image5, AcqHandle, -1) * Do something endwhile close_framegrabber (AcqHandle)