ハフ変換投票によって点列から円を検出する
Namespace: fvalgcliAssembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)
Syntax
C# |
---|
public static int fnFIE_hough_circles_detect( DEDGE_T_PTR vpEdgePnts, int iPntsNum, double dRMin, double dRMax, double dRsl, int iQRange, int iEdgePercent, int iMinScore, f_hough_objectcolor iCircleColor, bool bRefine, int iMergeXY, int iMergeR, ref HCD_CIRCLE_T_PTR vppCircles, ref int ipCirclesNum, INT_PTR ipPntsIndex ) |
Visual Basic |
---|
Public Shared Function fnFIE_hough_circles_detect ( vpEdgePnts As DEDGE_T_PTR, iPntsNum As Integer, dRMin As Double, dRMax As Double, dRsl As Double, iQRange As Integer, iEdgePercent As Integer, iMinScore As Integer, iCircleColor As f_hough_objectcolor, bRefine As Boolean, iMergeXY As Integer, iMergeR As Integer, ByRef vppCircles As HCD_CIRCLE_T_PTR, ByRef ipCirclesNum As Integer, ipPntsIndex As INT_PTR ) As Integer |
Parameters
- vpEdgePnts
- Type: fvalgcli..::..DEDGE_T_PTR
入力点列
- iPntsNum
- Type: System..::..Int32
入力点数, 4点以上なければならない
- dRMin
- Type: System..::..Double
検出目標にする円の最小半径 ( >= 3 * dRsl )
- dRMax
- Type: System..::..Double
検出目標にする円の最大半径
- dRsl
- Type: System..::..Double
分解能
- iQRange
- Type: System..::..Int32
エッジ方向の片幅, 度単位で[0, 90)
- iEdgePercent
- Type: System..::..Int32
円上のエッジ点数と円周の百分率の閾値, [0, 99]
- iMinScore
- Type: System..::..Int32
円上のエッジ点数の閾値, 数値は4以上を指定する
- iCircleColor
- Type: fvalgcli..::..f_hough_objectcolor
円の色。- BLACK_COLOR: 黒い円を検出する
- WHITE_COLOR: 白い円を検出する
- BLACK_WHITE_COLOR: 円の色は未知、未定の場合
- bRefine
- Type: System..::..Boolean
ロバスト推定法による検出円のパラメータを算出- TRUE: ロバスト推定法を使う
- FALSE:ロバスト推定法を使わない
- iMergeXY
- Type: System..::..Int32
検出された円の統括する円心範囲サイズ、0以上に設定する
- iMergeR
- Type: System..::..Int32
検出された円の統括する円半径範囲サイズ、0以上に設定する
- vppCircles
- Type: fvalgcli..::..HCD_CIRCLE_T_PTR%
出力円の配列。 IntPtr.Zero で初期化してください。
- ipCirclesNum
- Type: System..::..Int32%
検出された円の数量
- ipPntsIndex
- Type: fvalgcli..::..INT_PTR
検出された円上の点のindex
Return Value
Type: Int32以下のエラーコードを返します。
エラーコード:
f_err | 内容 |
---|---|
F_ERR_NONE | 正常終了 |
F_ERR_NOMEMORY | メモリ不足エラー |
F_ERR_INVALID_PARAM | パラメーター不正 |
F_ERR_CALC_IMPOSSIBLE | iMinScore の値が小さ過ぎるので、計算不可能 |
F_ERR_NO_LICENCE | ライセンスエラー、または未初期化エラー |
Remarks
Examples
C# | Copy |
---|---|
// $Revision: 1.1 $ using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using fvalgcli; namespace TC { public partial class FIE { /// <summary> /// ハフ変換投票によって点列から円を検出する. /// </summary> [FvPluginExecute] public void fnFIE_hough_circles_detect() { int status = (int)f_err.F_ERR_NONE; FHANDLE hHough = FHANDLE.Zero; FHANDLE himg = FHANDLE.Zero; F_DEDGE_PTR edges = IntPtr.Zero; DEDGE_T_PTR edges2 = IntPtr.Zero; HCD_CIRCLE_T_PTR ans_circles = IntPtr.Zero; INT_PTR pnts_index = IntPtr.Zero; try { // ハフオープン. int stq = 0; int edq = 359; int sx = 0; int sy = 0; int ex = 319; int ey = 239; int exerr = 0; hHough = fnFIE_hough_lines_open(stq, edq, sx, sy, ex, ey, ref exerr); // 初期化. fnFIE_hough_lines_init_space(hHough); // 投票空間の取得. fnFIE_hough_lines_get_space(hHough); // エッジを検出する. api.fnFIE_load_img_file(TestImageDir + "/TC/SampleCode/floppy_UC8.jpg", ref himg, f_color_img_type.F_COLOR_IMG_TYPE_UC8); F_EDGE_SOBEL_PARAMS param = new F_EDGE_SOBEL_PARAMS(); param.mag_threshold = 120; param.nms_length = 3; DPNT_T offset = new DPNT_T(); int edge_num = 0; status = api.fnFIE_edge_sobel_subpix(himg, FHANDLE.Zero, ref param, f_edge_feature_mode.F_EDGE_FEAT_DIRECT, f_border_mode.F_BORDER_NONE, offset, ref edges, ref edge_num); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_edge_sobel_subpixel: エラーが発生しました。({0})", (f_err)status); // DEDGE_T <=変換= F_DEDGE edges2 = DEDGE_T_PTR.alloc(edge_num); for (int i = 0; i < edge_num; i++) edges2[i] = DEDGE_T.init(edges[i].x, edges[i].y, edges[i].q); // 検出. double dRmin = 3.0; double dRmax = 50.0; double dRsl = 1.0; bool bRefine = true; int iQRange = 10; int iEdgePercent = 10; int iMinScore = 15; int iMergeXY = 2; int iMergeR = 1; f_hough_objectcolor iCircleColor = f_hough_objectcolor.BLACK_COLOR; int circle_num = 0; // 入力点列と同じサイズの配列を確保. pnts_index = INT_PTR.alloc(edge_num); //INT_PTR pi_pns_index = IntPtr.Zero; // 不要な場合は NULL (FHANDLE.Zero) を指定. status = api.fnFIE_hough_circles_detect( edges2, edge_num, dRmin, dRmax, dRsl, iQRange, iEdgePercent, iMinScore, iCircleColor, bRefine, iMergeXY, iMergeR, ref ans_circles, ref circle_num, pnts_index); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_hough_lines_detection: エラーが発生しました。({0})", (f_err)status); Console.WriteLine("fnFIE_hough_circles_detect"); Console.WriteLine("circle_num={0}", circle_num); for (int i = 0; i < circle_num; i++) { Console.WriteLine("xc,yc={0},{1}, r={2}, score={3}", ans_circles[i].xc, ans_circles[i].yc, ans_circles[i].r, ans_circles[i].score); } Console.WriteLine("pnts_index="); for (int i = 0; i < edge_num; i++) { Console.Write("{0,4:###0},", pnts_index[i]); if ((i + 1) % 20 == 0) Console.WriteLine(""); } Console.WriteLine(""); } finally { hHough.Dispose(); himg.Dispose(); edges.Dispose(); edges2.Dispose(); ans_circles.Dispose(); pnts_index.Dispose(); } } } } |
Visual Basic | Copy |
---|---|
' $Revision: 1.1 $ Imports System.Collections.Generic Imports System.Text Imports System.Runtime.InteropServices Imports fvalgcli Public Partial Class FIE ''' <summary> ''' ハフ変換投票によって点列から円を検出する. ''' </summary> <FvPluginExecute> _ Public Sub fnFIE_hough_circles_detect() Dim status As Integer = CInt(f_err.F_ERR_NONE) Dim hHough As FHANDLE = FHANDLE.Zero Dim himg As FHANDLE = FHANDLE.Zero Dim edges As F_DEDGE_PTR = IntPtr.Zero Dim edges2 As DEDGE_T_PTR = IntPtr.Zero Dim ans_circles As HCD_CIRCLE_T_PTR = IntPtr.Zero Dim pnts_index As INT_PTR = IntPtr.Zero Try ' ハフオープン. Dim stq As Integer = 0 Dim edq As Integer = 359 Dim sx As Integer = 0 Dim sy As Integer = 0 Dim ex As Integer = 319 Dim ey As Integer = 239 Dim exerr As Integer = 0 hHough = fnFIE_hough_lines_open(stq, edq, sx, sy, ex, ey, _ exerr) ' 初期化. fnFIE_hough_lines_init_space(hHough) ' 投票空間の取得. fnFIE_hough_lines_get_space(hHough) ' エッジを検出する. api.fnFIE_load_img_file(TestImageDir & "/TC/SampleCode/floppy_UC8.jpg", himg, f_color_img_type.F_COLOR_IMG_TYPE_UC8) Dim param As New F_EDGE_SOBEL_PARAMS() param.mag_threshold = 120 param.nms_length = 3 Dim offset As New DPNT_T() Dim edge_num As Integer = 0 status = api.fnFIE_edge_sobel_subpix(himg, FHANDLE.Zero, param, f_edge_feature_mode.F_EDGE_FEAT_DIRECT, f_border_mode.F_BORDER_NONE, offset, _ edges, edge_num) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_edge_sobel_subpixel: エラーが発生しました。({0})", CType(status, f_err)) ' DEDGE_T <=変換= F_DEDGE edges2 = DEDGE_T_PTR.alloc(edge_num) For i As Integer = 0 To edge_num - 1 edges2(i) = DEDGE_T.init(edges(i).x, edges(i).y, edges(i).q) Next ' 検出. Dim dRmin As Double = 3.0 Dim dRmax As Double = 50.0 Dim dRsl As Double = 1.0 Dim bRefine As Boolean = True Dim iQRange As Integer = 10 Dim iEdgePercent As Integer = 10 Dim iMinScore As Integer = 15 Dim iMergeXY As Integer = 2 Dim iMergeR As Integer = 1 Dim iCircleColor As f_hough_objectcolor = f_hough_objectcolor.BLACK_COLOR Dim circle_num As Integer = 0 ' 入力点列と同じサイズの配列を確保. pnts_index = INT_PTR.alloc(edge_num) 'INT_PTR pi_pns_index = IntPtr.Zero; // 不要な場合は NULL (FHANDLE.Zero) を指定. status = api.fnFIE_hough_circles_detect(edges2, edge_num, dRmin, dRmax, dRsl, iQRange, _ iEdgePercent, iMinScore, iCircleColor, bRefine, iMergeXY, iMergeR, _ ans_circles, circle_num, pnts_index) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_hough_lines_detection: エラーが発生しました。({0})", CType(status, f_err)) Console.WriteLine("fnFIE_hough_circles_detect") Console.WriteLine("circle_num={0}", circle_num) For i As Integer = 0 To circle_num - 1 Console.WriteLine("xc,yc={0},{1}, r={2}, score={3}", ans_circles(i).xc, ans_circles(i).yc, ans_circles(i).r, ans_circles(i).score) Next Console.WriteLine("pnts_index=") For i As Integer = 0 To edge_num - 1 Console.Write("{0,4:###0},", pnts_index(i)) If (i + 1) Mod 20 = 0 Then Console.WriteLine("") End If Next Console.WriteLine("") Finally hHough.Dispose() himg.Dispose() edges.Dispose() edges2.Dispose() ans_circles.Dispose() pnts_index.Dispose() End Try End Sub End Class |