移除3D对象的某些部分点云
1,目的
- 移除3D对象指定区域的点云。
- 效果
2,原理。
- 通过投影剔除指定区域外的点云数据。
3,主要的算子。
3.1,gen_image_gray_ramp
是 Halcon 中用于生成线性灰度渐变图像的算子
-
功能概述
- 数学原理
生成的图像灰度值按公式计算:
I m a g e G r a y R a m p ( r , c ) = A l p h a ∗ ( r − R o w ) + B e t a ∗ ( c − C o l u m n ) + M e a n ImageGrayRamp(r,c) = Alpha*(r-Row) + Beta*(c-Column) + Mean ImageGrayRamp(r,c)=Alpha∗(r−Row)+Beta∗(c−Column)+Mean
其中 (r,c) 为像素坐标,结果灰度值会被裁剪到 [0,255](byte 类型)。 - 典型用途
模拟光照渐变效果
作为图像处理的测试输入
- 数学原理
-
参数详解
参数 | 说明 |
---|---|
Alpha | 行方向(Y轴)的灰度变化斜率,正负控制渐变方向 |
Beta | 列方向(X轴)的灰度变化斜率 |
Mean | 灰度基准值,决定整体亮度水平 |
Row/Column | 渐变中心坐标(默认 Height/2, Width/2) |
Width/Height | 生成图像的尺寸(单位:像素) |
-
技术特性
数据类型:输出图像为 byte 类型(8位无符号整型)
多线程支持:算子可并行执行(reentrant 属性) -
应用示例
生成一个 512×512 的斜向灰度渐变图像(左上暗、右下亮):
gen_image_gray_ramp(ImageRamp, 0.2, 0.2, 50, 256, 256, 512, 512)
- 注意事项
若 Alpha 和 Beta 均为 0,图像将呈现均匀灰度(值为 Mean)
超出 [0,255] 的灰度值会被自动截断
3.2,reduce_object_model_3d_by_view
基于虚拟视角的 3D 模型智能降采样 的核心算子,其功能是通过投影剔除指定区域外的点云数据,优化模型处理效率
-
核心功能
视窗感知降采样
将 3D 模型投影到虚拟相机视图平面,仅保留落在 Region 参数指定区域内的点
自动剔除背面或遮挡部分,保留可见区域细节
工业应用价值
数据量减少 70%-90%,同时保持关键特征
适用于视觉检测、机器人抓取等需实时处理的场景 -
参数详解
参数 | 作用 | 示例值 |
---|---|---|
ObjectModel3D | 输入待处理的 3D 对象模型 | 从文件读取的模型数据 |
CamParam | 虚拟相机内参(焦距、畸变等) | 标定后的相机参数矩阵 |
Pose | 虚拟相机位姿(外参),定义投影视角 | 6D 位姿向量 [X,Y,Z,Rx,Ry,Rz] |
Region | ROI 区域(可空) | 指定保留点的投影范围 |
ObjectModel3DReduced | 输出的简化模型 | 降采样后的模型句柄 |
▶️ 注:若 Region 为空,则默认保留所有投影到图像平面内的点
-
注意事项
内存管理:输出模型使用后需手动释放 clear_object_model_3d
网格处理:若输入为网格模型,仅当所有顶点均在 Region 内时面片才会保留
并行支持:算子支持多线程加速(reentrant 模式) -
应用场景
目标定位:配合 remove_background_for_3d_object_localization 剔除背景干扰
实时检测:简化模型以提升匹配算法速度
4,代码。
* 参考案例库:reduce_object_model_3d_by_view.hdev* ********************************************************
* This example program shows how to remove parts of a
* 3D object model using reduce_object_model_3d_by_view.
* In particular, the user can rotate and translate the
* object and then draw a region that cuts out all points
* of the model that are projected into this region.
* All faces that base on one of these points are removed.
* ********************************************************
*
* Read 3D object model
read_object_model_3d ('glass_mug', 'cm', [], [], ObjectModel3D, Status)
*
* Prepare the Visualization
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 768, 512, 'black', WindowHandle)
dev_set_draw ('margin')
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
*
CamParam := [0.01,0,7e-6,7e-6,384,255,768,512]
Pose := [-0.1e-3,-0.47e-3,55.8e-3,104.5,358.0,353.0,0]*
* 生成一个线性灰度渐变的图像
* Alpha:行方向灰度变化率;Beta:列方向灰度变化率;Mean:灰度基准值;Row/Column:渐变中心坐标
* 生成图像的像素灰度值:ImageGrayRamp(r,c)=Alpha*(r-Row)+Beta*(c-Column)+Mean
* r,c为像素坐标,灰度值会被裁剪至[0,255](byte类型)
gen_image_gray_ramp (Ramp, -0.5, 0, 300, 0, 512, 768, 512)
*
* Show current 3D object model
Title := '移动并旋转对象到适当的姿态,'
Title[1] := '然后选择要修剪的区域。'
Instructions[0] := 'Rotate: Left button'
Instructions[1] := 'Zoom: Shift + left button'
Instructions[2] := 'Move: Ctrl + left button'
* 'disp_pose_0':显示第一个模型的坐标系
* 'attribute_1':第二个模型渲染形式。值为points:渲染为点云;wireframe:渲染为线框网格;surface:渲染为实体表面
* 'disp_background':是否显示背景
GenParamName := ['color_0','disp_pose_0','alpha_0','attribute_1']
GenParamValue := ['yellow','true',0.3,'points']
GenParamName := [GenParamName,'color_1','disp_background']
GenParamValue := [GenParamValue,'blue','true']
* 背景图像
dev_display (Ramp)visualize_object_model_3d (WindowHandle, [ObjectModel3D,ObjectModel3D], CamParam, Pose, GenParamName, GenParamValue, Title, [], Instructions, Pose)
*
* Now, select the points to be trimmed off by entering a
* suitable region
Message := '现在用鼠标绘制区域以剪切模型的一部分'
Message[1] := '(Right click to finish)'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
* Wait for a region
dev_set_line_width (3)
dev_set_color ('red')
draw_region (Region, WindowHandle)
gen_rectangle1 (Rectangle, 0, 0, CamParam[7], CamParam[6])
* 保留的区域
difference (Rectangle, Region, RegionComplement)
* 通过投影剔除指定区域外的点云数据,仅保留落在 RegionComplement 参数指定区域内的点
reduce_object_model_3d_by_view (RegionComplement, ObjectModel3D, CamParam, Pose, ObjectModel3DReduced)
*
* Visualize the result
Title := 'Resulting reduced 3d object model'
dev_display (Ramp)
visualize_object_model_3d (WindowHandle, [ObjectModel3DReduced,ObjectModel3DReduced], CamParam, Pose, GenParamName, GenParamValue, Title, [], Instructions, Pose)
clear_object_model_3d ([ObjectModel3D,ObjectModel3DReduced])