基于halcon的眼在手外(Eye-to-Hand)标定

前言

        上个月写了一个《基于halcon的眼在手上(Eye-in-Hand)标定》的文章,通过官方的示例代码进行了简单的叙述,想学习的小伙伴可以点击链接进行学习。之前博主认为眼在手上(Eye-in-Hand)的案例更多,或者说是使用场景更多的。但是,最近在学习机械臂的运动规划方向的内容后,发现对于机械臂避障这一块,眼在手上的实施方式是不太可能实现避障的。主要问题在于,眼在手上这种方式,只能看到机械臂前端的物体,而忽略机械臂周围的物体,没有周围物体的位置,那么机械臂在运动过程中,就难以保证机械臂不会碰撞。而眼在手外则可以看到机械臂和机械臂周围的物体,减小机械臂与周围物体碰撞的概率。

        (emmm。。这里得提一下,对机械臂的运动规划这一部分内容通常是在Moveit!中进行的,当然肯定会有在该平台下的手眼标定方案,需要的小伙伴请自行学习。由于我感觉halcon的手眼标定精度是不错的,所以还是记录一下啦~)

halcon示例代码

halcon示例代码

* 
* This example explains how to use the hand eye calibration for the case where
* the camera is stationary with respect to the robot and the calibration
* object is attached to the robot arm.
* In this case, the goal of the hand eye calibration
* is to determine two unknown poses:
* - the pose of the robot base in the coordinate system
*   of the camera (BaseInCamPose).
* - the pose of the calibration object in the coordinate system of the
*   tool (CalObjInToolPose)
* Theoretically, as input the method needs at least 3 poses of the
* calibration object in the camera coordinate system and the corresponding
* poses of the robot tool in the coordinate system of the
* robot base. However it is recommended
* to use at least 10 Poses.
* The poses of the calibration object are obtained from images of the
* calibration object recorded with the stationary camera.
* The calibration object is moved by the robot with respect to the camera.
* To obtain good calibration results, it its essential to position
* the calibration object with respect to the camera so that the object appears
* tilted in the image.
* After the hand eye calibration, the computed transformations are
* extracted and used to compute the pose of the calibration object in the
* camera coordinate system.
dev_update_off ()
* Directories with calibration images and data files
ImageNameStart := '3d_machine_vision/hand_eye/stationarycam_calib3cm_'
DataNameStart := 'hand_eye/stationarycam_'
NumImages := 17
* Read image
read_image (Image, ImageNameStart + '00')
get_image_size (Image, Width, Height)
* Open window
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_line_width (2)
dev_set_draw ('margin')
dev_display (Image)
* Set font
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
* Load the calibration plate description file.
* Make sure that the file is in the current directory,
* the HALCONROOT/calib directory, or use an absolut path
CalTabFile := 'caltab_30mm.descr'
* Read the initial values for the internal camera parameters
read_cam_par (DataNameStart + 'start_campar.dat', StartCamParam)
* Create the calibration model for the hand eye calibration
create_calib_data ('hand_eye_stationary_cam', 1, 1, CalibDataID)
set_calib_data_cam_param (CalibDataID, 0, [], StartCamParam)
set_calib_data_calib_object (CalibDataID, 0, CalTabFile)
set_calib_data (CalibDataID, 'model', 'general', 'optimization_method', 'nonlinear')
disp_message (WindowHandle, 'The calibration data model was created', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Start the loop over the calibration images
for I := 0 to NumImages - 1 by 1
    read_image (Image, ImageNameStart + I$'02d')
    * Search for the calibration plate, extract the marks and the
    * pose of it, and store the results in the calibration data model of the
    * hand-eye calibration
    find_calib_object (Image, CalibDataID, 0, 0, I, [], [])
    get_calib_data_observ_contours (Caltab, CalibDataID, 'caltab', 0, 0, I)
    get_calib_data_observ_points (CalibDataID, 0, 0, I, RCoord, CCoord, Index, CalObjInCamPose)
    * Visualize the extracted calibration marks and the estimated pose (coordinate system)
    dev_set_color ('green')
    dev_display (Image)
    dev_display (Caltab)
    dev_set_color ('yellow')
    disp_cross (WindowHandle, RCoord, CCoord, 6, 0)
    dev_set_colored (3)
    disp_3d_coord_system (WindowHandle, StartCamParam, CalObjInCamPose, 0.01)
    * Read pose of tool in robot base coordinates (ToolInBasePose)
    read_pose (DataNameStart + 'robot_pose_' + I$'02d' + '.dat', ToolInBasePose)
    * Set the pose tool in robot base coordinates in the calibration data model
    set_calib_data (CalibDataID, 'tool', I, 'tool_in_base_pose', ToolInBasePose)
    * Uncomment to inspect visualization
*     disp_message (WindowHandle, 'Extracting data from calibration image ' + (I + 1) + ' of ' + NumImages, 'window', 12, 12, 'black', 'true')
*     disp_continue_message (WindowHandle, 'black', 'true')
*     stop ()
endfor
disp_message (WindowHandle, 'All relevant data has been set in the calibration data model', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Check the input poses for consistency
check_hand_eye_calibration_input_poses (CalibDataID, 0.05, 0.005, Warnings)
if (|Warnings| != 0)
    * There were problem detected in the input poses. Inspect Warnings and
    * remove erroneous poses with remove_calib_data and remove_calib_data_observ.
    dev_inspect_ctrl (Warnings)
    stop ()
endif
* Perform hand-eye calibration
* Internally before performing the hand-eye calibration the cameras are calibrated
* and the calibrated poses of the calibration object in the camera are used.
dev_display (Image)
disp_message (WindowHandle, 'Performing the hand-eye calibration', 'window', 12, 12, 'black', 'true')
calibrate_hand_eye (CalibDataID, Errors)
* Query the error of the camera calibration
get_calib_data (CalibDataID, 'model', 'general', 'camera_calib_error', CamCalibError)
* Query the camera parameters and the poses
get_calib_data (CalibDataID, 'camera', 0, 'params', CamParam)
* Get poses computed by the hand eye calibration
get_calib_data (CalibDataID, 'camera', 0, 'base_in_cam_pose', BaseInCamPose)
get_calib_data (CalibDataID, 'calib_obj', 0, 'obj_in_tool_pose', ObjInToolPose)
try
    * Store the camera parameters to file
    write_cam_par (CamParam, DataNameStart + 'final_campar.dat')
    * Save the hand eye calibration results to file
    write_pose (BaseInCamPose, DataNameStart + 'final_pose_cam_base.dat')
    write_pose (ObjInToolPose, DataNameStart + 'final_pose_tool_calplate.dat')
catch (Exception)
    * Do nothing
endtry
* Display calibration errors of the hand-eye calibration
disp_results (WindowHandle, CamCalibError, Errors)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* For the given camera, get the corresponding pose indices and calibration object indices
query_calib_data_observ_indices (CalibDataID, 'camera', 0, CalibObjIdx, PoseIds)
* Compute the pose of the calibration object in the camera coordinate
* system via calibrated poses and the ToolInBasePose and visualize it.
for I := 0 to NumImages - 1 by 1
    read_image (Image, ImageNameStart + I$'02d')
    * Obtain the pose of the tool in robot base coordinates used in the calibration.
    * The index corresponds to the index of the pose of the observation object.
    get_calib_data (CalibDataID, 'tool', PoseIds[I], 'tool_in_base_pose', ToolInBasePose)
    dev_display (Image)
    * Compute the pose of the calibration plate with respect to the camera
    * and visualize it
    calc_calplate_pose_stationarycam (ObjInToolPose, BaseInCamPose, ToolInBasePose, CalObjInCamPose)
    dev_set_colored (3)
    disp_3d_coord_system (WindowHandle, CamParam, CalObjInCamPose, 0.01)
    Message := 'Using the calibration results to display the'
    Message[1] := 'coordinate system in image ' + (I + 1) + ' of ' + NumImages
    disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    if (I < NumImages - 1)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
* Clear the data model
clear_calib_data (CalibDataID)
* 
* After the hand-eye calibration, the computed pose
* BaseInCamPose can be used in robotic grasping applications.
* To grasp an object with the robot, typically, its pose
* with respect to the camera is determined (which
* is simulated here by setting the object's pose to the
* pose of the calibration object)
ObjInCamPose := CalObjInCamPose
* If the tool coordinate system is placed at the gripper
* and an object detected at ObjInCamPose shall be grasped,
* the pose of the detected object relative
* to the robot base coordinate system has to be computed.
pose_invert (BaseInCamPose, CamInBasePose)
pose_compose (CamInBasePose, ObjInCamPose, ObjInBasePose)

解析

        和眼在手上一致,眼在手外的标定代码前面部分也是一些参数配置。比如:ImageNameStart和DataNameStart是文件地址起始部分路径(文件名相同部分)、NumImages为图像数量。

创建、设置标定模型

下面代码主要是用于创建标定模型:

* Read the initial values for the internal camera parameters
read_cam_par (DataNameStart + 'start_campar.dat', StartCamParam)
* Create the calibration model for the hand eye calibration
create_calib_data ('hand_eye_stationary_cam', 1, 1, CalibDataID)
set_calib_data_cam_param (CalibDataID, 0, [], StartCamParam)
set_calib_data_calib_object (CalibDataID, 0, CalTabFile)
set_calib_data (CalibDataID, 'model', 'general', 'optimization_method', 'nonlinear')

read_cam_par        读取相机内参;

create_calib_data        创建标定模型;

set_calib_data_cam_param        将相机内参设置到标定模型中;

set_calib_data_calib_object        获取标定板的描述文件;

set_calib_data        设置标定的一些参数;

读取标定图像

下面是for循环中的内容,主要功能为读取标定图像:

read_image (Image, ImageNameStart + I$'02d')
* Search for the calibration plate, extract the marks and the
* pose of it, and store the results in the calibration data model of the
* hand-eye calibration
find_calib_object (Image, CalibDataID, 0, 0, I, [], [])
get_calib_data_observ_contours (Caltab, CalibDataID, 'caltab', 0, 0, I)
get_calib_data_observ_points (CalibDataID, 0, 0, I, RCoord, CCoord, Index, CalObjInCamPose)

read_image        读取图像;

find_calib_object        寻找标定板;

get_calib_data_observ_contours        找到标定板,然后画轮廓;

get_calib_data_observ_points        找到标定板,然后画标定点;

读取工具坐标系位姿

每一张图像对应着一个机械臂末端夹具(工具坐标系)在机械臂基坐标系下的位姿

* Read pose of tool in robot base coordinates (ToolInBasePose)
read_pose (DataNameStart + 'robot_pose_' + I$'02d' + '.dat', ToolInBasePose)
* Set the pose tool in robot base coordinates in the calibration data model
set_calib_data (CalibDataID, 'tool', I, 'tool_in_base_pose', ToolInBasePose)

read_pose        读取工具坐标系在机械臂基坐标系下的位姿;

set_calib_data        将读取的结果设置到标定模型中;

手眼标定

参数读取和设置都完成之后,结下来就是手眼标定啦~

calibrate_hand_eye (CalibDataID, Errors)
* Query the error of the camera calibration
get_calib_data (CalibDataID, 'model', 'general', 'camera_calib_error', CamCalibError)
* Query the camera parameters and the poses
get_calib_data (CalibDataID, 'camera', 0, 'params', CamParam)
* Get poses computed by the hand eye calibration
get_calib_data (CalibDataID, 'camera', 0, 'base_in_cam_pose', BaseInCamPose)
get_calib_data (CalibDataID, 'calib_obj', 0, 'obj_in_tool_pose', ObjInToolPose)

calibrate_hand_eye        手眼标定;

get_calib_data         获取一些标定数据,这个算子有点特别,里面包含很多参数选择,这里就不进行叙述了。想要了解的小伙伴可以去halcon算子里面进行学习;

到这里标定就结束了。下面是保存参数。

write_cam_par (CamParam, DataNameStart + 'final_campar.dat')
write_pose (ToolInCamPose, DataNameStart + 'final_pose_cam_tool.dat')
write_pose (CalObjInBasePose, DataNameStart + 'final_pose_base_calplate.dat')
write_pose (PlaneInBasePose, DataNameStart + 'final_pose_base_plane.dat')

验证    

        在这里就不对验证进行解释了,简单来说就是根据以下三个坐标系进行转换:标定板坐标系相对于基座标系的转换关系、工具坐标系相对于相机坐标系的转换关系、工具坐标系相对于机械臂基座标的转换关系。这里进行一些数学计算,就能获得标定板坐标系在相机坐标系下的位置和姿态。注意这里不是识别标定板的结果,而是根据结果进行验证。

下面是一个比较好的结果(halcon示例结果):

可以看到坐标系和标定板的中心和姿态基本上是吻合的。这就是一个好的结果。  

-------------------------2024.06.27        留个坑,等我有空实验一下--------------

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/749254.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Embedding是什么?为什么重要?

本文为 Simon Willison 在 PyBay 上发表的演讲视频的文字改进版 原文链接&#xff1a; https://simonwillison.net/2023/Oct/23/embeddings/ 演讲视频链接&#xff1a; https://youtu.be/ArnMdc-ICCM Embedding 是一个非常巧妙的技术&#xff0c;但常常和一堆令人生畏的术…

国内首现AIGC环幕巨屏作品《大闹天宫》人工智能已经不知不觉的出现在我们身边了!

前言 春节期间在佛山紫薇星空光影艺术馆&#xff0c;由元响空间影音打造的AIGC作品《大闹天宫》迎来了第一批线下体验者&#xff0c;揭开一场深度融合了AIGC创作和空间影音技术的视听盛宴。 没想到全网火爆的AIGC&#xff0c;竟然已经真真切切的出现在了我们身边。春节期间在…

YOLOv10训练自己的数据集(图像目标检测)

目录 1、下载代码 2、环境配置 3、准备数据集 4、yolov10训练 可能会出现报错&#xff1a; 1、下载代码 源码地址&#xff1a;https://github.com/THU-MIG/yolov10 2、环境配置 打开源代码&#xff0c;在Terminal中&#xff0c;使用conda 创建虚拟环境配置 命令如下&a…

【数据结构】--栈

&#x1f44c;个人主页: 起名字真南 &#x1f923;个人专栏:【数据结构初阶】 【C语言】 目录 1 栈1.1 栈的概念和结构1.2 栈的实现1.2.1 头文件1.2.2 初始化1.2.3 销毁1.2.4 打印所有元素1.2.5 入栈1.2.6 出栈1.2.7 获取栈顶数据1.2.8 判空1.2.9 获取元素个数 1 栈 1.1 栈的概…

apk右键一键签名方法

使用说明 1 修改reg文件最后一行&#xff0c;修改为自己的电脑路径 2 修改bat文件apksigner_path路径为自己的SDK路径&#xff0c;将签名文件命名为platform.keystore放在该文件夹内 3 运行reg文件添加注册表后&#xff0c;要签名的apk右键选择“cux”系统签名即可 一键cux系…

ABAP开发:动态Open SQL编程案例介绍

动态Open SQL是Open SQL的扩展。它不是要求整个SQL语句都是动态指定的。通过熟悉的静态ABAP编码表达静态已知的部分&#xff0c;动态元素的部分通过动态标记指定。动态片段不明确包含在ABAP源代码中&#xff0c;而是源代码包含一个ABAP变量&#xff0c;用括号括起来作为占位符。…

【网络架构】lvs集群

目录 一、集群与分布式 1.1 集群介绍 1.2 分布式系统 1.3 集群设计原则 二、LVS 2.1 lvs工作原理 2.2 lvs集群体系架构 ​编辑 2.3 lvs功能及组织架构 2.4 lvs集群类型中术语 三、LVS工作模式和命令 3.1 lvs集群的工作模式 3.1.1 lvs的nat模式 3.1.2 lvs的dr模式 …

python-docx 使用xml为docx不同的章节段落设置不同字体

本文目录 前言一、完整代码二、代码详细解析1、处理过程解释(1) 引入库并定义路径(2) 创建docx的备份文件(3) 定义命名空间(4) 打开并处理.docx文件(5) 分析和组织文档结构(6) 设置字体(7) 保存结果前言 本文主要解决的内容,就是为一个docx的不同章节段落设置不同的字体,因为…

2024年公司加密软件排行榜(企业加密软件推荐)

在信息时代&#xff0c;企业数据安全至关重要&#xff0c;防止数据泄露和未授权访问是首要任务之一。以下是2024年备受好评的企业加密软件排行榜&#xff1a; 固信加密软件https://www.gooxion.com/ 1.固信加密软件 固信加密软件是新一代企业级加密解决方案&#xff0c;采用先…

7月开始,考研数学0️⃣基础线代30天满分规划

线代零基础&#xff1f; 那千万不要去跟李永乐老师的线代课程&#xff0c;因为李永乐老师的线代课程比较进阶&#xff0c;适合有一定基础的同学去听&#xff0c;下面这两位才是零基础线代的神&#xff01; 一个是喻老&#xff0c;另外一个是汤家凤&#xff01; 这两个老师的…

stencil 组件

stencil 组件 装饰器生命周期应用加载事件 组件定义组件如何响应数据变化 组件使用如何传递 slot如何暴露组件内部的方法供外部使用&#xff1f;Element 装饰器 Host 组件样式函数组件 stencil 提供一些装饰器、生命周期钩子和渲染函数去编写一个组件。 装饰器 装饰器是一组用…

Web网页端IM产品RainbowChat-Web的v7.0版已发布

一、关于RainbowChat-Web RainbowChat-Web是一套Web网页端IM系统&#xff0c;是RainbowChat的姊妹系统&#xff08;RainbowChat是一套基于开源IM聊天框架 MobileIMSDK (Github地址) 的产品级移动端IM系统&#xff09;。 ► 详细介绍&#xff1a;http://www.52im.net/thread-2…

【Sklearn驯化-回归指标】一文搞懂机器学习中回归算法评估指标:mae、rmse等

【Sklearn驯化-回归指标】一文搞懂机器学习中回归算法评估指标&#xff1a;mae、rmse等 本次修炼方法请往下查看 &#x1f308; 欢迎莅临我的个人主页 &#x1f448;这里是我工作、学习、实践 IT领域、真诚分享 踩坑集合&#xff0c;智慧小天地&#xff01; &#x1f387; 免…

大学计算机

项目一 了解计算机 1.1 了解计算机的诞生及发展阶段 1.2 认识计算机的特点、应用和分类 1&#xff0e;计算机的特点 1. 计算机的特点 2.计算机的应用 3.计算机的分类 4.数量单位 1.3 了解计算机操作系统的概念、功能与种类 1.操作系统概念 2.操作系统的作用 1&#xff0e…

Linux 中变量的取用与设定

优质博文&#xff1a;IT-BLOG-CN Linux是一个多人多任务的环境&#xff0c;每个人登录系统都能取得一个bash shell&#xff0c;每个人都能够使用bash下达mail这个指令来接收自己的邮箱等等。问题是&#xff0c;bash如何得知你的邮箱是那个文件&#xff1f;这就需要『变量』的帮…

jmeter性能测试

一.jmeter基本使用 1.元件执行顺序 配置元件&#xff1b; 前置处理器&#xff1b; 定时器&#xff1b; sampler&#xff1b; 后置处理器&#xff1b;&#xff08;关联&#xff0c;正则表达式提取器&#xff09; 断言&#xff1b; 监听&#xff1b;&#xff08;不涉及顺序&…

Windows 电脑类别怎么区分?不同类别区分总结

电脑类别 Windows 电脑的类别有哪些&#xff1f;我们可以大致分为这三类&#xff1a;CopilotPC、AI PC、普通 PC。下面就来看看这些电脑类别的区别。 普通 PC 普通 PC 就是指那些标准的台式电脑或者笔记本电脑&#xff0c;它们是由中央处理器&#xff08;CPU&#xff09;以及…

【面试题】信息安全风险评估要做些什么

信息安全风险评估是识别、评估和管理信息系统中潜在风险的重要过程。它具有以下几个关键步骤&#xff1a; 1.资产识别&#xff1a; 确定需要保护的信息资产&#xff0c;如硬件、软件、数据、人员等。例如&#xff0c;企业的客户数据库、重要的业务文档等。 2.威胁评估&#…

手把手教你打造高精度STM32数字时钟,超详细步骤解析

STM32数字时钟项目详解 1. 项目概述 STM32数字时钟是一个集成了时间显示、闹钟功能、温湿度检测等多功能于一体的小型电子设备。它利用STM32的实时时钟(RTC)功能作为核心,配合LCD显示屏、按键输入、温湿度传感器等外设,实现了一个功能丰富的数字时钟系统。 2. 硬件组成 STM…

文献解读-基因编辑-第十二期|《CRISPR-detector:快速、准确地检测、可视化和注释基因组编辑事件引起的全基因组范围突变》

关键词&#xff1a;基因组变异检测&#xff1b;全基因组测序&#xff1b;基因编辑&#xff1b; 文献简介 标题&#xff08;英文&#xff09;&#xff1a;CRISPR-detector: fast and accurate detection, visualization, and annotation of genome-wide mutations induced by g…