Halcon遍历读取文件夹里的所有图片

岁酱吖の 提交于 2020-03-17 02:00:18

Halcon遍历读取图片的例子

1、通用方法

使用list_files和tuple_regexp_select算子

dev_close_window ()
list_files ('D:/hellowprld/pic', ['files','follow_links','recursive'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image, ImageFiles[Index])
    dev_close_window ()
    get_image_size (Image, Width, Height)
    *dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
    dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
    dev_display (Image)

    gen_rectangle1 (Rectangle, 482.313, 458.083, 847.963, 1001.78)
    reduce_domain (Image, Rectangle, ImageReduced)
    crop_domain (ImageReduced, ImagePart)
    mean_image (ImagePart, ImageMean, 20, 20)
    auto_threshold (ImageMean, Regions, 2)
    connection (Regions, ConnectedRegions)
    select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)
    area_center (SelectedRegions, Area, Row, Column)
    
    dev_clear_window ()
    dev_display (ImagePart)
    dev_display (Image)
    if (Area < 100000)
        disp_message (WindowHandle, 'good', 'window', Row, Column, 'black', 'true')
    else
        disp_message (WindowHandle, 'bad', 'window', Row, Column, 'black', 'true')    
    endif
    stop ()
endfor

 

2、简易方法

直接for循环

dev_close_window()
dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
for i:=1 to 7 by 1
    read_image (Image, 'image/蚕丝检测' + i + '.bmp')
endfor

* Main loop: process different images
for Index1 := 1 to 7 by 1
    read_image (Image, 'image/saw_blade/saw_'+Index1$'02')
endfor

 

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!