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

[例程] Halcon案例分析_拉链检测

  [复制链接]
绝地武士 发表于 2016-10-12 11:28:48 | 显示全部楼层 |阅读模式
QQ截图20161012112636.jpg

  1. * Code generated by Image Acquisition 01
  2. list_files ('I:/测量图片及程序/拉链/', ['files','follow_links'], ImageFiles)
  3. tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)图片下载:
  4. [hide]链接:[url]http://pan.baidu.com/s/1c9TzOi[/url] 密码:17a1[/hide]
  5. ,'ignore_case'], ImageFiles)
  6. for Index := 0 to |ImageFiles| - 1 by 1

  7.     read_image (image, ImageFiles[Index])
  8.     * Do something
  9. count_seconds(Seconds)

  10. * read_image (image, 'C:/Documents and Settings/zazaniao/桌面/拉链/拉链ng2.png')
  11. rgb1_to_gray(image, GrayImage)

  12. threshold (GrayImage, Regions, 200, 255)
  13. connection(Regions, ConnectedRegions2)
  14. select_shape(ConnectedRegions2, SelectedRegions2, 'area', 'and', 150, 99999)

  15. closing_circle(SelectedRegions2, RegionClosing, 3.5)



  16. select_shape(RegionClosing, SelectedRegions, ['width','height'], 'and', [8,25], [40,80])

  17. union1(SelectedRegions, RegionUnion)
  18. gen_rectangle2(Rectangle, 0, 0, 0, 800, 10)

  19. dilation1(RegionUnion, Rectangle, RegionClosing1,1)

  20. connection(RegionClosing1, ConnectedRegions1)

  21. select_shape(ConnectedRegions1, SelectedRegions1, 'width', 'and', 400, 99999)
  22. dilation_rectangle1(SelectedRegions1, SelectedRegions1, 21, 1)
  23. smallest_rectangle2(SelectedRegions1, Row, Column, Phi, Length1, Length2)
  24. get_image_size(GrayImage, Width, Height)
  25. gen_empty_obj(LLine)
  26. gen_empty_obj(RLine)
  27. ResultFlag:=0
  28. for i:=0 to |Row|-1 by 1

  29. gen_measure_rectangle2(Row[i], Column[i], 0,Width, Length2[i],  Width, Height, 'nearest_neighbor', MeasureHandle)
  30. gen_rectangle2(Rectangle1, Row[i], Column[i], 0,Width, Length2[i])
  31.         measure_pairs (GrayImage, MeasureHandle, 1, 25, 'positive_strongest', \
  32. 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond,\
  33. ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)
  34.         close_measure(MeasureHandle)
  35.   dev_display(GrayImage)
  36.     for j:=0 to |RowEdgeFirst|-1 by 1
  37.     gen_rectangle2(Rectangle1, RowEdgeFirst[j], ColumnEdgeFirst[j], Phi[i], 1, Length2[i])
  38.     concat_obj(LLine,Rectangle1,LLine)
  39.      gen_rectangle2(Rectangle1, RowEdgeSecond[j], ColumnEdgeSecond[j], Phi[i], 1, Length2[i])
  40.      concat_obj(LLine,Rectangle1,LLine)
  41. *      if(j<|IntraDistance|and  j>0)
  42. *      disp_message(3600, IntraDistance[j], 'image', RowEdgeFirst[j]-40, ColumnEdgeFirst[j], 'red', 'false')
  43. *      endif
  44. *      if(j<|InterDistance| and  j>0)
  45. *      disp_message(3600, InterDistance[j], 'image', RowEdgeSecond[j]+40, ColumnEdgeSecond[j], 'red', 'false')
  46. *      endif
  47. endfor

  48.      tuple_median(InterDistance, Median)
  49.      tuple_max(InterDistance, Max)
  50.      if(Max>1.5*Median)
  51.          ResultFlag:=ResultFlag+1
  52.      endif
  53.          
  54. dev_display(LLine)

  55. if(ResultFlag>0)
  56.          disp_message(3600, 'chain NG', 'window', 12, 12, 'red', 'true')
  57.      else
  58.           disp_message(3600, 'chain OK', 'window', 12, 12, 'green', 'true')
  59.      endif
  60. endfor
  61. count_seconds(Seconds1)
  62. time:=1000*(Seconds1-Seconds)
  63. stop()
  64. endfor
复制代码
图片下载:
游客,如果您要查看本帖隐藏内容请回复

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
a3231459 发表于 2018-1-24 10:32:00 | 显示全部楼层
多学习
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
Olee 发表于 2020-4-8 10:05:55 | 显示全部楼层
再稳固一遍
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
囚绿 发表于 2023-2-13 21:39:28 | 显示全部楼层
thank u share
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
EricLu55 发表于 2023-2-14 01:37:50 | 显示全部楼层
頂一下 學習大神的思維
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
2149246776 发表于 2023-2-17 16:18:48 | 显示全部楼层
学习了,谢谢
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
wy008163 发表于 2023-2-17 19:59:38 | 显示全部楼层
学习学习。。。。。。
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
张满满 发表于 2023-2-20 18:51:32 | 显示全部楼层
多学习
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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