设为首页收藏本站
授权版本:2024_07
开启左侧

从某网站找的付费资源,可以拟合直线的自定义算子,菜鸟不会用,请大佬指点一下。

[复制链接]
wjjun 发表于 2024-3-26 09:56:31 | 显示全部楼层 |阅读模式
  1. gen_empty_obj (ShowAll)
  2. get_image_size (Image, Width, Height)
  3. RowAll:=[]
  4. ColAll:=[]
  5. for IndexNum := 0 to |RowStart|-1 by 1
  6.         gen_contour_polygon_xld (Contour, [RowStart[IndexNum],RowEnd[IndexNum]], [ColStart[IndexNum],ColEnd[IndexNum]])
  7.         concat_obj (ShowAll, Contour, ShowAll)
  8.         Row:=[]
  9.         Col:=[]
  10.     if (CountOrStep>0)
  11.         for Index := 0 to CountOrStep by 1
  12.             Rowtemp := (RowEnd[IndexNum]-RowStart[IndexNum])*(1.0/CountOrStep*Index)+RowStart[IndexNum]
  13.             Coltemp := (ColEnd[IndexNum]-ColStart[IndexNum])*(1.0/CountOrStep*Index)+ColStart[IndexNum]
  14.                 Row:=[Row,Rowtemp]
  15.                 Col:=[Col,Coltemp]
  16.             endfor
  17.         else
  18.             angle_lx (RowStart[IndexNum], ColStart[IndexNum], RowEnd[IndexNum], ColEnd[IndexNum], Phi)
  19.             Rowt:=RowStart[IndexNum]
  20.             Colt:=ColStart[IndexNum]
  21.             gen_region_contour_xld (Contour, Region, 'margin')
  22.             IsInside:=1
  23.             while (IsInside)
  24.                 Row:=[Row,Rowt]
  25.                 Col:=[Col,Colt]
  26.             Rowt := Rowt+(-CountOrStep)*sin(-Phi)
  27.             Colt := Colt+(-CountOrStep)*cos(-Phi)
  28.                 test_region_point (Region, Rowt, Colt, IsInside)
  29.             endwhile            
  30.         endif

  31.         if (IsAngleAuto=1)
  32.             angle_lx (RowStart[IndexNum], ColStart[IndexNum], RowEnd[IndexNum], ColEnd[IndexNum], Phi)
  33.             RowOff:=(1.0*Heiget/2*sin(Phi+rad(90)))
  34.             ColOff:=(1.0*Heiget/2*cos(Phi+rad(90)))
  35.         else
  36.             RowOff:=(1.0*Heiget/2*sin(rad(-Angle)))
  37.             ColOff:=(1.0*Heiget/2*cos(rad(-Angle)))
  38.         endif
  39.         RowS:=Row-RowOff
  40.         ColS:=Col-ColOff
  41.         RowE:=Row+RowOff
  42.         ColE:=Col+ColOff


  43.         for Index := 0 to |RowS|-1 by 1

  44.             if(Index=0 or Index=|RowS|-1)
  45.                 gen_arrow_contour_xld (Arrow, RowS[Index], ColS[Index], RowE[Index], ColE[Index], ROIWidth, ROIWidth)
  46.                 concat_obj (ShowAll, Arrow, ShowAll)
  47.             endif
  48.             test_region_point (Image, RowS[Index], ColS[Index], IsInside1)
  49.             test_region_point (Image,  RowE[Index], ColE[Index], IsInside2)
  50.             if (0=IsInside1 or 0=IsInside2)
  51.                 continue
  52.             endif
  53.             set_system ('int_zooming', 'true')
  54.             LineRowStart_Measure_01_0 := RowS[Index]
  55.             LineColumnStart_Measure_01_0 := ColS[Index]
  56.             LineRowEnd_Measure_01_0 := RowE[Index]
  57.             LineColumnEnd_Measure_01_0 := ColE[Index]
  58.             TmpCtrl_Row := 0.5*(LineRowStart_Measure_01_0+LineRowEnd_Measure_01_0)
  59.             TmpCtrl_Column := 0.5*(LineColumnStart_Measure_01_0+LineColumnEnd_Measure_01_0)
  60.             TmpCtrl_Dr := LineRowStart_Measure_01_0-LineRowEnd_Measure_01_0
  61.             TmpCtrl_Dc := LineColumnEnd_Measure_01_0-LineColumnStart_Measure_01_0
  62.             TmpCtrl_Phi := atan2(TmpCtrl_Dr, TmpCtrl_Dc)
  63.             TmpCtrl_Len1 := 0.5*sqrt(TmpCtrl_Dr*TmpCtrl_Dr + TmpCtrl_Dc*TmpCtrl_Dc)
  64.             TmpCtrl_Len2 := ROIWidth


  65.             if (isDbLine=1)
  66.                 gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2,Width, Height, 'nearest_neighbor', MsrHandle_Measure_01_0)
  67.                 measure_pos (Image, MsrHandle_Measure_01_0, Sigma, Threshold, Transition,Select, Row_Measure_01_1, Column_Measure_01_1, Amplitude_Measure_01_0, Distance_Measure_01_0)
  68.                 gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi+rad(180), TmpCtrl_Len1, TmpCtrl_Len2,Width, Height, 'nearest_neighbor', MsrHandle_Measure_01_0)
  69.                 measure_pos (Image, MsrHandle_Measure_01_0, Sigma, Threshold, Transition,Select, Row_Measure_01_2, Column_Measure_01_2, Amplitude_Measure_01_0, Distance_Measure_01_0)
  70.                 Row_Measure_01_0:=(Row_Measure_01_1+Row_Measure_01_2)/2.0
  71.                 Column_Measure_01_0:=(Column_Measure_01_1+Column_Measure_01_2)/2.0
  72.             else
  73.                 gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2,Width, Height, 'nearest_neighbor', MsrHandle_Measure_01_0)
  74.                 measure_pos (Image, MsrHandle_Measure_01_0, Sigma, Threshold, Transition,Select, Row_Measure_01_0, Column_Measure_01_0, Amplitude_Measure_01_0, Distance_Measure_01_0)
  75.             endif


  76.             close_measure (MsrHandle_Measure_01_0)
  77.             RowAll:=[RowAll,Row_Measure_01_0]
  78.             ColAll:=[ColAll,Column_Measure_01_0]
  79.         endfor
  80. endfor
  81. gen_cross_contour_xld (Cross, RowAll, ColAll, ROIWidth, rad(45))
  82. concat_obj (ShowAll, Cross, ShowAll)
  83. gen_contour_polygon_xld (ContourLine, RowAll, ColAll)
  84. if (MaxNumRatio<0 and MaxNumRatio>1)
  85.     fit_line_contour_xld (ContourLine, 'tukey', -1, 0, 5, 2, RowB, ColB, RowE, ColE, Nr, Nc, Dist)
  86. else
  87.     fit_line_contour_xld (ContourLine, 'tukey', |RowAll|*MaxNumRatio, 0, 5, 2, RowB, ColB, RowE, ColE, Nr, Nc, Dist)
  88. endif
  89. gen_contour_polygon_xld (Contour, [RowB,RowE], [ColB,ColE])
  90. concat_obj (ShowAll, Contour, ShowAll)
  91. return ()
复制代码
LineInspection_AaronLin.zip (2.25 KB, 下载次数: 18)

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
halcon2016 发表于 2024-3-26 11:15:35 | 显示全部楼层
扫了一眼,不就是测量直线吗,直接用二维测量多简单,去看看add_metrology_object_line_measure 算子
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| wjjun 发表于 2024-3-26 11:28:12 | 显示全部楼层
halcon2016 发表于 2024-3-26 11:15
扫了一眼,不就是测量直线吗,直接用二维测量多简单,去看看add_metrology_object_line_measure 算子 ...

谢谢大佬。
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
ntbing 发表于 2024-3-26 13:14:23 | 显示全部楼层

还是可以的,可以自由屏蔽部分区域
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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