引言
线扫激光得到图片有两张,一张是深度图,一张是灰度图,基恩士的会将两张图像合成显示,看起来更加自然,如何用Halcon实现同样的功能呢 。
这两张图像就是我们用来使用的示例图片,其中左边是深度图,右边是灰度图。
我们要实现的效果是:
第一张深度附加灰度显示,第二张是单独深度图显示。
下面我们将一步一步实现它:
首先我们需要定义一些参数
*Z比例系数,Z偏差量,X比例系数,Y比例系数,无效值,最小颜色,最大颜色,灰度比例
XScale:=0.005
YScale:=0.005
ZScale:=0.0008
ZOffset:=-32768
InvalidValue:=1000
min_Color:=180
max_Color:=0
gray_mix_percent:=0.8
*高度范围,[MinHeight,MaxHeight],如果无值的话,自动计算高度
HeightRange:=[]
*是否输出HSV图,是否生成点云
NeedOutputHSVImage:='true'
NeedOutputOM3:='true'
1、剔除无效值,将图像转为实际高度图像,并获取图像最大最小高度。
get_domain (ImageH, Domain)
min_max_gray (Domain, ImageH, 0, Min, Max, Range0)
threshold (ImageH, Region, InvalidValue, Max)
convert_image_type (ImageH, ImageH, 'real')
scale_image (ImageH, ImageHOfReal, ZScale, ZScale*ZOffset)
min_max_gray (Region, ImageHOfReal, 0, DeepMin, DeepMax, Range0)
2、将高度图转为HSV格式的图像
min_Color:=180
max_Color:=0
Convert_K :=(max_Color - min_Color)*1.0 / (DeepMax - DeepMin)
Convert_B := min_Color - Convert_K * DeepMin*1.0
reduce_domain (ImageHOfReal, Region, HImageOut)
scale_image (HImageOut, ImageScaled2, Convert_K, Convert_B)
convert_image_type (ImageScaled2, ImageConverted, 'byte')
gen_image_proto (ImageConverted, ImageCleared, 255)
trans_to_rgb (ImageConverted, ImageCleared, ImageCleared, ImageRed1, ImageGreen1, ImageBlue1, 'hsv')
compose3 (ImageRed1, ImageGreen1, ImageBlue1, HSVImageForHeight)
3、将灰度图注入高度图像的HSV图像中
read_image (ImageL, 'D:/收集示例图片/GTA/20230828163136L.bmp')
get_image_size (ImageL, Width, Height)
gray_mix_percent:=0.7
*VImage
scale_image (ImageL, VImage, gray_mix_percent, 255 * (1 - gray_mix_percent))
*SImage
Saturation :=(1 - gray_mix_percent) * 512
gen_image_surface_first_order (SImage, 'byte', 0, 0, Saturation, 0, 0, Width, Height)
*ToRGB
trans_to_rgb (ImageConverted, SImage, VImage, ImageRed, ImageGreen, ImageBlue, 'hsv')
compose3 (ImageRed, ImageGreen, ImageBlue, HSVImageForHL)
4、将深度图转为3D点云模型
gen_image_surface_first_order (ImageX, 'real', 0, XScale, 0, 0, 0, Width, Height)
gen_image_surface_first_order(ImageY,'real',YScale,0,0,0, 0,Width,Height)
xyz_to_object_model_3d (ImageX, ImageY, HImageOut, ObjectModel3D)
5、分别展示不同效果的3D点云
*第一种效果,Halcon lut颜射映射
visualize_object_model_3d (WindowHandle, ObjectModel3D, [], [], ['disp_pose','color_attrib','lut'], ['true','coord_z','color1'], [], [], [], PoseOut)
*第二种效果,Halcon 高度图HSV
HSVToOM3 (HSVImageForHeight, ObjectModel3D)
visualize_object_model_3d (WindowHandle, ObjectModel3D, [], [], ['disp_pose','red_channel_attrib','green_channel_attrib','blue_channel_attrib'], ['false','&red', '&green', '&blue'], [], [], [], PoseOut)
*第三种效果,Halcon 高度灰度图HSV
HSVToOM3 (HSVImageForHL, ObjectModel3D)
visualize_object_model_3d (WindowHandle, ObjectModel3D, [], [], ['disp_pose','red_channel_attrib','green_channel_attrib','blue_channel_attrib'], ['false','&red', '&green', '&blue'], [], [], [], PoseOut)
对于HSVToOM3 (HSVImageForHL, ObjectModel3D),一下是内容
access_channel (MultiChannelImage1, Image1, 1)
get_domain (Image1, Domain)
get_region_points (Domain, Rows, Columns)
get_grayval (Image1, Rows, Columns, Grayval)
set_object_model_3d_attrib_mod (ObjectModel3D, ['&red'], ['points'], [Grayval])
access_channel (MultiChannelImage1, Image2, 2)
get_domain (Image2, Domain)
get_region_points (Domain, Rows1, Columns1)
get_grayval (Image2, Rows1, Columns1, Grayval1)
set_object_model_3d_attrib_mod (ObjectModel3D, ['&green'], ['points'], [Grayval1])
access_channel (MultiChannelImage1, Image3, 3)
get_domain (Image3, Domain)
get_region_points (Domain, Rows2, Columns2)
get_grayval (Image3, Rows2, Columns2, Grayval2)
set_object_model_3d_attrib_mod (ObjectModel3D, ['&blue'], ['points'], [Grayval2])
return ()