fit_circle_contour_xld擬合圓


 

在HDevelop中

dev_close_window ()
read_image (Image, 'D:/bb/tu/8.jpg')
rgb1_to_gray (Image, GrayImage)
edges_sub_pix (GrayImage, Edges, 'canny', 1, 5, 10)
*亞像素邊緣
select_shape_xld (Edges, SelectedXLD, 'contlength', 'and', 136.87, 136.9)
segment_contours_xld (SelectedXLD, ContoursSplit, 'lines_circles', 5, 4, 2)
select_shape_xld (ContoursSplit, SelectedXLD1, 'contlength', 'and', 56, 58)

fit_circle_contour_xld (SelectedXLD1, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
*對XLD輪廓做近似圓計算--擬合圓--獲得圓數據
*參數1:輸入xld輪廓
*參數2:圓的擬合算法
*      'ahuber'           對輪廓點進行加權,以減少異常值的影響
*      'algebraic'        這種方法使輪廓點和生成的圓之間的代數距離最小化
*      'atukey'           對輪廓點進行加權,並忽略異常值
*      'geohuber'         對輪廓點進行加權,以減少異常值的影響
*      'geometric'    使輪廓點和生成的圓之間的幾何距離最小化。距離度量在統計上是最優的,但需要更多的計算時間。
*                     如果輪廓點被噪聲嚴重扭曲,建議使用此選項
*      'geotukey'         對輪廓點進行加權,並忽略異常值
*參數8:Row圓中心的行坐標
*參數9:Column圓中心的列坐標
*參數10:Radius圓的半徑
*參數11:StartPhi起點的角度
*參數12:EndPhi終點的角度
*參數13:PointOrder沿邊界的點順序( 'negative'負序, 'positive'正序)
*注意:擬合時參數1只能包含一條xld

gen_circle_contour_xld (ContCircle, Row, Column, Radius, StartPhi, EndPhi, PointOrder, 1)
*創建圓或圓弧的XLD輪廓
*參數1:輸出輪廓
*參數2:輸入圓心的行坐標
*參數3:輸入圓心列坐標
*參數4:輸入圓的半徑
*參數5:輸入起始點角度
*參數6:輸入結束點的角度
*參數7:輸入沿邊界的點序( 'negative'負序, 'positive'正序)
*參數8:輸入相鄰輪廓點之間的距離(Resolution >= 0.00001)


get_image_size (GrayImage, Width, Height)
dev_open_window(10,10,Width, Height,'black',WindowHandle)
dev_display(SelectedXLD1)

dev_open_window(10,10,Width, Height,'black',WindowHandle1)
dev_display(ContCircle)

 

 

 

 

在QtCreator中

  HObject  ho_Image, ho_GrayImage, ho_Edges, ho_SelectedXLD;
  HObject  ho_ContoursSplit, ho_SelectedXLD1, ho_ContCircle;
  HTuple  hv_Row, hv_Column, hv_Radius, hv_StartPhi;
  HTuple  hv_EndPhi, hv_PointOrder, hv_Width, hv_Height, hv_WindowHandle;
  HTuple  hv_WindowHandle1;
  ReadImage(&ho_Image, "D:/bb/tu/8.jpg");
  Rgb1ToGray(ho_Image, &ho_GrayImage);
  EdgesSubPix(ho_GrayImage, &ho_Edges, "canny", 1, 5, 10);
  //亞像素邊緣
  SelectShapeXld(ho_Edges, &ho_SelectedXLD, "contlength", "and", 136.87, 136.9);
  SegmentContoursXld(ho_SelectedXLD, &ho_ContoursSplit, "lines_circles", 5, 4, 2);
  SelectShapeXld(ho_ContoursSplit, &ho_SelectedXLD1, "contlength", "and", 56, 58);

  FitCircleContourXld(ho_SelectedXLD1, "algebraic", -1, 0, 0, 3, 2, &hv_Row, &hv_Column, 
      &hv_Radius, &hv_StartPhi, &hv_EndPhi, &hv_PointOrder);
  //對XLD輪廓做近似圓計算--擬合圓--獲得圓數據
  //參數1:輸入xld輪廓
  //參數2:圓的擬合算法
  //     'ahuber'           對輪廓點進行加權,以減少異常值的影響
  //     'algebraic'        這種方法使輪廓點和生成的圓之間的代數距離最小化
  //     'atukey'           對輪廓點進行加權,並忽略異常值
  //     'geohuber'         對輪廓點進行加權,以減少異常值的影響
  //     'geometric'    使輪廓點和生成的圓之間的幾何距離最小化。距離度量在統計上是最優的,但需要更多的計算時間。
  //                    如果輪廓點被噪聲嚴重扭曲,建議使用此選項
  //     'geotukey'         對輪廓點進行加權,並忽略異常值
  //參數8:Row圓中心的行坐標
  //參數9:Column圓中心的列坐標
  //參數10:Radius圓的半徑
  //參數11:StartPhi起點的角度
  //參數12:EndPhi終點的角度
  //參數13:PointOrder沿邊界的點順序( 'negative'負序, 'positive'正序)
  //注意:擬合時參數1只能包含一條xld

  GenCircleContourXld(&ho_ContCircle, hv_Row, hv_Column, hv_Radius, hv_StartPhi, 
      hv_EndPhi, hv_PointOrder, 1);
  //創建圓或圓弧的XLD輪廓
  //參數1:輸出輪廓
  //參數2:輸入圓心的行坐標
  //參數3:輸入圓心列坐標
  //參數4:輸入圓的半徑
  //參數5:輸入起始點角度
  //參數6:輸入結束點的角度
  //參數7:輸入沿邊界的點序( 'negative'負序, 'positive'正序)
  //參數8:輸入相鄰輪廓點之間的距離(Resolution >= 0.00001)


  GetImageSize(ho_GrayImage, &hv_Width, &hv_Height);
  SetWindowAttr("background_color","black");
  OpenWindow(10,10,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle);
  HDevWindowStack::Push(hv_WindowHandle);
  if (HDevWindowStack::IsOpen())
    DispObj(ho_SelectedXLD1, HDevWindowStack::GetActive());

  SetWindowAttr("background_color","black");
  OpenWindow(10,10,hv_Width,hv_Height,0,"visible","",&hv_WindowHandle1);
  HDevWindowStack::Push(hv_WindowHandle1);
  if (HDevWindowStack::IsOpen())
    DispObj(ho_ContCircle, HDevWindowStack::GetActive());

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM