《zw版·Halcon-delphi系列原创教程》 2d照片-3d逆向建模脚本
《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逆向建模脚本的更多相关文章
- 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别
[<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...
- 【《zw版·Halcon与delphi系列原创教程》Halcon图层与常用绘图函数
[<zw版·Halcon与delphi系列原创教程>Halcon图层与常用绘图函数 Halcon的绘图函数,与传统编程vb.c.delphi语言完全不同, 传统编程语言,甚至cad ...
- 《zw版Halcon与delphi系列原创教程》发布说明
<zw版Halcon与delphi系列原创教程>发布说明 zw转载的<台湾nvp系列halcon-delphi教程>,虽然很多,不过基本上都是从cnc.数控角度的demo.. ...
- 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版
<zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...
- 《zw版·delphi与Halcon系列原创教程》THOperatorSetX版hello,zw
<zw版·delphi与Halcon系列原创教程>THOperatorSetX版hello,zw 下面介绍v3版的hello,zw. Halcon两大核心控件,THImagex.THOpe ...
- 《zw版·delphi与halcon系列原创教程》zw版_THImagex控件函数列表
<zw版·delphi与halcon系列原创教程>zw版_THImagex控件函数列表 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就要7w多行,但核心控件就是两 ...
- 《zw版·ddelphi与halcon系列原创教程》Halcon的短板与delphi
[<zw版·delphi与Halcon系列原创教程>Halcon的短板与delphi 看过<delphi与Halcon系列>blog的网友都知道,笔者对Halcon一直是非常推 ...
- 《zw版·delphi与halcon系列原创教程》hello,zw
<zw版·delphi与halcon系列原创教程>hello,zw 按惯例,第一个程序是‘hello’ 毕竟,Halcon是专业的图像库,所以我们就不用纯文本版的,来一个专业版.Halco ...
- 《zw版·Halcon-delphi系列原创教程》 zw版-Halcon常用函数Top100中文速查手册
<zw版·Halcon-delphi系列原创教程> zw版-Halcon常用函数Top100中文速查手册 Halcon函数库非常庞大,v11版有1900多个算子(函数). 这个Top版,对 ...
随机推荐
- [LeetCode]题解(python):056-Merge Intervals
题目来源 https://leetcode.com/problems/merge-intervals/ Given a collection of intervals, merge all overl ...
- OO之美2
面向对象并没有想象中那么神秘,以生活的现实眼光来看更是如此.把面向对象深度浓缩起来,可以概括为: ⑴目标:重用,扩展,兼容 ⑵核心:低耦合,高内聚 ⑶手段:封装变化 ⑷思想:面向接口编程,面向抽象编程 ...
- Swift-05-SizeOf&&SizeOfValue
在C中定义的运算符,可以作用于类型或者某个实际的变量,并返回其在内存中的尺寸size_t. 在Cocoa中,我们一般用来将数组生成NSData的时候传入数据长度.因为在OC里面,sizeOf这个C运算 ...
- 5分钟弄懂Docker!
http://www.csdn.net/article/2014-07-02/2820497-what%27s-docker 关注点:1.DOCKER和VM的架构区别 2.Docker 的容器利用了 ...
- Objective-C的对象模型
Objective-C是一门面向对象,并且在C的基础上加入了Smalltalk式的消息机制而形成的编程语言,它主要被苹果公司用于开发Mac OS X和iOS操作系统.既然Objective-C是面向对 ...
- POJ1043问题描述
Description The FBI is conducting a surveillance of a known criminal hideout which serves as a commu ...
- Virtio:针对 Linux 的 I/O 虚拟化框架
Virtio:针对 Linux 的 I/O 虚拟化框架 --http://www.ibm.com/developerworks/cn/linux/l-virtio/#ibm-pcon 使用 KVM 和 ...
- UserMapper.selectByPrimaryKey-Inline 报错的解决办法
报错原因,及解决办法: 实体类id属性上少加了@Id 然后mybatis不知道哪个是主键了 我写了个demo public interface UserMapper extends Mapper< ...
- startssl 申请证书,并在Nginx, apache, Tomcat上使用
tomcat: http://blog.csdn.net/buyaore_wo/article/details/5771470 apache: http://blog.mowd.tw/index.ph ...
- 给表追加主键-----报错ORA-02437: 无法验证 (DENGCHAO.TEST) - 违反主键
由于 这次 项目 做了 数据库 迁移(从 mysql 转到oracle 用的是navicat) 的工具 所以导致很多主键都丢失了 导致数据库很多 数据的id重复 导致系统修改一条数据的时候 出现 ...