halcon学习笔记(二)
halcon图像处理入门
一. 图像读取的三种方式:
利用read_image 算子读取图像;利用采集助手批量读取文件夹下所有图像利用采集助手采集图像。
二.图像的显示:
图像窗口:通常使用算子dev_open_window(: : Row, Columu, Width, Height,Backgound WindowHandle)来新增一图形窗口,例如: dev_open_window( 0, 0, 512, 512, ‘black’, WindowHandle)
图像显示:常使用dis_dislpay 算子,格式为dev_display(Object ::?
可以通过调用dev_update_window(‘off’)语句关闭窗口的更新
显示文字:常用的disp_message 算子与write_string 算子
disp_message (: : window WindowHandle, string String, attribute.value CoordSystem, point.y Row, point.x Column, color Color, attribute.value Box: )
算子作用:在窗口中显示字符串
write_string (: : window WindowHandle, string String: )
算子作用:在窗口一设定的 光标位置显示字符串,该算子一般与set_tposition配合使用,先使用set_tposition算子设置光标位置,然后使用write_string 在光标处输出字符串
dev_close_window()
dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
dev_set_color('red')
disp_arrow(WindowHandle,255-20, 255-20, 255,255,1)
disp_message(WindowHandle,'显示文字1', 'window', 20, 20, 'black','true')
dev_set_color('blue')
set_tposition(WindowHandle, 40,40)
write_string(WindowHandle, '显示文字2')
set_tposition(WindowHandle, 255, 255)
read_string(WindowHandle, 'default', 32, Outstring)
运行结果:
三.halcon 图像转换
1.RGB转为灰度图
算子:rgb1_to_gary(RGBImage;GaryImage:?
实例:
read_image (test, 'F:/英雄时刻/29388144/英雄时刻_20190420-23点31分59s.gif')
rgb1_to_gray(test, GrayImage)
结果:
2.区域与图像的平均灰度值
使用算子 region_to_mean
region_to_mean(Regions, Image, ImageMean:?
代码:
read_image (Image, 'F:/英雄时刻/29388144/英雄时刻_20190511-14点32分01s.gif')
regiongrowing(Image, Regions,3,3,6,100)
region_to_mean(Regions, Image, Disp)
dev_open_window(0,0,-1,-1,'black', WindowHandle)
dev_display(Disp)
结果:
3.将区域转换为二进制图像或label图像
a.转换为二进制:算子—> region_to_bin(Region: BinImage: ForegroundGray:BackGroundGray:Width:Heigth)
b.转换为Label图像:region_to_label(Regions,ImageLabel,Type,Width,Height)
代码:
read_image (Image, 'F:/壁纸/4.jpg')
copy_image(Image, DupImage)
regiongrowing(DupImage, Regions, 3, 3, 1, 100)
region_to_bin(Regions,BinImage, 255,0,512,512)
region_to_label(Regions,ImageLabel,'int4',512,512)