*用立体方法分割板子组件的示例程序
*Application program to illustrate the segmentation
* of board _components.hdev  with stereo methods
* 用有两个相机的立体装备
* We have a stereo setup of two cameras.
*两个相机都是经过30mm的标定板标定过的
* Both cameras will be calibrated by a couple of images
* of a 30mm calibration plate.
*以此来矫正和分割不同板子的图像
*The images of different  boards will be rectified and the components segmented.
*这种方法只对有一定纹理的物体有效
* Note that this approach only works for sufficiently textured objects.
*如果只有很少的或者重复的纹理图像,对应的两个图像中点会匹配失败,测量结果也是错的
* If little or repetitive texture is present, the matching
* of corresponding points in both images will fail and
* therefore the measurement will be false.
*只有很少的或者重复的纹理图像的时候,可以加一个动态照明,给现场加一个随机的照明,生成一种纹理
* In such cases, it is a good practice to use active
* illumination, e.g., projecting a random light pattern
* onto the scene, to add texture information.
* 在有些应用场合中,有限的场景深度会成为一个问题,特别是场景特别小或者用远心镜头的时候
* In some applications, a limited depth of field can be
* a problem, especially when using a small field of view
* or telecentric lenses.
*在这种情况下,可以用倾斜镜头,充分利用Scheimpflug原理
* In such cases, please consider using tilt lenses
* to take advantage of the Scheimpflug principle.
*
* -------------------------------------------------------
* (1)           STEREO CALIBRATION
* 关闭更新
dev_update_off ()
*设置图像路径
* Set the image path (make sure, that you have set HALCONIMAGES to the HALCON image directory)
ImgPath := 'stereo/board/'
*标定板描述文件
CalDescrFile := 'caltab_30mm.descr'
* Read the first images to get their size
*获取图像
read_image (ImageL, ImgPath + 'calib_l_01')
read_image (ImageR, ImgPath + 'calib_r_01')
* Reopen the windows with an appropriate size
*官拜窗口
dev_close_window ()
*获取图像大小
get_image_size (ImageL, WidthL, HeightL)
*打开固定尺寸的新窗体
dev_open_window (0, 0, WidthL, HeightL, 'black', WindowHandle1)
*设置显示填充形式,两种,margin表示边界,fill表示全部填充
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 + 12, WidthL, HeightL, 'black', WindowHandle2)
*设置显示填充形式,两种,margin表示边界,fill表示全部填充
dev_set_draw ('margin')
*设置显示颜色为绿色
dev_set_color ('green')
*设置显示字体
set_display_font (WindowHandle2, 14, 'mono', 'true', 'false')
* Calibrate the stereo setup
* (determine the internal and external camera parameters).
*
* Set the initial values for the internal camera parameters
*生成面扫描相机初始参数
gen_cam_par_area_scan_division (0.0125, 0, 1.48e-5, 1.48e-5, WidthL / 2.0, HeightL / 2.0, WidthL, HeightL, StartCamPar)
*创建标定数据句柄
create_calib_data ('calibration_object', 2, 1, CalibDataID)
*设置标定相机出事参数
set_calib_data_cam_param (CalibDataID, 'all', [], StartCamPar)
*设置标定板文件
set_calib_data_calib_object (CalibDataID, 0, CalDescrFile)
*
* Read all used calibration images
*读取左右两幅图像
read_image (ImagesL, ImgPath + 'calib_l_' + [1:15]$'02d')
read_image (ImagesR, ImgPath + 'calib_r_' + [1:15]$'02d')
* Calibrate the setup
*矫正立体双目视觉
calibrate_stereo_setup (ImagesL, ImagesR, WindowHandle1, WindowHandle2, CalibDataID, StartCamPar, CalDescrFile, CamParamL, CamParamR, cLPcR, Errors)
* Generate the rectification maps
*生成双目矫正分布图
gen_binocular_rectification_map (MapL, MapR, CamParamL, CamParamR, cLPcR, 1, 'geometric', 'bilinear', RectCamParL, RectCamParR, CamPoseRectL, CamPoseRectR, RectLPosRectR)
*
* Check the calibration result
* by checking the epipolar constraint on the rectified images:
* The differences in row coordinates of all
* calibration point correspondences should be minimal
*检视矫正结果
map_image (ImagesL, MapL, ImagesRectL)
map_image (ImagesR, MapR, ImagesRectR)
*检测极线约束差异
check_epipolar_constraint (ImagesRectL, ImagesRectR, RectCamParL, RectCamParR, WindowHandle1, WindowHandle2, CalDescrFile, EpipolarError)
if (EpipolarError[1] > 0.3)
    * The calibration of the stereo rig was not performed thoroughly
    *右下角显示 'Press Run (F5) to continue' 这个信息
    disp_continue_message (WindowHandle2, 'black', 'true')
    stop ()
endif
*右下角显示 'Press Run (F5) to continue' 这个信息
disp_continue_message (WindowHandle2, 'black', 'true')
stop ()
*清除矫正数据
clear_calib_data (CalibDataID)
* --------------------------------------------------------
* (2)   STEREO PROCESSING
*
* Parameters from above if calibration was not performed:
* gen_cam_par_area_scan_division (0.0131205, -665.85466, 1.4803422e-005, 1.48e-005, 155.90117, 126.703971, 320, 240, CamParamL)
* gen_cam_par_area_scan_division (0.0131712, -728.9579, 1.4799849e-005, 1.48e-005, 163.265701, 119.310684, 320, 240, CamParamR)
* cLPcR := [0.15350044,-0.003732778,0.04481715,0.1736607,319.8612,359.8945,0]
*定义双目视觉相对的差异参数和双目距离
* Define parameter values for binocular_disparity and binocular_distance, respectively.
*掩码宽
MaskWidth := 17
*掩码高
MaskHeight := 17
*纹理阈值
TextureThresh := 5
*最小差异
MinDisparity := 10
*最大差异
MaxDisparity := 40
*Level
NumLevels := 1
ScoreThresh := 0.1
* Get stereo image pair
**聚焦到窗体1
dev_set_window (WindowHandle1)
*读取图像
read_image (ImageL, ImgPath + 'board_l_01')
*增强对比度
emphasize (ImageL, ImageL, 7, 7, 1)
*映射图像
map_image (ImageL, MapL, ImageRectifiedL)
*显示图像
dev_display (ImageRectifiedL)
**聚焦到窗体2
dev_set_window (WindowHandle2)
*读取图像
read_image (ImageR, ImgPath + 'board_r_01')
*增强图像
emphasize (ImageR, ImageR, 7, 7, 1)
*映射图像
map_image (ImageR, MapR, ImageRectifiedR)
*显示图像
dev_display (ImageRectifiedR)
*显示信息
disp_message (WindowHandle1, 'Rectified left image', 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle2, 'Rectified right image', 'window', 12, 12, 'black', 'true')
  *右下角显示 'Press Run (F5) to continue' 这个信息
disp_continue_message (WindowHandle2, 'black', 'true')
stop ()
*当以图像距离
* Determine the distance image.
binocular_distance (ImageRectifiedL, ImageRectifiedR, DistanceImage, ScoreImageDistance, RectCamParL, RectCamParR, RectLPosRectR, 'ncc', MaskWidth, MaskHeight, TextureThresh, MinDisparity, MaxDisparity, NumLevels, ScoreThresh, 'left_right_check', 'interpolation')
* Display the distance image
dev_set_window (WindowHandle1)
dev_clear_window ()
dev_display (DistanceImage)
* Correct the distance image for the tilt of the stereo camera system.
*   (Attention: the distance values are not measured
*    in the rectified coordinate system anymore!)
* Define a region, which indicates three areas on the reference plane
*生成一组圆
gen_circle (Circle, [15,208,95], [58,32,211], [8,8,8])
*联合区域
union1 (Circle, RegionDefiningReferencePlane)
*倾斜修正
tilt_correction (DistanceImage, RegionDefiningReferencePlane, DistanceImageCorrected)
**聚焦到窗体2
dev_set_window (WindowHandle2)
*清除窗体
dev_clear_window ()
*显示纠正图像
dev_display (DistanceImageCorrected)
*显示信息
disp_message (WindowHandle1, 'Distance image', 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle2, 'After tilt correction', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle2, 'black', 'true')
stop ()
MinHeight := -0.0005
MaxHeight := 0.05
* Transform the distances into heights above the reference plane.
*计算离参考平面的距离范围
height_range_above_reference_plane (DistanceImageCorrected, HeightAboveReferencePlaneReduced, MinHeight, MaxHeight)
*显示高度范围(本地函数)
visualize_height_ranges (ImageRectifiedL, HeightAboveReferencePlaneReduced, WindowHandle2, 0.0004, 0.0015, 0.0015, 0.0025, 0.0025, 0.004)
**聚焦到窗体1
dev_set_window (WindowHandle1)
*清除窗体
dev_clear_window ()
*显示数据
dev_display (HeightAboveReferencePlaneReduced)
*显示信息
disp_message (WindowHandle2, 'Segmented components', 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle1, 'Height above reference plane', 'window', 12, 12, 'black', 'true')

Blob分析之board _components.hdev的更多相关文章

  1. Blob分析之board.hdev

    * board.hdev: Detection of missing solder* 获取当前系统参数get_system ('clip_region', Information)*设置当前系统参数s ...

  2. 常用机器视觉工具----图像分析工具(blob分析)

    http://blog.sina.com.cn/s/blog_67cc4eb70100ivnt.html Blob分析:Blob分析目的在于对图像中的2-D形状进行检测和分析,得到诸如目标位置.形状. ...

  3. opencv 在工业中的应用:blob分析

    在工业中经常要检测一副图像中物体的数量,位置,大小,面积等信息,这就要用到BLOB分析,我用OPENCV做了个BLOB分析的DEMO. (1)打开一幅图像 (2)进行参数设置,设定二值化阙值,并选择是 ...

  4. Blob分析--粘连颗粒检测 基于距离变换的分水岭区域分割 盆地与原连通域求交集

    文章转自微信公众号:机器视觉那些事 *******************************************************************公众号:机器视觉那些事儿*** ...

  5. Halcon 笔记2 Blob分析

    1. 数组操作 2. 可视化-更新窗口 (1)单步模式-总是:则可以自动显示图像: (2)单步模式-从不:需要调用显示函数才能显示图像. (3)单步模式-清空显示:将原图清除,再显示新图 3. 图像处 ...

  6. Halcon blob分析基本处理步骤

    Halcon,blob分析 应用场景,二值化后的灰度图像对比度清晰 基本处理流程 1 读取图片 read_image(变量名,'路径') //halcon字符串使用单引号'' 2 预处理 2.1 RO ...

  7. Blob分析之bottle.hdev

    * 分割读取啤酒瓶子上的数字* bottle.hdev: Segment and read numbers on a beer bottle* 第0步* Step 0: Preparations*定义 ...

  8. Blob分析之ball_seq.hdev

    * ball_seq.hdev: Inspection of Ball Bonding * 关闭更新dev_update_off ()*图像集合ImageNames := 'die/' + ['die ...

  9. Blob分析之 ball.hdev

    * ball.hdev: Inspection of Ball Bonding * 关闭窗体更新 dev_update_window ('off')*关闭窗体dev_close_window ()*打 ...

随机推荐

  1. Mybatis 报错

    Mybatis 报错 builder.BuilderException: Error parsing SQL Mapper Configuration Caused by: org.apache.ib ...

  2. 平常我们是如何区分css中class和id之间有什么区别的?

    我们平常在用DIV+CSS制作html网页页面时,常会用到class 和id来选择调用CSS样式属性.对学习CSS的新手来说class和id可能比较模糊,同时不知道什么时候该用class,什么时候又用 ...

  3. 实现 React Hooks

    实现 React Hooks UI 开发有两个问题: 展示复用 逻辑复用 展示复用目前基本使用组件化来解决,逻辑复用一直以来都没有特别好的解决方案.React 从一开始的 mixin ,到 高阶组件 ...

  4. SSTI-服务端模板注入

    SSTI-服务端模板注入漏洞 原理: 服务端模板注入是由于服务端接收了用户的输入,将其作为 Web 应用模板内容的一部分,在进行目标编译渲染的过程中,执行了用户插入的恶意内容,因而导致了敏感信息泄露. ...

  5. mac篇---mac安装jupyter

    1.Jupyter搭建 pip install --user jupyter 如果是在python3中,则用如下命令: pip3 install --user jupyter 如下图所示: 2. Ju ...

  6. HBuilder生成证书

    一.安装jdk https://www.oracle.com/java/technologies/javase-downloads.html 二.打开CMD命令到JDK安装目录bin文件夹下 执行命令 ...

  7. 小程序checkbox-group只获取到一个值

    wx:for循环不能写在checkbox-group标签上 wx:for循环不能写在checkbox-group标签上 wx:for循环不能写在checkbox-group标签上 wx:for循环不能 ...

  8. day10 基本数据类型(下)

    目录 一.集合 1.作用 2.定义 3.类型转换 4.内置方法 4.1交集:两者共有的 4.2合集:两者融合去重 4.3差集:某个集合单独有的 4.4对称差集:两个集合各自单独有的组成的集合 4.5父 ...

  9. Linux超强截图工具flameshot

    Pop!_OS自带的截屏快捷键如下 但讲道理这个是真的不好用 所以我们借助第三方的截图工具,这里推荐flameshot(火焰截图) 在终端键入以下命令即可安装 sudo apt update sudo ...

  10. flutter gradle版本不一致

    我们有时候拿到别人的项目时,直接运行可能会报错,因为gradle版本不一样,此时需要修改这两个地方: 要把这两个版本改成你本地的版本就可以了,怎么看呢,一般你自己创建过flutter项目,里面也有这个 ...