设置首页收藏本站
开启左侧

如何把明显不是钉子的显示去除掉

[复制链接]
youyiyang 发表于 2021-8-18 16:35:40 | 显示全部楼层 |阅读模式
在我们的一个项目中,需要对客户的地板上的钉子找到,halcon程序写了2版,应该说比以前好了很多i,但是还是把其他不是钉子的地方找出来,由于客户地板上的钉子是机器打的,所以基本保持相同的横向和纵向距离,所以如何在代码中在最后加上这个距离的判断,使明显不对的钉子不要显示出来。代码如下所示,请查看:
  1. * 识别区域
  2. gen_rectangle1 (Rectangle, startY, startX, EndY, EndX)
  3. reduce_domain (Image, Rectangle, ImageReduced)
  4. * 初步边缘提取
  5. edges_image (ImageReduced, ImaAmp, ImaDir, 'canny', 1, 'nms', 10, 20)
  6. threshold (ImaAmp, Region1, 1, 255)
  7. connection (Region1, ConnectedRegions)
  8. select_shape (ConnectedRegions, SelectedRegions, ['outer_radius','anisometry','area'], 'and', [10,1,50], [30,3.9,300])
  9. shape_trans (SelectedRegions, RegionTrans, 'outer_circle')
  10. dilation_circle (RegionTrans, RegionDilation,5.5)
  11. union1 (RegionDilation, RegionUnion)
  12. reduce_domain (Image, RegionUnion, ImageReduced2)
  13. * 详细边缘提取
  14. edges_sub_pix (ImageReduced2, Edges, 'canny', 1, 5, 15)
  15. select_shape_xld (Edges, SelectedXLD, ['contlength','outer_radius'], 'and', [28,10], [99999,99999])
  16. segment_contours_xld (SelectedXLD, ContoursSplit, 'lines_circles', 4, 2, 2)
  17. * 筛选
  18. count_obj (ContoursSplit, NumberContours)
  19. gen_empty_obj (Circles)
  20. for i := 1 to NumberContours by 1
  21.     select_obj (ContoursSplit, ObjectSelected, i)
  22.     get_contour_global_attrib_xld (ObjectSelected, 'cont_approx', Attrib)
  23.     if (Attrib == 1)
  24.         concat_obj (Circles, ObjectSelected, Circles)
  25.     endif
  26. endfor
  27. union_cocircular_contours_xld (Circles, UnionContours2, rad(60), rad(10), rad(30), 100, 50, 10, 'true', 1)
  28. select_contours_xld (UnionContours2, SelectedContours, 'contour_length', 28, 200, -0.5, 0.5)
  29. * 拟合圆
  30. count_obj (SelectedContours, NumberCircles)
  31. gen_empty_obj (ContCircles)
  32. for i := 1 to NumberCircles by 1
  33.     select_obj (SelectedContours, ObjectSelected, i)
  34.     fit_circle_contour_xld (ObjectSelected, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
  35.     gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, rad(360), 'positive', 1.5)
  36.     GetRow[i-1] := Row
  37.     GetCol[i-1] := Column
  38.     concat_obj (ContCircles, ContCircle, ContCircles)
  39. endfor
  40. * 排序
  41. sort_contours_xld (ContCircles, SortedContours, 'upper_left', 'true', 'row')
  42. ResultRow := []
  43. ResultCol := []
  44. SampleRow := []
  45. SampleCol := []
  46. count_obj (SortedContours, Number2)
  47. j:=0
  48. if (Number2 >= 2)
  49.     n := 1
  50.     for i := 2 to Number2 by 1
  51.         select_obj (SortedContours, Circle1, i-1)
  52.         area_center_xld (Circle1, Area1, Row1, Column1, PointOrder1)
  53.         select_obj (SortedContours, Circle2, i)
  54.         area_center_xld (Circle2, Area2, Row2, Column2, PointOrder2)
  55.         distance_pp(Row1, Column1, Row2, Column2, Distance)
  56.        * disp_line(PointOrder2, Row1, Column1, Row2, Column2)
  57.         if (i == 2)
  58.             ResultRow[0] := Row1
  59.             ResultCol[0] := Column1
  60.         endif
  61.         if (Distance > 10)
  62.             ResultRow[n] := Row2
  63.             ResultCol[n] := Column2
  64.             n := n+1
  65.         endif
  66.         j:=j+1
  67.     endfor
  68. endif
  69. return ()
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| youyiyang 发表于 2021-8-18 16:48:52 | 显示全部楼层

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
Lee0417 发表于 2021-8-25 08:50:42 | 显示全部楼层
可以尝试,先按中心点row排序,然后按照两两column相减在某个范围筛选,
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| youyiyang 发表于 2021-8-31 17:26:52 | 显示全部楼层
谢谢你的回复,我再看一下
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表