对应示例程序:
rim.hdev

目标:提取圆孔以及包含印记字符的区域

思路为:
      1.读取图像,窗口初始化
      2.先定位圆孔的位置和测量直径:
         a.分割提取出灰度较低的区域 再根据圆度和面积筛选出较小的圆孔
         b.之后 膨胀一次 腐蚀一次 求二者之间的差值图像进行目标区域的定位
         c.根据上述定位区域 截取ROI图像 再进行边缘检测 和椭圆拟合 得到 圆孔的直径等相关测量参数
      3.定位字符区域:
         a.将图像进行局部阈值分割,再根据面积,椭圆半径等参数的筛选,定位出字符区域
         b.上面提取的图像 有干扰 不太好区分 就把他合并成一个区域 先闭操作进行放大 再根据面积筛选出包含ROI的不规则区域
         b.将不规则区域进行凸包操作
         d.将与之前的阈值图 进行交集计算 抠出ROI
      总结:这个例程其实主要用到的就是Blob分析的手法。

图像:
                                                                       原图
                                                                    圆孔的定位和测量结果图
                                                                     包含干扰区域的字符图像


                                                                       闭操作结果图


                                                                       凸包图

结果图

代码:

* Set the display parameters and read the image
//初始化  设置窗口  读入图像
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 768, 576, 'black', WindowID)
set_display_font (WindowID, 16, 'mono', 'true', 'false')
read_image (Rim, 'rim')
dev_display (Rim)
disp_continue_message (WindowID, 'black', 'true')
stop ()//Blob分析:
//阈值分割提取出灰度较低的区域  再根据圆度和面积筛选出较小的圆孔
//之后 膨胀一次 腐蚀一次  求二者之间的差值图像进行目标区域的定位
//根据上述定位区域  截取ROI区域  再进行边缘检测  和椭圆拟合  得到 圆孔的直径等相关测量参数* To find the holes, we first segment the dark regions
*为了找到洞,我们首先对暗区域进行分割
threshold (Rim, Dark, 0, 128)
dev_display (Rim)
dev_set_color ('green')
dev_set_draw ('fill')
dev_display (Dark)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Determine all connected components
connection (Dark, DarkRegions)
* Select regions with circular shape and an area larger than 50 pixel
select_shape (DarkRegions, Circles, ['circularity','area'], 'and', [0.85,50], [1.0,99999])
dev_display (Rim)
dev_set_colored (12)
dev_display (Circles)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* To extract a region that contains just the edges of the circles
* use dilation and erosion.
dilation_circle (Circles, ROIOuter, 8.5)
erosion_circle (Circles, ROIInner, 8.5)
difference (ROIOuter, ROIInner, ROI)
union1 (ROI, ROIEdges)
dev_display (Rim)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_color ('green')
dev_display (ROIEdges)
disp_continue_message (WindowID, 'black', 'true')
stop ()//边缘检测
* Reduce the region of interest (domain) to the extracted
* regions containing the edges.
reduce_domain (Rim, ROIEdges, RimReduced)
* Extract subpixel precise edges
edges_sub_pix (RimReduced, Edges, 'canny', 4, 20, 40)
* Select only the contours with length larger than 30 pixels
select_contours_xld (Edges, RelEdges, 'length', 30, 999999, 0, 0)
dev_display (Rim)
dev_set_colored (12)
dev_display (RelEdges)
disp_continue_message (WindowID, 'black', 'true')
stop ()//拟合圆
* Fit an ellipse to the extracted edges
fit_ellipse_contour_xld (RelEdges, 'ftukey', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Ra, Rb, StartPhi, EndPhi, PointOrder)
display_ellipses (Rim, Row, Column, Phi, Ra, Rb, WindowID)
* dev_display (Rim)
* disp_ellipse (WindowID, Row, Column, Phi, Ra, Rb)
* disp_arrow (WindowID, Row - Ra * sin(Phi), Column + Ra * cos(Phi), Row + Ra * sin(Phi), Column - Ra * cos(Phi), 1)
* disp_arrow (WindowID, Row + Ra * sin(Phi), Column - Ra * cos(Phi), Row - Ra * sin(Phi), Column + Ra * cos(Phi), 1)
* Phi2 := Phi + 1.57
* disp_arrow (WindowID, Row - Rb * sin(Phi2), Column + Rb * cos(Phi2), Row + Rb * sin(Phi2), Column - Rb * cos(Phi2), 1)
* disp_arrow (WindowID, Row + Rb * sin(Phi2), Column - Rb * cos(Phi2), Row - Rb * sin(Phi2), Column + Rb * cos(Phi2), 1)
* dev_set_color ('yellow')
* for I := 1 to |Row| by 1
*     disp_message (WindowID, 'd: ' + Diameter[I - 1], 'image', Row[I - 1] - (Ra[I - 1] * 1.5), Column[I - 1] - 70, 'yellow', 'false')
* endfor
disp_continue_message (WindowID, 'black', 'true')
stop ()
///接下来 进行字符的定位//Blob分析:
//将图像进行局部阈值分割,再根据面积,椭圆半径等参数的筛选,定位出字符区域
* Next, the goal is to find the characters in the image.
* Extract small regions with low gray value.
gauss_filter (Rim, RimGauss, 11)  //高斯滤波
dyn_threshold (Rim, RimGauss, SmallAndDarkerRegion, 5, 'dark')  //局部阈值分割图像
dev_display (Rim)
dev_set_draw ('fill')
dev_set_color ('green')
dev_display (SmallAndDarkerRegion)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Compute connected components
connection (SmallAndDarkerRegion, SmallAndDarker)
* Select all regions with an area between 40 and 400 pixels
select_shape (SmallAndDarker, CharCandidates, 'area', 'and', 40, 400)
* From these regions, select those that can be enclosed by
* a given elliptic region.
select_shape (CharCandidates, PossibleChar, ['ra','rb'], 'and', [10,5], [20,30])  //根据椭圆的半径 进行筛选
dev_display (Rim)
dev_set_colored (12)
dev_display (PossibleChar)
disp_continue_message (WindowID, 'black', 'true')
stop ()//上面提取的图像 有干扰 不太好区分  就把他合并成一个区域 先闭操作进行放大  再根据面积筛选出包含ROI的不规则区域
//之后 将不规则区域进行凸包操作
//最后 将与之前的阈值图 进行交集计算  抠出ROI* Extract connected regions containing all the character
union1 (PossibleChar, ROI)
closing_circle (ROI, CharRegion, 17.5)
connection (CharRegion, CharBlocks)
dev_display (Rim)
dev_set_draw ('margin')
dev_display (CharBlocks)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* Select the region that has an area of at least 400 pixel
select_shape (CharBlocks, CharRegion, 'area', 'and', 400, 99999)
* Transform the region into its enclosing rectangle
shape_trans (CharRegion, ROIChar, 'rectangle2')   //将区域转换成一个矩形
dev_display (Rim)
dev_set_color ('green')
dev_display (ROIChar)
disp_continue_message (WindowID, 'black', 'true')
stop ()
display_ellipses (Rim, Row, Column, Phi, Ra, Rb, WindowID)
* Extract all character candidate regions
* that lie in the extracted rectangle region.
intersection (CharCandidates, ROIChar, Characters)  //计算区域的交集  其实就是定位字符区域
* Show the extracted characters
dev_set_colored (12)
dev_display (Characters)//下面就是 进行可视化的优化    开个小窗口 把字符摆正显示
* Fit the smallest surrounding rectangle and get its orientation
smallest_rectangle2 (ROIChar, RowChar, ColumnChar, PhiChar, Length1Char, Length2Char)
* Rotate the image and regions so that the characters are parallel to the lower image border
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_rotate (HomMat2DIdentity, rad(180) - PhiChar, RowChar, ColumnChar, HomMat2DRotate)
affine_trans_region (Characters, CharRotated, HomMat2DRotate, 'constant')
affine_trans_image (Rim, RimRotated, HomMat2DRotate, 'weighted', 'false')
dev_open_window (0, 800, 192, 144, 'black', WindowChar)
* For zooming in, extract a rectangle containing the characters
union1 (CharRotated, CharRotatedAll)
smallest_rectangle1 (CharRotatedAll, Row1, Column1, Row2, Column2)
ZoomHeight := Row2 - Row1 + 1
ZoomWidth := Column2 - Column1 + 1
ZoomFactor := min([768 / ZoomWidth,576 / ZoomHeight])
ZoomRow := (Row1 + Row2) / 2
ZoomColumn := (Column1 + Column2) / 2
dev_set_part (ZoomRow - 576 / ZoomFactor / 2, ZoomColumn - 768 / ZoomFactor / 2, ZoomRow + 576 / ZoomFactor / 2 - 1, ZoomColumn + 768 / ZoomFactor / 2 - 1)
dev_display (RimRotated)
dev_set_draw ('fill')
dev_set_colored (12)
dev_display (CharRotated)

用到的几个算子:
    dyn_threshold --局部阈值分割图像
    select_shape --根据参数筛选图像
    shape_trans–转变区域的形状# 学习目标:

二维测量--轮辋和轮胎的检查相关推荐

  1. 【ABviewer从零开始教学查看器篇⑥】二维测量和三维测量

    ABViewer是一款高质量.高效率.低成本的多功能设计及工程文档管理工具,能为您提供全面的专业的浏览及编辑功能,同时支持30多种光栅和矢量图形格式. 在小编看来,ABViewer是一款非常简单且实用 ...

  2. 【Halcon二维测量】——2D计量模型

    2D计量 2D 计量的概念 通过二维计量,可以测量用特定几何体表示的物体的尺寸.可以测量的几何形状包括圆圈.椭圆.矩形和线条.我们需要测量对象的位置.方向和尺寸的近似值.然后,图像中对象的实际边缘位置 ...

  3. Halcon_二维测量_Apply_bead_inspection_model

    这个例子展示了如何使用胎圈检查算子来检验粘合剂. 胎圈检查可用于检测以下错误: 1.缺少粘合胶的部分,断胶 2.粘合剂过多或过少的部分 3.粘合胶离其预定位置太远的部分 apply_bead_insp ...

  4. 【Halcon二维测量】——使用计量模型以亚像素精度测量圆和矩形

    算法大致思路如下:       1.创建计量模型模板并设置计量对象图像大小       2.根据先验知识生成相关图形形状,如矩形,圆,并将其加入到创建的模板中       3.设置模板的相关参数,包括 ...

  5. 二维测量--轮廓间的距离

    对应示例程序: apply_distance_transform_xld.hdev 目标: 比较算子distance_contours_xld 和算子 apply_distance_transform ...

  6. 基于halcon的二维椭圆测量实例

    halcon二维测量 原图 代码 结果 原图 代码 dev_close_window () read_image (Src, 'src.bmp') get_image_size (Src, Width ...

  7. 医疗检查报告和影像资料,扫二维码就能查看!

    去医院看病不容易,尤其是三甲医院,排队挂号.排队看病.排队付费.排队取检查报告--似乎我们每一次去医院,医院给我们的印象就是非常的多人,而且是人挤人. 在排队取检查报告你有没有这样的经历:随身拎着厚厚 ...

  8. 如何利用码文书把海报图片中的二维码替换成自己的二维码

    通过利用二维码图片进行产品的推广分享已经广泛的应用在各行各业也,用户可以将自己的微信/抖音二维码分享出去,让其他的小伙伴扫码添加自己为好友.方便我们更好的推广自己的产品! 有时候我们看到一张海报很漂亮 ...

  9. 灭火器及消防栓二维码巡检系统搭建

    搭建消防器材灭火器.消火栓管理系统,**摆脱传统消防纸质巡检卡.避免浪费财力物力每年更换纸质检查卡.杜绝传统假检.漏检.记录整理繁琐的缺点. 二维码标签替代传统纸质巡 如何生成消防器材二维码?具体方法 ...

最新文章

  1. 通过 OpenAPI 部署 Npcf_PolicyAuthorization-PostAppSessions API Service
  2. Spring MVC-08循序渐进之国际化(基于Session-SessionLocaleResolver)
  3. 学习笔记Hadoop(六)—— Hadoop集群的安装与部署(3)—— 配置ssh无密码登录
  4. hive ALLOW_UNQUOTED_CONTROL_CHARS
  5. [读书笔记]TCP/IP详解V1读书笔记-3
  6. WCF服务寄宿IIS与Windows服务 - C#/.NET
  7. 歌谣舞台_高光时刻 || 哈油宝藏男孩沈家麒登上吉林卫视和广东卫视青春歌谣舞台!...
  8. 在sphinx中处理使用特殊字符时所引起错误的办法
  9. 迁移实战:一次AntDB(基于pgxl分布式架构的数据库)数据库迁移经验分享
  10. 解除工作压力的四大疗法
  11. 搭建携程Apollo分布式配置中心
  12. VUE系列 ---- 网络模块axios(一 )
  13. 【活动回顾】大咖分享:流量过后,在线教育的留存和发展
  14. 赵栋201771010137《面向对象程序设计(java)》第七周学习总结
  15. 4.25 使用图标集功能标识指定范围的数据 [原创Excel教程]
  16. 微信 小程序 web前端的春天 or 噩梦
  17. Syclover战队专访 | 年度终局之战,键指圣诞狂欢
  18. 用Python进行训练/测试集分割和交叉验证
  19. io口模拟spi,stm32f103与MS5611基于spi总线的温度压力高度数据读取
  20. 8A大功率直流稳压电源设计

热门文章

  1. 树洞外链2.1,一款基于七牛的外链分享平台
  2. android圆形点击效果,Android 三种方式实现自定义圆形页面加载中效果的进度条
  3. oracle 查看表空间总量,oracle 查看表空间以及剩余量
  4. 湖北省黄石市谷歌高清卫星地图下载
  5. Java将字符串分割为数组
  6. 笔记2——一元二次方程平方根(包含实部与虚部)
  7. 河北大学数学模型作业战争飞行计划
  8. 花店商城Flower Shop网站前端HTML页面模板源码
  9. 安卓手机投屏软件_好物推荐:偶然发现的安卓手机投屏软件 非常好用
  10. MVC三层架构(图解)