Halcon 的一些常用算子,持续更新,希望各位大佬们多多指教!
Halcon 打开相机 采集
open_framegrabber (‘GigEVision2’, 0, 0, 0,
0, 0, 0, ‘progressive’, -1, ‘default’, -1, ‘false’, ‘default’, ‘default’, 0,
-1, AcqHandle)
grab_image_start (AcqHandle, -1)
grab_image_async (Image, AcqHandle, -1) //采集
close_framegrabber (AcqHandle) //关闭相机
将读取的照片保存到本地/从本地读取图片
write_image (Right, ‘bmp’, 0, ‘C:/Users/admin/Pictures/copy’)
read_image (Image,
‘C:/Users/admin/Pictures/22.jpg’)
rgb1_to_gray (Image, GrayImage)//转换为灰度图像
将模板写文件/从文件中读出模板
write_shape_model (ModelID,
‘D:/CCD/Release/1.shm’)
read_shape_model (‘D:/CCD/Release/1.shm’,
ModelID1)
设置边缘是否判断
set_system (‘border_shape_models’, ‘false’) false 为不进行判断,true 进行判断
查找模板匹配
find_shape_model (Image, ModelID, rad(0),
rad(360), 0.7, 1, 0.5, ‘least_squares’, [3,1], 1, Row, Column, Angle,
Score)
显示文字 角度
disp_message (200000, deg(Angle), ‘window’,
Row, Column, ‘black’, ‘true’)
disp_arrow (WindowHandle, 10, 10, 118, 118,9)//显示箭头
set_tposition (WindowHandle,110,110)//显示光标 与write_string连用
write_string (WindowHandle, ‘hello’)//显示文字
smallest_circle (ModelRegion, Row1,
Column1, Radius)//显示角度
阙值分割
threshold (Image, Region, 80, 255)
connection (Region, ConnectedRegions) //分割
fill_up (SelectedRegions, RegionFillUp) //填充
按圆度/面积来筛选图像
select_shape (ConnectedRegions,
SelectedRegionP, ‘circularity’, ‘and’, 0.7, 1)
select_shape (SelectedRegionP,
SelectedRegions, ‘area’, ‘and’, 70000, 150000)
按圆度/面积来筛选图像
select_shape (ConnectedRegions,
SelectedRegionP, ‘circularity’, ‘and’, 0.7, 1)
select_shape (SelectedRegionP,
SelectedRegions, ‘area’, ‘and’, 70000, 150000)
region_features (RegionDilation, ‘area’, Value)//查看筛选的值
扩张圆
dilation_circle (RegionFillUp, RegionDilation, 5.5)
//
gen_contour_region_xld (RegionDilation, Contours, ‘border’)
//Xld 的拟合操作(fit_***_contour_xld) 把不完整的形状拟合完整
fit_circle_contour_xld (Contours, ‘algebraic’, -1, 0, 0, 3, 2, Row2, Column2, Radius1, StartPhi, EndPhi, PointOrder)//
获取面积,坐标
area_center (ImageReduced, Area, RowRef, ColumnRef)