《zw版·Halcon-delphi系列原创教程》

2d照片-3d逆向建模脚本

3D逆向建模,是逆向工程的核心要素。
       3D逆向建模,除了目前通用的3D点云模式,通过2D图像实现快速3D建模,也是目前的重要手段。
       2D图像的3D逆向建模,目前常用的有两种模式,一个是左右视距(或多角度取景)图片叠加处理,google的卫星地图3D化,就是这个模式。
       另外一种,就是本文要介绍的3D定标模式,就是在现场先拍摄一张标准3D定标图片,获取定位参数,再采集目标图像。

下面Halcon自带demo脚本:handeye_stationarycam_calibration.hdev
脚本挺长的,有129行,而且只提供了单点的3D参数,可见3D建模还是蛮复杂的

真正建模,需要采集的10万-100万个数据点,不过这些只是简单的循环扫描scan采样,

最核心的代码,还是上面的100多行

 *
* Prior to executing this example, the example
* 'handeye_stationarycam_calibration.hdev' has to be executed.
* Given the transformations computed by the hand-eye calibration
* this example computes the pose of the robot tool in robot base
* coordinates for grasping the nut with the gripper.
dev_update_off ()
dev_close_window ()
* Directories with calibration images and data files
ImageNameStart := '3d_machine_vision/handeye/stationarycam_'
DataNameStart := 'handeye/stationarycam_'
read_image (Image, ImageNameStart + 'nut12_square')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, , , Width, Height, WindowHandle)
dev_set_draw ('margin')
dev_set_line_width ()
set_display_font (WindowHandle, , 'mono', 'true', 'false')
dev_display (Image)
disp_message (WindowHandle, 'Object to grasp', 'window', , , 'black', 'true')
* Read internal camera parameters and calibrated poses
read_cam_par (DataNameStart + 'final_campar.dat', CamParam)
read_pose (DataNameStart + 'final_pose_cam_base.dat', BaseInCamPose)
pose_to_hom_mat3d (BaseInCamPose, cam_H_base)
read_pose (DataNameStart + 'final_pose_tool_calplate.dat', CalplateInToolPose)
pose_to_hom_mat3d (CalplateInToolPose, tool_H_calplate)
* Read pose of gripper in tool coordinates
read_pose (DataNameStart + 'pose_tool_gripper.dat', GripperInToolPose)
pose_to_hom_mat3d (GripperInToolPose, tool_H_gripper)
stop ()
* Define reference coordinate system and display it
CalplateFile := 'caltab_30mm.descr'
define_reference_coord_system (ImageNameStart + 'calib3cm_00', CamParam, CalplateFile, WindowHandle, PoseRef)
pose_to_hom_mat3d (PoseRef, cam_H_ref)
Message := 'Defining a reference coordinate system'
Message[] := 'based on a calibration image'
disp_message (WindowHandle, Message, 'window', , , 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_display (Image)
disp_3d_coord_system (WindowHandle, CamParam, PoseRef, 0.01)
* Find parallel sides of the nut
dev_set_color ('yellow')
threshold (Image, BrightRegion, , )
connection (BrightRegion, BrightRegions)
select_shape (BrightRegions, Nut, 'area', 'and', , )
fill_up (Nut, NutFilled)
gen_contour_region_xld (NutFilled, NutContours, 'border')
segment_contours_xld (NutContours, LineSegments, 'lines', , , )
fit_line_contour_xld (LineSegments, 'tukey', -, , , , RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
gen_empty_obj (Lines)
for I := to |RowBegin| - by
gen_contour_polygon_xld (Contour, [RowBegin[I],RowEnd[I]], [ColBegin[I],ColEnd[I]])
concat_obj (Lines, Contour, Lines)
endfor
gen_polygons_xld (Lines, Polygon, 'ramer', )
gen_parallels_xld (Polygon, ParallelLines, , , rad(), 'true')
dev_display (ParallelLines)
* Accumulate corner points
get_parallels_xld (ParallelLines, Row1, Col1, Length1, Phi1, Row2, Col2, Length2, Phi2)
CornersRow := [Row1[],Row1[],Row2[],Row2[]]
CornersCol := [Col1[],Col1[],Col2[],Col2[]]
* Method : transform corners into reference coordinate system and determine grasp
image_points_to_world_plane (CamParam, PoseRef, CornersRow, CornersCol, 'm', CornersX_ref, CornersY_ref)
* Determine center and orientation of the grasp
CenterPointX_ref := sum(CornersX_ref) * 0.25
CenterPointY_ref := sum(CornersY_ref) * 0.25
GraspPointsX_ref := [(CornersX_ref[] + CornersX_ref[]) * 0.5,(CornersX_ref[] + CornersX_ref[]) * 0.5]
GraspPointsY_ref := [(CornersY_ref[] + CornersY_ref[]) * 0.5,(CornersY_ref[] + CornersY_ref[]) * 0.5]
GraspPhiZ_ref := atan((GraspPointsY_ref[] - GraspPointsY_ref[]) / (GraspPointsX_ref[] - GraspPointsX_ref[]))
* Display grasping points after projecting them into the image
affine_trans_point_3d (cam_H_ref, GraspPointsX_ref, GraspPointsY_ref, [,], GraspPointsX_cam, GraspPointsY_cam, GraspPointsZ_cam)
project_3d_point (GraspPointsX_cam, GraspPointsY_cam, GraspPointsZ_cam, CamParam, GraspPointsRow, GraspPointsCol)
display_grasping_points (GraspPointsRow, GraspPointsCol, WindowHandle)
disp_message (WindowHandle, 'Finding grasping points', 'window', -, -, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Transform it into a homogeneous transformation matrix
hom_mat3d_identity (HomMat3DIdentity)
hom_mat3d_rotate (HomMat3DIdentity, GraspPhiZ_ref, 'z', , , , HomMat3D_RZ_Phi)
hom_mat3d_translate (HomMat3D_RZ_Phi, CenterPointX_ref, CenterPointY_ref, , ref_H_grasp)
* Display coordinate system of the gripper
hom_mat3d_compose (cam_H_ref, ref_H_grasp, cam_H_grasp)
hom_mat3d_to_pose (cam_H_grasp, GripperInCamPose)
dev_set_colored ()
disp_3d_coord_system (WindowHandle, CamParam, GripperInCamPose, 0.01)
Message := 'Determining the gripper pose'
Message[] := 'via the reference coordinate system'
disp_message (WindowHandle, Message, 'window', , , 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Method : pose estimation using the four corner points of the nut
NX := [0.009,-0.009,-0.009,0.009]
NY := [0.009,0.009,-0.009,-0.009]
NZ := [,,,]
sort_corner_points (CornersRow, CornersCol, WindowHandle, NRow, NCol)
vector_to_pose (NX, NY, NZ, NRow, NCol, CamParam, 'iterative', 'error', PoseCamNut, Quality)
dev_set_colored ()
disp_3d_coord_system (WindowHandle, CamParam, GripperInCamPose, 0.01)
Message := 'Alternative: Determining the gripper pose'
Message[] := 'via pose estimation using the corners'
disp_message (WindowHandle, Message, 'window', , , 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* Determine corresponding robot position (pose of the tool in base coordinates)
* base_H_tool = base_H_cam * cam_H_ref * ref_H_grasp * gripper_H_tool
* where to position the tool to grasp the nut
hom_mat3d_invert (cam_H_base, base_H_cam)
hom_mat3d_compose (base_H_cam, cam_H_grasp, base_H_grasp)
hom_mat3d_invert (tool_H_gripper, gripper_H_tool)
hom_mat3d_compose (base_H_grasp, gripper_H_tool, base_H_tool)
hom_mat3d_to_pose (base_H_tool, PoseRobotGrasp)
* Convert pose type to the one used by the robot controller (ZYX) and display it
convert_pose_type (PoseRobotGrasp, 'Rp+T', 'abg', 'point', PoseRobotGrasp_ZYX)
* Alternatively, the PoseRobotGrasp can be computed using only poses instead of
* matrices.
pose_invert (BaseInCamPose, CamInBasePose)
pose_compose (CamInBasePose, GripperInCamPose, GripperInBasePose)
pose_invert (GripperInToolPose, ToolInGripper)
* The computed ToolInBasePose equals PoseRobotGrasp
pose_compose (GripperInBasePose, ToolInGripper, ToolInBasePose)
dev_display (Image)
disp_3d_coord_system (WindowHandle, CamParam, GripperInCamPose, 0.01)
disp_message (WindowHandle, 'Converting the pose into robot coordinates', 'window', -, -, 'black', 'true')
dev_inspect_ctrl (PoseRobotGrasp_ZYX)
* This pose should then be sent to the robot
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_close_inspect_ctrl (PoseRobotGrasp_ZYX)

【《zw版·Halcon-delphi系列原创教程》,网址,cnblogs.com/ziwang/】

《zw版·Halcon-delphi系列原创教程》 2d照片-3d逆向建模脚本的更多相关文章

  1. 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别

    [<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...

  2. 【《zw版·Halcon与delphi系列原创教程》Halcon图层与常用绘图函数

    [<zw版·Halcon与delphi系列原创教程>Halcon图层与常用绘图函数 Halcon的绘图函数,与传统编程vb.c.delphi语言完全不同,     传统编程语言,甚至cad ...

  3. 《zw版Halcon与delphi系列原创教程》发布说明

    <zw版Halcon与delphi系列原创教程>发布说明 zw转载的<台湾nvp系列halcon-delphi教程>,虽然很多,不过基本上都是从cnc.数控角度的demo..  ...

  4. 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版

    <zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...

  5. 《zw版·delphi与Halcon系列原创教程》THOperatorSetX版hello,zw

    <zw版·delphi与Halcon系列原创教程>THOperatorSetX版hello,zw 下面介绍v3版的hello,zw. Halcon两大核心控件,THImagex.THOpe ...

  6. 《zw版·delphi与halcon系列原创教程》zw版_THImagex控件函数列表

    <zw版·delphi与halcon系列原创教程>zw版_THImagex控件函数列表 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就要7w多行,但核心控件就是两 ...

  7. 《zw版·ddelphi与halcon系列原创教程》Halcon的短板与delphi

    [<zw版·delphi与Halcon系列原创教程>Halcon的短板与delphi 看过<delphi与Halcon系列>blog的网友都知道,笔者对Halcon一直是非常推 ...

  8. 《zw版·delphi与halcon系列原创教程》hello,zw

    <zw版·delphi与halcon系列原创教程>hello,zw 按惯例,第一个程序是‘hello’ 毕竟,Halcon是专业的图像库,所以我们就不用纯文本版的,来一个专业版.Halco ...

  9. 《zw版·Halcon-delphi系列原创教程》 zw版-Halcon常用函数Top100中文速查手册

    <zw版·Halcon-delphi系列原创教程> zw版-Halcon常用函数Top100中文速查手册 Halcon函数库非常庞大,v11版有1900多个算子(函数). 这个Top版,对 ...

随机推荐

  1. [LeetCode] Sudoku Solver(迭代)

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  2. ArcGIS Engine开发之旅09--几何对象和空间参考

    原文:ArcGIS Engine开发之旅09--几何对象和空间参考 1.Geometry  Geometry 是 GIS 中使用最为广泛的对象集之一,用户在创建.删除.编辑和进行地理分析的时候,就是处 ...

  3. Linux上使用SMART检测硬盘

    SMART(Self-Monitoring, Analysis, and Reporting Technology)是一种普及度比较高的磁盘分析检测工具,磁盘运行过程中,该工具搜集磁盘的状态参数,如型 ...

  4. Appium-001-测试开发环境搭建(Android - Win7)

    随着移动端 App 测试自动化的兴起,为更好的控制产品质量,越来越多的中大型公司开始了移动端的自动化测试.Appium 自动化测试技术也是我很早之前就想学习的一门技术,却一直没有比较空余的时间来学习( ...

  5. JMeter学习-003-JMeter与LoadRunner的异曲同工

    本节主要对 JMeter 与 LoadRunner 的优缺点进行概要的总结,若有不足之处,敬请指正,不胜感激! 同时,我也不得不承认,在对 JMeter 和 LoadRunner 进行比较时,我个人的 ...

  6. raspberry 烧写镜像到SD卡

    刚开始接触树莓派,需要烧写系统镜像到SD卡,网上找了些资料,记录于此. raspberry镜像下载: https://www.raspberrypi.org/downloads/ 烧写工具: wid3 ...

  7. [代码片段]YEAH!连通域标记和计数

    //标记的连通域存储在buff[]里 //返回值为连通域个数 int LinkBlob(unsigned char **imagedata,unsigned char buff[], int heig ...

  8. 如何让SQLPLUS实现带日期的时间戳

    from http://www.itpub.net/thread-1876506-4-1.html SQL> defineDEFINE _DATE           = "20-7月 ...

  9. TXT导入出现乱码

    错误#1 11:15 2012-12-19客户提供一txt文本文件,要求导入到数据库,选用dts导入工具,选择数据源步骤如下列预览时出现乱码解答#1 双击打开原始文件中文显示正常,将其另存为选择编码为 ...

  10. [HDF]hdf-4.2.6类库的使用

    HDF文件包括科学数据和VData部分.读取HDF格式的calipso数据,用GDAL可以方便的读取其中的子数据集,但是没有发现GDAL中提供读取Vdata的方法.所以只好考虑借助hdf-4.2.6类 ...