《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. Requirements Gathering

    Requirements gathering is an essential part of any project and project management. Understanding ful ...

  2. android studio配置AndroidAnnotations

    现在很多人都使用Android studio开发工具代替eclipse了,当然的 在eclipse使用的好的一些开发框架也会对应的在android studio上面使用. 参考文档:http://bl ...

  3. LeetCode Single Number III

    原题链接在这里:https://leetcode.com/problems/single-number-iii/ 题目: Given an array of numbers nums, in whic ...

  4. Change Tracking of SQLServer

    1.Enable the change tracking at the database level. ALTER DATABASE AdventureWorks2008 SET CHANGE_TRA ...

  5. JQuery: 基本知识了解

    一.介绍:jQuery 是一个 JavaScript函数库.它极大地简化了 JavaScript 编程.jQuery 库可以通过一行简单的标记被添加到网页中.jQuery 是一个轻量级的"写 ...

  6. Spring中的工厂模式和单例模式

    Spring预备知识(适合中小型项目) 作用:集成和管理其他框架 工厂模式: A  a  = new A( ); 将类所要创建的对象写入工厂,统一进行管理 package com.spring; pu ...

  7. 感知开源的力量-APICloud Studio开源技术分享会

    2014.9.15 中国领先的“云端一体”移动应用云服务提供商APICloud正式发布2015.9.15,APICloud上线一周年,迎来第一个生日这一天,APICloud 举办APICloud St ...

  8. idea 的问题

    IDEA的maven项目中,默认源代码目录下的xml等资源文件并不会在编译的时候一块打包进classes文件夹,而是直接舍弃掉. 如果使用的是Eclipse,Eclipse的src目录下的xml等资源 ...

  9. MVC项目实践,在三层架构下实现SportsStore-08,部署到IIS服务器

    SportsStore是<精通ASP.NET MVC3框架(第三版)>中演示的MVC项目,在该项目中涵盖了MVC的众多方面,包括:使用DI容器.URL优化.导航.分页.购物车.订单.产品管 ...

  10. Android -- Looper.prepare()和Looper.loop() —深入版

    Android中的Looper类,是用来封装消息循环和消息队列的一个类,用于在android线程中进行消息处理.handler其实可以看做是一个工具类,用来向消息队列中插入消息的. (1) Loope ...