当前位置: 首页 > news >正文

halcon轮廓处理(不同线段用不同颜色显示)与交点检测

主程序

read_image (image_BN, 'C:/训练照片/16')
threshold(image_BN,Regions,0,30)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1000, 9999999999)
dismember_outline (SelectedRegions, Rows, Columns) //函数输入图像Region,输出参数Rows, Columns
* read_image (image_S, 'S.bmp')

dismember_outline函数实现

gen_contour_region_xld (Region, Contours, 'border')
smooth_contours_xld (Contours, SmoothedContours, 11)
gen_region_contour_xld (SmoothedContours, SmoothedRegion, 'filled')
gen_contour_region_xld (SmoothedRegion, Contours, 'border')segment_contours_xld (Contours, Segments, 'lines_circles', 5, 4, 3.5)Colors := ['red', 'green', 'blue', 'yellow', 'magenta', 'cyan', 'orange']IntersectionPoints := []dev_update_off ()
count_obj (Segments, NumSegments)for i := 1 to NumSegments by 1select_obj (Segments, CurrentSegment, i)ColorIndex := (i-1) % 7dev_set_color (Colors[ColorIndex])dev_display (CurrentSegment)get_contour_xld (CurrentSegment, Row, Col)PointCount := |Row|fit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (Dist <= 1.0 and PointCount >= 5)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifelseif (PointCount >= 10)tryfit_circle_contour_xld (CurrentSegment, 'geometric', -1, 0, 0, 3, 2, RowC, ColC, Radius, StartPhi, EndPhi, Order)if (Radius > 0 and abs(EndPhi - StartPhi) >= rad(15))if (Order == 'positive')StartPointRow := RowC + Radius * sin(StartPhi)StartPointCol := ColC + Radius * cos(StartPhi)EndPointRow := RowC + Radius * sin(EndPhi)EndPointCol := ColC + Radius * cos(EndPhi)elseStartPointRow := RowC + Radius * sin(EndPhi)StartPointCol := ColC + Radius * cos(EndPhi)EndPointRow := RowC + Radius * sin(StartPhi)EndPointCol := ColC + Radius * cos(StartPhi)endifif (i == 1)IntersectionPoints := [IntersectionPoints, StartPointRow, StartPointCol, EndPointRow, EndPointCol]elseIntersectionPoints := [IntersectionPoints, EndPointRow, EndPointCol]endifelsefit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 10, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifendifcatch (Exception)fit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 10, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifendtryelsefit_line_contour_xld (CurrentSegment, 'tukey', -1, 0, 5, 10, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)if (i == 1)IntersectionPoints := [IntersectionPoints, RowBegin, ColBegin, RowEnd, ColEnd]elseIntersectionPoints := [IntersectionPoints, RowEnd, ColEnd]endifendifendif
endfor* 闭合处理:确保首尾点相连
if (NumSegments >= 1 and |IntersectionPoints| >= 4)* 正确访问数组元素(Row和Col交替存储)FirstRow := IntersectionPoints[0]FirstCol := IntersectionPoints[1]LastRow := IntersectionPoints[|IntersectionPoints|-2]LastCol := IntersectionPoints[|IntersectionPoints|-1]* 如果未闭合则添加闭合点if (sqrt((FirstRow - LastRow)*(FirstRow - LastRow) + (FirstCol - LastCol)*(FirstCol - LastCol)) > 2)IntersectionPoints := [IntersectionPoints, FirstRow, FirstCol]endif
endifdev_set_color ('white')
dev_set_draw ('fill')
dev_set_line_width (1)* 正确显示交点
for j := 0 to |IntersectionPoints|/2 - 1 by 1Row := IntersectionPoints[2*j]Col := IntersectionPoints[2*j+1]gen_circle (Circle, Row, Col, 3)dev_display (Circle)
endfordev_update_on ()

在这里插入图片描述

相关文章:

  • Python的文本操作和try语句使用
  • day1 大模型学习 Qwen系列学习
  • 精益数据分析(76/126):最小可行愿景(MVV)与可持续商业模式构建
  • 飞牛fnNAS远程映射盘符
  • MySql添加非空字段时的“伪空”问题
  • JC/T 2387-2024 改性聚苯乙烯泡沫(EPS)复合装饰制品检测
  • 生存资料的多因素分析,如果满 足等比例风险假定, 采用Cox回归; 如果不满足等比例风险假定,则考虑采用 非等比例Cox回归分析研究预后因素的影响
  • 【Pandas】pandas DataFrame round
  • Ubuntu+Docker+内网穿透:保姆级教程实现安卓开发环境远程部署
  • AI智慧高光谱遥感实战精修班暨手撕99个案例项目、全覆盖技术链与应用场景一站式提升方案
  • 加工生产调度(Johnson算法)
  • 重读《人件》Peopleware -(11)Ⅱ 办公环境 Ⅳ 插曲:生产力测量与不明飞行物
  • 浏览器原生 Web Crypto API 实现 SHA256 Hash 加密
  • 架构实践中,指标体系如何科学建立?构建指标体系的五层结构模型是什么?不同架构风格下的指标体系有怎样的差异?
  • 嵌入式软件架构规范之 - 分层设计
  • Cmake+VS2019MSVC编译器编译opencv4.10成功步骤
  • Kotlin 极简小抄 P10(类与对象、主构造函数、带有默认参数值的主构造函数、次要构造函数)
  • python——多线程编程(threading)
  • python实战:如何获取word文档中指定内容并作为新文件名
  • 鸿蒙 HarmonyOS NEXT 系统 Preference 首选项使用全解析
  • 做网站 阿里云/长沙网站推广智投未来
  • 做网站听的纯音乐/百度手机网页版入口
  • 网站是做后台好还是做前台好/网站关键词优化软件效果
  • 百度西安研发中心/站长工具seo综合查询网
  • 湘潭网站seo/互联网推广方案
  • dede 手机网站/网站如何做seo推广