长度和角度测量例子(一)

素材如下:

image.png

代码如下, 带注释:

   *读取并截取图片
   dev_close_window()
   read_image (Image, 'C:/Users/Administrator/Desktop/微信截图_20180928100130.png')
   crop_rectangle1 (Image, ImagePart, 75, 0, 400, 400)
   get_image_size (ImagePart, Width, Height)
   dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
   dev_display (ImagePart)
    
   *获取图形的边界
   threshold (ImagePart, Regions, 0, 112)
    
   *分离三角形和圆形
   connection(Regions,ConnectedRegions)
   sort_region(ConnectedRegions,SortedRegions,'upper_left','true','column')
   select_obj(SortedRegions,Circle,1)
   select_obj(SortedRegions,Triangle,2)
    
   *获取三角形各边的信息
   skeleton(Triangle,TriangleSkeleton)
   gen_contours_skeleton_xld(TriangleSkeleton,TriangleContours,1,'filter')
   segment_contours_xld(TriangleContours,ContoursSplit,'lines_circles', 5, 4, 2)
   select_contours_xld(ContoursSplit,SelectedContours, 'contour_length',100, 999, -0.5, 0.5)
   fit_line_contour_xld (SelectedContours, 'tukey', -1, 10, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
    
   *计算三角形角度
   angle_ll (RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], Angle1)
   angle_ll (RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], RowBegin[2], ColBegin[2], RowEnd[2], ColEnd[2], Angle2)
   angle_ll (RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], RowBegin[2], ColBegin[2], RowEnd[2], ColEnd[2], Angle3)
   Angle1:=abs(deg(Angle1))
   Angle2:=abs(deg(Angle2))
   Angle3:=abs(deg(Angle3))
    
   *获取圆的信息
   area_center(Circle,AreaCircle, RowCircle, ColumnCircle)
    
   *计算圆心到三角形各边的距离
   Distance := []
   for Index := 0 to 2 by 1
       distance_pl (RowCircle, ColumnCircle, RowBegin[Index], ColBegin[Index], RowEnd[Index], ColEnd[Index], ThisDistance)
       Distance := [Distance,ThisDistance]
   endfor


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864