Halcon三 依据点关系计算物体三维位姿Halcon
1.set_origin_pose( : : PoseIn, DX, DY, DZ : PoseNewOrigin)
平移POSEIN的原点,输出为新的原点。注意,平移沿着OBJ的坐标新进行,而非沿着摄像机的坐标系进行。
2.disp_3d_coord_system (WindowHandle, CamParam, Pose, 0.02)
内部函数,显示世界坐系的坐标轴
3.determine_control_points (Image, Intersection, RowCenter, ColCenter)
内部函数,找到两个圆形洞,一个矩形洞的交点中心坐标。
4.gen_cross_contour_xld( : Cross : Row, Col, Size, Angle : )
在输出点处产生十字交叉的XLD轮廓。
5.dev_clear_window( : : : )
关闭活动窗口
6.affine_trans_point_3d( : : HomMat3D, Px, Py, Pz : Qx, Qy, Qz)
点到点的三维变换,输入控制为其次变换矩阵,输出为新坐标系下的点坐标。
7.project_3d_point( : : X, Y, Z, CameraParam : Row, Column)
把摄像机坐标下的点投影到图像坐标系,输出为图像坐标系下的行列坐标。
* Set image path and name
ImgPath := '3d_machine_vision/pose/' //设定读取图像的路径//
ImgName := 'metal_part' //设定图像名称//
* Read reference image
read_image (ImageRef, ImgPath+'calib') //读取图像//
* Define camera parameters (the exterior camera parameters define the world coordinate system)
CamParam := [1.222445e-002,-2.610410e+003,7.395958e-006,7.400000e-006,3.031241e+002,2.341259e+002,640,480] //设定已知相机内参数//
* Reopen the window to get the WindowHandle
dev_close_window ()
get_image_size (ImageRef, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* Define WCS
find_caltab (ImageRef, Caltab, 'caltab_30mm.descr', 3, 112, 5) //输出标定板区域//
find_marks_and_pose (ImageRef, Caltab, 'caltab_30mm.descr', CamParam, 128, 10, 18, 0.9, 15, 100, RCoord, CCoord, PoseOfWCS) //输出标定点的图像坐标及标定板在摄像机坐标系下的初步位姿//
*
* Modify the pose of the WCS in order to modify the world coordinate system
*
if (true)
* If the pose is only to be shifted, you can use set_origin_pose
set_origin_pose (PoseOfWCS, -0.0568, 0.0372, 0, PoseOfWCS)
* But you may also rotate the respective coordinate system, or apply other transformations.
* This can be done based on homogenous transformation matrices
pose_to_hom_mat3d (PoseOfWCS, camHwcs)//输出世界坐标相对于摄像机坐标的齐次变换矩阵//
hom_mat3d_rotate_local (camHwcs, rad(180), 'x', camHwcs)//世界坐标绕着自身X轴转180,输出为
齐次变换矩阵//
hom_mat3d_to_pose (camHwcs, PoseOfWCS)//输出世界坐标系在摄像机坐标系中的位姿//
endif
dev_display (ImageRef)
hom_mat3d_to_pose (camHwcs, Pose))//输出世界坐标系在摄像机坐标系中的位姿//
disp_3d_coord_system (WindowHandle, CamParam, Pose, 0.02)//显示世界坐系的坐标轴//
*
* Select an image (1, 2, or 3)
*
ImgNum := 1
*
read_image (Image, ImgPath+ImgName+'_'+ImgNum$'02d')
* Define object coordinates of control points
ShiftXObj := 5.5/1000.0 //世界坐标系中控制点距离原点X方向的距离//
ShiftYObj := 5.15/1000.0 //世界坐标系中控制点距离原点Y方向的距离//
ControlX := [18.73,-5.35,13.05, 0.00]/1000.0+ShiftXObj
ControlY := [27.52,27.68, 0.00, 0.00]/1000.0+ShiftYObj
ControlZ := [ 0.00, 0.00, 0.00, 0.00] //控制点的世界坐标//
dev_set_color ('green')
* Determine the image coordinates of the control points (here: via find_caltab and find_marks_and_pose)
determine_control_points (Image, Intersection, RowCenter, ColCenter)
* Visualize control point
disp_message (WindowHandle, 'Extracted control points', 'window', -1, -1, 'green', 'false')
gen_cross_contour_xld (Cross, RowCenter, ColCenter, 6, 0.785398)//在输出点坐标处输出XLD轮廓//
dev_display (Cross) //显示XLD轮廓//
disp_continue_message (WindowHandle, 'black', 'true')//窗口显示F5继续//
stop () //程序暂停,等待继续执行按钮//
* Determine the pose of the object ...
vector_to_pose (ControlX, ControlY, ControlZ, RowCenter, ColCenter, CamParam, 'iterative', 'error', PoseOfObject, Errors) //根据4个控制点在世界坐标和图像坐
标之间的关系,得到物体坐标系在摄像机坐标系下的位姿//
* Transform the poses into homogeneous transformation matrices
pose_to_hom_mat3d (PoseOfWCS, camHwcs)//世界坐标在摄像机坐标下的齐次变换矩阵//
pose_to_hom_mat3d (PoseOfObject, camHobj)//物体坐标系在摄像机坐标系下的齐次变换矩阵//
* Determine the transformation matrix from object coordinates into world coordinates
hom_mat3d_invert (camHwcs, wcsHcam) //求世界坐标在摄像机坐标坐标系下矩阵的逆矩阵//
hom_mat3d_compose (wcsHcam, camHobj, wcsHobj)//相机对世界坐标矩阵乘以物体系对世界坐标系
矩阵,得到物体对世界坐标系的齐次变换矩阵//
* Visualize the results
dev_clear_window () //关闭活动窗口//
dev_display (Image)
dev_set_color ('green') //设置接下来要显示部分的颜色//
disp_coordinate_system_3d (WindowHandle, CamParam, camHwcs, 'WCS') //显示世界坐标系,为绿色//
dev_set_color ('red')
disp_coordinate_system_3d (WindowHandle, CamParam, camHobj, 'OBJ')//显示物体坐标系,红色//
* Define some 3D object coordinates of points (here: the four corners of the rectangular hole)
CornersXObj := [0.89, 0.77, 12.12, 12.18]/1000.0+ShiftXObj //角点物体坐标系下的X坐标//
CornersYObj := [21.63, 8.47, 8.45, 21.51]/1000.0+ShiftYObj//角点在物体坐标系下的Y坐标//
CornersZObj := [0,0,0,0] //角点在物体坐标系下的Z坐标//
* Transform the 3D object coordinates into the world coordinate system
affine_trans_point_3d (wcsHobj, CornersXObj, CornersYObj, CornersZObj, CornersXWCS, CornersYWCS, CornersZWCS) //转换物体坐标系中的点进入世界坐标系//
* Transform the 3D object coordinates into the image coordinate system and display the respective points
affine_trans_point_3d (camHobj, CornersXObj, CornersYObj, CornersZObj, CornersXCam, CornersYCam, CornersZCam) //转换物体坐标系中的点进入摄像机坐标系//
project_3d_point (CornersXCam, CornersYCam, CornersZCam, CamParam, CornersRow, CornersCol)
//把摄像机坐标系中的3D点投影到图像坐标//
dev_set_color ('blue')
gen_cross_contour_xld (Cross, CornersRow, CornersCol, 6, 0.785398)//在图像中4个角点出产生交叉线//
dev_display (Cross)
* Display the 3D object coordinates and the 3D coordinates in the world coordinate system
CornersXObjmm := CornersXObj*1000.0
CornersYObjmm := CornersYObj*1000.0
CornersZObjmm := CornersZObj*1000.0
CornersXWCSmm := CornersXWCS*1000.0
CornersYWCSmm := CornersYWCS*1000.0
CornersZWCSmm := CornersZWCS*1000.0 //米转化成毫米单位//
disp_message (WindowHandle, 'Object coordinates:', 'window', 10, 10, 'red', 'false')
disp_message (WindowHandle, 'World coordinates:', 'window', 10, 200, 'green', 'false')
//显示信息//
for i := 1 to |CornersRow| by 1
disp_message (WindowHandle, i, 'window', CornersRow[i-1], CornersCol[i-1], 'blue', 'false')
disp_message (WindowHandle, i+':', 'window', 30+i*20, 10, 'red', 'false')
disp_message (WindowHandle, '('+CornersXObjmm[i-1]$'.2f'+','+CornersYObjmm[i-1]$'.2f'+','+CornersZObjmm[i-1]$'.2f'+') [mm]', 'window', 30+i*20, 30, 'red', 'false')
dev_set_color ('green')
disp_message (WindowHandle, i+':', 'window', 30+i*20, 200, 'green', 'false')
disp_message (WindowHandle, '('+CornersXWCSmm[i-1]$'.2f'+','+CornersYWCSmm[i-1]$'.2f'+','+CornersZWCSmm[i-1]$'.2f'+') [mm]', 'window', 30+i*20, 220, 'green', 'false')
endfor //分别在物体坐标系和世界坐标系下显示4个角点的坐标//
8.1 绿色交叉线处为控制点
Halcon三 依据点关系计算物体三维位姿Halcon的更多相关文章
- EF Core 快速上手——EF Core的三种主要关系类型
系列文章 EF Core 快速上手--EF Core 入门 本节导航 三种数据库关系类型建模 Migration方式创建和习修改数据库 定义和创建应用DbContext 将复杂查询拆分为子查询 本 ...
- C#的百度地图开发(三)依据坐标获取位置、商圈及周边信息
原文:C#的百度地图开发(三)依据坐标获取位置.商圈及周边信息 我们得到了百度坐标,现在依据这一坐标来获取相应的信息.下面是相应的代码 public class BaiduMap { /// < ...
- C++中的三种继承关系
C++中的三种继承关系 先看类中声明成员时的三种访问权限 public : 可以被任意实体访问 protected : 只允许子类及本类的成员函数访问 private : 只允许本类的成员函数访问 在 ...
- python小练习:使用循环和函数实现一个摇骰子小游戏。游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“大”,3<=总值<=10为“小”。然后告诉玩家猜对或者是猜错的结果。
python小练习:使用循环和函数实现一个摇骰子小游戏.游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“ ...
- PD的CDM模型中的三种实体关系
PD的CDM模型中的三种实体关系 本文摘自:http://www.cnblogs.com/syf/articles/2480580.html PD 正向工程使用说明:http://download.c ...
- [LINQ2Dapper]最完整Dapper To Linq框架(三)---实体类关系映射
此特性需要安装Kogel.Dapper.Mssql或者Oracle 3.06及以上版本,实体类层需要安装Kogel.Dapper.Extension 3.06及以上版本 目录 [LINQ2Dapper ...
- 李飞飞团队最新论文:基于anchor关键点的类别级物体6D位姿跟踪
6-PACK: Category-level 6D Pose Tracker with Anchor-Based Keypoints 论文地址: 6-PACK: Category-level 6D P ...
- nyis oj 68 三点顺序 (计算几何基础)
三点顺序 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 如今给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,如今让你推断A,B,C是顺时针给出的还是逆 ...
- halcon三种模板匹配方法
halcon有三种模板匹配方法:即Component-Based.Gray-Value-Based.Shaped_based,分别是基于组件(或成分.元素)的匹配,基于灰度值的匹配和基于形状的匹配,此 ...
随机推荐
- UE4中动画蒙太奇的合成
在游戏中的技能施法动作是可以通过软件合成的,笔者在这里介绍一种用UE4合成多个动画的操作. 在UE4中角色的动作可以由多种方式达成,一种是混合空间,例如角色的跑动和跳跃,其中的动作是由状态机控制的,原 ...
- 洛谷 P1251 餐巾计划问题(线性规划网络优化)【费用流】
(题外话:心塞...大部分时间都在debug,拆点忘记加N,总边数算错,数据类型标错,字母写错......) 题目链接:https://www.luogu.org/problemnew/show/P1 ...
- Docker存储方式选型建议
转自:https://segmentfault.com/a/1190000007168476 第一部分 问题诊断 事情从一次实施项目说起,我们需要帮助客户将他们的应用容器化并在数人云平台上发布此应用. ...
- nodejs实现mysql数据库的简单例子
在MySQLWorkbench中创建table存储用户的tokenId信息: use token; SET FOREIGN_KEY_CHECKS = ; DROP TABLE IF EXISTS `a ...
- windows禁用端口命令
netstat -aon|findstr 1099 找出占用1099端口的进程 然后关闭占用该端口的进程:taskkill -f -pid 3756(进程id)
- zookeeper 集群安装与配置
Zookeeper安装和配置 准备工作 安装 JDK,此步略. 下载 zookeeper wget http://archive.apache.org/dist/zookeeper/zookeeper ...
- Spring4自动装配(default-autowire)
§1 什么是自动装配? Spring IoC容器可以自动装配(autowire)相互协作bean之间的关联关系.因此,如果可能的话,可以自动让Spring通过检查BeanFactory中的内容,来替我 ...
- git 代码比较工具,分支冲突解决
下载地址:https://www.scootersoftware.com/BCompare-4.2.9.23626.exe
- Rendering Engine 主流的浏览器内核(排版引擎、渲染引擎、解释引擎)有哪几种,分别的特点
一.A web browser engine A rendering engine is software that draws text and images on the screen. The ...
- GIt帮助文档之创建新的Git仓库——现有目录下,通过导入所有文件来创建
1.新建仓库初始化操作 1.1打开Git Bash命令窗口,切换到项目文件夹目录: $ cd weixin 1.2执行命令: $ git init 初始化操作,把项目weixin纳入Git管理.初始化 ...