下面是标定双目并进行双目标定的halcon代码,我使用的图片分辨率太高了,所以笔记本无法运行,使用台式机测试成功,但是图片需要拍得比较好才行。这里进行了三维重建,实验只需要生成视差图,可以去掉一部分代码,不然笔记本可能带不动,甚至报错。标定图片省略。这里三维重建部分的代码注释掉了,但是重建效果最后有展示。
当时的试验记录

1,复制图片以及重命名的时候一定要对比一下顺序是否正确,如果重命名的时候出现顺序错乱,会出现calibrate_cameras报错,
如果单目采集完在标定助手下面运行没问题这里的标定一般也不会出问题。
2,两个图片路径需要注意,程序这里都使用了绝对路径
3,图片数量需要注意,多了没事少了会报错,最好修改
4,使用别的方式保存图片比如halcon的时候要注意大小和格式,要按照原分辨率大小和比例以及bmp格式保存,保存完后查看属性检查一下
5,现在低分辨率相机像素6.9um,距离0.3m,焦距16mm,光圈使用最大2.8,计算出来景深13.5913mm左右,如果距离0.6m,计算出来景深54.45mm
6,如果选择相机像素2.4um,距离0.6m,光圈最大2.8,焦距16mm,计算出来景深18.9047mm左右,如果光圈最小22,景深148.5mm.
7,生成相机内参矩阵的时候,像素点大小2.4需要注意
8,threshold函数里面这个值需要对应修改,可以设置断点,再看Z的范围,如果不在范围内会最后得到空的值,后面运行会报通道不对的错(重建)
9,两幅图像的光照对结果影响比较大,所以如果光照差距比较大,会出现无法匹配的结果(重建)
10,基线(两只相机的间距)对测量距离有影响,正相关
11,不适用于特征不明显的目标,会出现匹配不上的情况
12,建议提前计算一下景深,一方面熟悉公式,一方面不至于拍摄出一些问题
13,HALCON保存图片如果是“保存所有”,需要在英文路径下进行,默认保存为png格式
14,保存图片的时候注意是什么格式
15,角度比较大并且距离比较近的时候,可能会出现标志点对不上焦的问题
16,相机参数官网:https://www.hikrobotics.com/cn/machinevision/productdetail?id=2116&pageNumber=1&pageSize=50
17,镜头参数官网:https://www.hikrobotics.com/cn/machinevision/productdetail?id=7444&pageNumber=1&pageSize=50
18,计算景深网址:http://www.ooidea.com/tools/depth.html

代码如下

*set_calib_data_calib_object (CalibDataID, 0, CalTabFile)
ImgPath := 'C:/pic_formal/'
* Read the first images to get their size
Index := 1
read_image (ImageL, ImgPath + 'l_image_' + Index$'02d')
read_image (ImageR, ImgPath + 'r_image_' + Index$'02d')
* Reopen the windows with an appropriate size
dev_close_window ()
dev_update_off ()
get_image_size (ImageL, WidthL, HeightL)
dev_open_window (0, 0, WidthL/10, HeightL/10, 'black', WindowHandle1)
dev_set_draw ('margin')
dev_set_color ('green')
set_display_font (WindowHandle1, 14, 'mono', 'true', 'false')
get_image_size (ImageR, WidthR, HeightR)
dev_open_window (0, WidthL/10+10, WidthL/10, HeightL/10, 'black', WindowHandle2)
dev_set_draw ('margin')
dev_set_color ('green')* Set the initial values for the internal camera parameters
gen_cam_par_area_scan_division (0.016, 0, 2.4e-6, 2.4e-6, WidthL / 2.0, HeightL / 2.0, WidthL, HeightL, StartCamParL)
StartCamParR := StartCamParL* Read the model calibration points.
*create_caltab(26, 30, 0.003, [12, 4, 4, 20, 20], [14, 4, 24, 4, 24], 'light_on_dark', 'D:/教学/课程/机器人视觉技术/材料/caltab200.descr', 'D:/caltab200.ps')
CalTabFile := 'C:/Users/管理员/Desktop/multicam_rebuild/6mm.cpd'create_calib_data ('calibration_object', 2, 1, CalibDataID)
* Set the camera type used
set_calib_data_cam_param (CalibDataID, 0, [], StartCamParL)
set_calib_data_cam_param (CalibDataID, 1, [], StartCamParR)
* Set the calibration object
set_calib_data_calib_object (CalibDataID, 0, CalTabFile)
* Start the loop over the calibration images
* Set the optimization method to be used
set_calib_data (CalibDataID, 'model', 'general', 'optimization_method', 'nonlinear')* Start the loop over the calibration images
for I := 1 to 7 by 1* Read and display the calibration imagesread_image (ImageL, ImgPath + 'l_image_' + I$'02d')read_image (ImageR, ImgPath + 'r_image_' + I$'02d')dev_set_window (WindowHandle1)dev_display (ImageL)dev_set_window (WindowHandle2)dev_display (ImageR)* Find the calibration plate and store observations* in the calibration data modelfind_calib_object (ImageL, CalibDataID, 0, 0, I, [], [])find_calib_object (ImageR, CalibDataID, 1, 0, I, [], [])* Visualize the extracted calibration marks and the* coordinate system defined by the estimated pose.visualize_observation_results (ImageL, CalibDataID, 0, I, WindowHandle1)    visualize_observation_results (ImageR, CalibDataID, 1, I, WindowHandle2)wait_seconds (.2)
endfor
* Perform the actual calibration
calibrate_cameras (CalibDataID, Errors)
* Get the calibrated camera parameters
get_calib_data (CalibDataID, 'camera', 0, 'params', CamParamL)
get_calib_data (CalibDataID, 'camera', 1, 'params', CamParamR)
* Since the left camera is the reference camera for the
* calib data model, the pose of the right camera is its
* pose relative to the left camera
get_calib_data (CalibDataID, 'camera', 1, 'pose', cLPcR)
* Store the results into files. Here, you can either store the
* individual results
write_cam_par (CamParamL, 'cam_left-125.dat')
write_cam_par (CamParamR, 'cam_right-125.dat')
write_pose (cLPcR, 'pos_right2left.dat')
* or you store the complete camera setup model and thus enable
* the later access to all contained parameters
get_calib_data (CalibDataID, 'model', 'general', 'camera_setup_model', CameraSetupModelID)
write_camera_setup_model (CameraSetupModelID, 'stereo_camera_setup.csm')
* Generate the rectification maps
gen_binocular_rectification_map (MapL, MapR, CamParamL, CamParamR, cLPcR, 1, 'geometric', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)
* Read in a stereo image pair, acquired with the stereo camera system,
* which has been calibrated, just now.
read_image (ImageL, ImgPath + 'l_2')
read_image (ImageR, ImgPath + 'r_2')
*rgb1_to_gray(ImageL,ImageL)
*rgb1_to_gray(ImageR,ImageR)* Rectify the stereo images and display them
map_image (ImageL, MapL, ImageRectifiedL)
map_image (ImageR, MapR, ImageRectifiedR)
* Check the epipolar constraint on the rectified images,
* (the differences of the features' row coordinates should be small)
* and visualize the result (including some corresponding epipolar lines)
dev_close_window ()
dev_close_window ()*get_image_size (ImageRectifiedL, WidthL, HeightL)
*上面这个因为把图像斜着摆放会放大窗口尺寸所以还是保持原状
dev_open_window (0, 0, WidthL/10, HeightL/10, 'white', WindowHandle1)
set_display_font (WindowHandle1, 11, 'mono', 'true', 'false')
dev_display (ImageRectifiedL)
disp_message (WindowHandle1, 'Left rectified image', 'window', 10, 10, 'black', 'true')
*
* Display the right recitified image
dev_open_window (0, WidthL/10 + 10, WidthL/10, HeightL/10, 'white', WindowHandle2)
set_display_font (WindowHandle2, 11, 'mono', 'true', 'false')
dev_display (ImageRectifiedR)
disp_message (WindowHandle2, 'Right rectified image', 'window', 10, 10, 'black', 'true')
disp_continue_message (WindowHandle2, 'black', 'true')
stop ()dev_open_window (HeightL/10+20, 0, WidthL/10, HeightL/10, 'white', WindowHandle3)
set_display_font (WindowHandle3, 11, 'mono', 'true', 'false')
disp_message(WindowHandle3, 'generating... ', 'window', 10, 10, 'black', 'true')
binocular_distance_mg (ImageRectifiedL, ImageRectifiedR, Distance_mg, Score, RectCamParL, RectCamParR, RectLPosRectR, 1, 10, 5, 0, 'false', 'default_parameters', 'accurate')
dev_display (Distance_mg)
disp_message(WindowHandle3, 'Distance Image by Distance_mg', 'window', 10, 10, 'black', 'true')
disp_continue_message(WindowHandle3, 'black', 'true')
stop()dev_open_window (HeightL/10+20, WidthL/10 + 10, WidthL/10, HeightL/10, 'white', WindowHandle4)
set_display_font (WindowHandle4, 11, 'mono', 'true', 'false')
disp_message(WindowHandle4, 'generating... ', 'window', 10, 10, 'black', 'true')
binocular_distance_ms (ImageRectifiedL, ImageRectifiedR, Distance_ms, Score, RectCamParL, RectCamParR, cLPcR, 20, 40, 30, 20, [], [])
dev_display (Distance_ms)
disp_message(WindowHandle4, 'Distance Image by Distance_ms', 'window', 10, 10, 'black', 'true')
disp_continue_message(WindowHandle4, 'black', 'true')
stop()binocular_disparity(ImageRectifiedL, ImageRectifiedR, DisparityImage, Score, 'ncc', 17, 17, 5, 10, 40, 1, 0.1, 'left_right_check', 'none')* 注意:下面是生成三维模型的代码
* Fill the gaps in the disparity image
*get_domain (DisparityImage, RegionInpainting)
*complement (RegionInpainting, RegionInpainting)
*full_domain (DisparityImage, DisparityImage)
*harmonic_interpolation (DisparityImage, RegionInpainting, DisparityImage, 0.001)
*
* Display the disparity imagedev_set_window (WindowHandle1)
dev_clear_window()
dev_display (DisparityImage)
disp_message (WindowHandle1, 'Disparity image', 'window', 10, 10, 'black', 'true')*disparity_to_distance (CamParamL, CamParamR, cLPcR, DisparityImage, Distance)
*
* Compute the 3D coordinates
* *******************************************
*
* Transform the disparity image into images X, Y and Z.
* The gray values in X, Y and Z represent the x, y, and z
* coordinates of the pixels (Row, Column).
*disparity_image_to_xyz (DisparityImage, X, Y, Z, RectCamParL, RectCamParR, RectLPosRectR)
*
* Visualize the 3D points in the 3D space
* *******************************************
*
* Scale Z (for better visualization)
*scale_image (Z, Z, 2, 0)
*
* Reduce impact of inaccuracies in visualization
*threshold (Z, Regions, 0.3, 0.9)
*reduce_domain (Z, Regions, ZThresholded)
*
* Add the gray values to the point cloud.
*xyz_attrib_to_object_model_3d (X, Y, Z, ImageRectifiedL, '&gray', ObjectModel3D)
*
* Visualize the result
*prepare_object_model_3d (ObjectModel3D, 'segmentation', 'true', 'max_area_holes', 100)
*create_pose (-0.025, -0.37, 1.7, 300, 12, 180, 'Rp+T', 'gba', 'point', Pose)
*visualize_object_model_3d (WindowHandle2, ObjectModel3D, [], Pose, 'color_attrib', '&gray', [], [], [], PoseOut)

视差图:

两组三维重建实验图片与结果
拍摄的图片:


三维重建的模型:

拍摄的图片:


三维重建的模型:

HALCON双目三维重建实验相关推荐

  1. HALCON双目重建

    在上面一篇HALCON双目标定 是双目标定的介绍,标定完之后就是利用两个相机的内参和外参关系来进行双目重建,下面就是官方的一个重建PCB板的示例 下面是运行结果 * This example desc ...

  2. Android双目三维重建:Android双目摄像头实现双目测距

    Android双目三维重建:Android双目摄像头实现双目测距 目录 Android双目三维重建:Android双目摄像头实现双目测距 1.开发版本 2.Android双目摄像头 3.双目相机标定 ...

  3. 【Halcon】Halcon双目标定

    Halcon双目标定 * 设置图片路径 ImgPath := 'E:/2222/' * 读取第一幅图像,并获取图像尺寸 Index := 1 read_image (ImageL, ImgPath + ...

  4. 双目三维重建系统(双目标定+立体校正+双目测距+点云显示)Python

    双目三维重建系统(双目标定+立体校正+双目测距+点云显示)Python 目录 双目三维重建系统(双目标定+立体校正+双目测距+点云显示)Python 1.项目结构 2. Environment 3.双 ...

  5. 示例程序:关于双目视觉,标定,立体匹配(视差算法),点云,双目三维重建的原理以及代码

    Evision双目视觉 关于双目视觉的一些总结 说明 前言 相机模型 标定 视差算法:立体匹配 测量,三维重建 示例程序 参考文献 关于双目视觉的一些总结 说明 如果读者对于本文或者Evision程序 ...

  6. python双目三维重建_OpenCV+OpenGL 双目立体视觉三维重建

    0.绪论 这篇文章主要为了研究双目立体视觉的最终目标--三维重建,系统的介绍了三维重建的整体步骤.双目立体视觉的整体流程包括:图像获取,摄像机标定,特征提取(稠密匹配中这一步可以省略),立体匹配,三维 ...

  7. HALCON双目标定

    下面是HALCON示例中的双目标定的一个例子 * Application program to demonstrate the calibration of * a binocular stereo ...

  8. 双目三维重建_【光电视界】简单介绍双目视觉三维重构

    今日光电        有人说,20世纪是电的世纪,21世纪是光的世纪:知光解电,再小的个体都可以被赋能.欢迎来到今日光电! ----与智者为伍 为创新赋能---- 1.三维重构 1.1.三维重构到底 ...

  9. 双目三维重建_系列篇|结构光三维重建基本原理

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 结构光三维重建系统是由一个相机和一个投影仪组成,关于结构光三维重建系统的理论有很多,其中有一个简单的模 ...

最新文章

  1. 大厂项目是如何死掉的?太过真实!
  2. 调整数组顺序使奇数位于偶数前面【不保持相对位置】
  3. POJ 1523 SPF 割点与桥的推断算法-Tarjan
  4. [转]在ASP.NET中如何用C#.NET实现基于表单的验证(二)
  5. C/C++ 为什么#ifndef 头文件 要用大写加下划线?(这就是一种约定俗成的规范)
  6. 正则表达式的20个小应用
  7. flask jinja2 如何遍历新闻列表
  8. Python编程从入门到实践~文件写入
  9. Python计算有向图中所有节点出度和入度
  10. gradle问题 cordova
  11. python函数参数的引用传递_Python初学者笔记(八):函数参数的值传递和引用传递...
  12. 2006 年100 款最佳安全工具谱
  13. 整合DZ .net论坛与.net整合。
  14. 503 service unavailable php,503service unavailable错误提示解决方法
  15. 【Verilog设计—数字传输系统】ASK调制与FSK调制
  16. 如何提高团队的工作效率
  17. OpenCV每日函数 图像过滤模块 (14) medianBlur中值滤波函数
  18. matlab app designer学习笔记1——简易计算器
  19. matlab批量下载网页文件
  20. Win10最详细优化设置告别卡顿

热门文章

  1. [翻译]AKKA笔记 - CHILD ACTORS与ACTORPATH -6
  2. 转载:Objective-C中的 instancetype 和 id 关键字
  3. [LeetCode]3.Longest Substring Without Repeating Characters
  4. OpenStack Swift源码安装
  5. 查看系统信息命令:uname
  6. mysql练习题——数据分析/大数据岗面试
  7. Grafana中整个Dashboard报错问题解决
  8. springboot 防重复 提交
  9. 初识java反射机制
  10. 第7章 jQuery中的事件与动画