1.set_origin_pose( : : PoseInDXDYDZ : 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 : RowColSizeAngle : )

在输出点处产生十字交叉的XLD轮廓。

5.dev_clear_window( : : : )

关闭活动窗口

6.affine_trans_point_3d( : : HomMat3DPxPyPz : QxQyQz)

点到点的三维变换,输入控制为其次变换矩阵,输出为新坐标系下的点坐标。

7.project_3d_point( : : XYZCameraParam : RowColumn)

把摄像机坐标下的点投影到图像坐标系,输出为图像坐标系下的行列坐标。

* 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 绿色交叉线处为控制点
                   8.2 最后的窗口显示结果

Halcon三 依据点关系计算物体三维位姿Halcon的更多相关文章

  1. EF Core 快速上手——EF Core的三种主要关系类型

    系列文章 EF Core 快速上手--EF Core 入门 本节导航 三种数据库关系类型建模 Migration方式创建和习修改数据库 定义和创建应用DbContext 将复杂查询拆分为子查询   本 ...

  2. C#的百度地图开发(三)依据坐标获取位置、商圈及周边信息

    原文:C#的百度地图开发(三)依据坐标获取位置.商圈及周边信息 我们得到了百度坐标,现在依据这一坐标来获取相应的信息.下面是相应的代码 public class BaiduMap { /// < ...

  3. C++中的三种继承关系

    C++中的三种继承关系 先看类中声明成员时的三种访问权限 public : 可以被任意实体访问 protected : 只允许子类及本类的成员函数访问 private : 只允许本类的成员函数访问 在 ...

  4. python小练习:使用循环和函数实现一个摇骰子小游戏。游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“大”,3<=总值<=10为“小”。然后告诉玩家猜对或者是猜错的结果。

    python小练习:使用循环和函数实现一个摇骰子小游戏.游戏规则如下:游戏开始,首先玩家选择Big or Small(押大小),选择完成后开始摇三个骰子,计算总值,11<=总值<=18为“ ...

  5. PD的CDM模型中的三种实体关系

    PD的CDM模型中的三种实体关系 本文摘自:http://www.cnblogs.com/syf/articles/2480580.html PD 正向工程使用说明:http://download.c ...

  6. [LINQ2Dapper]最完整Dapper To Linq框架(三)---实体类关系映射

    此特性需要安装Kogel.Dapper.Mssql或者Oracle 3.06及以上版本,实体类层需要安装Kogel.Dapper.Extension 3.06及以上版本 目录 [LINQ2Dapper ...

  7. 李飞飞团队最新论文:基于anchor关键点的类别级物体6D位姿跟踪

    6-PACK: Category-level 6D Pose Tracker with Anchor-Based Keypoints 论文地址: 6-PACK: Category-level 6D P ...

  8. nyis oj 68 三点顺序 (计算几何基础)

    三点顺序 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 如今给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,如今让你推断A,B,C是顺时针给出的还是逆 ...

  9. halcon三种模板匹配方法

    halcon有三种模板匹配方法:即Component-Based.Gray-Value-Based.Shaped_based,分别是基于组件(或成分.元素)的匹配,基于灰度值的匹配和基于形状的匹配,此 ...

随机推荐

  1. ajax 跨域解决方法

    最近在开发过程中,使用ajax去异步调取图片.在开发中这个功能没什么问题,可以后来提测,重新部署之后就有问题了,这就是ajax的跨域问题. ajax核心对象XMLHttpRequest本身是不支持跨域 ...

  2. MVC四大筛选器—AuthorizeFilter

    在Action的执行中包括两个重要的部分,一个是Action方法本身逻辑代码的执行,第二个就是Action方法的筛选器的执行. MVC4中筛选器都是以AOP(面向方面编程)的方式来设计的,通过对Act ...

  3. java一个字符串中出现次数最多的字符以及次数

    学习了别人的方法,觉得挺巧妙的.就是每次取出字符串的第一个字符,将字符串中与第一个字符相同的字符全部删除掉,然后通过计算删除前后字符串的长度来确定该字符在字符串中出现的次数,最终比较出出现最多次的字符 ...

  4. python第十四课--排序及自定义函数之自定义函数(案例一)

    案例一: 演示自定义函数的使用:包含:1).定义格式的掌握2).函数的好处 自定义函数:实现打印矩形的操作两个原则需要考虑:1).有没有形参?有,2个 2).有没有返回值?没有. def printR ...

  5. 调试cnn-Sentence-Classifier遇到的问题

    运行train文件训练模型出现了以下错误: train文件在app文件目录下: raw_vectors.txt文件则在cnn-Sentence-Classifier目录下: 这是train代码调用re ...

  6. 更改backend

    keras默认的backend是tensorflow,更改成theano方法如下: vim ~/.keras/keras.json { "image_dim_ordering":& ...

  7. .Net实现Word文档及导出

    参考网址: http://www.jb51.net/article/25062.htm(实用性) http://wenku.baidu.com/link?url=44O7Dua49DrZ-PF2QU7 ...

  8. 【jq】插件—弹出层layer.js

    layer.js包含了所有的层级情形,并且附加的有:tab层,相册层.webIM层. 适用于移动版本的layer.js   为layer for mobile 配套的layui 非常适合用于后台系统的 ...

  9. 笔记:iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)(别人的代码直接复制过来的,我脸皮有点厚)

    NSString* str=@"hello";//存在代码区,不可变 NSLog(@"%@",str); //1.[字符串插入] NSMutableString ...

  10. GoogleTest初探(1)

    此篇主要了解一下GoogleTest中的断言. 总的来说,GoogleTest中的断言分为两大类:EXPECT_*和ASSERT_*,这两者在测试成功或失败后均会给出测试报告,区别是前者在测试失败后会 ...