ハフ直線検出
Namespace: fvalgcliAssembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)
Syntax
C# |
---|
public static int fnFIE_hough_lines_detection( FHANDLE hHough, int request_line_num, int rgn_r, int rgn_q, F_LH_LINE_PTR ans_lines, ref int line_num ) |
Visual Basic |
---|
Public Shared Function fnFIE_hough_lines_detection ( hHough As FHANDLE, request_line_num As Integer, rgn_r As Integer, rgn_q As Integer, ans_lines As F_LH_LINE_PTR, ByRef line_num As Integer ) As Integer |
Parameters
- hHough
- Type: fvalgcli..::..FHANDLE
ハフ構造体のハンドル
- request_line_num
- Type: System..::..Int32
検出要求数(1以上)
- rgn_r
- Type: System..::..Int32
ρ方向極大値決定サイズ(0以上, 単位:ピクセル)
- rgn_q
- Type: System..::..Int32
θ方向極大値決定サイズ(0〜179, 単位:度)
- ans_lines
- Type: fvalgcli..::..F_LH_LINE_PTR
検出結果直線( request_line_num 個以上のメモリが必要)
- line_num
- Type: System..::..Int32%
検出された直線の数
Return Value
Type: Int32以下のエラーコードを返します。
エラーコード:
f_err | 内容 |
---|---|
F_ERR_NONE | 正常終了 |
F_ERR_INVALID_OBJECT | 不正なハフオブジェクトが渡された |
F_ERR_INVALID_PARAM | 不正なパラメータが渡された |
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> /// <remarks> /// 検査対象関数 <br/> /// fnFIE_hough_lines_open <br/> /// fnFIE_hough_lines_init_space <br/> /// fnFIE_hough_lines_voting <br/> /// fnFIE_hough_lines_detection <br/> /// </remarks> [FvPluginExecute] public void fnFIE_hough_lines_detection() { int status = (int)f_err.F_ERR_NONE; FHANDLE hHough = FHANDLE.Zero; FHANDLE himg = FHANDLE.Zero; F_EDGE_PTR edges = IntPtr.Zero; F_EDGE_PTR support_edges = IntPtr.Zero; F_LH_LINE_PTR ans_lines = 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; PNT_T offset = new PNT_T(); int edge_num = 0; status = api.fnFIE_edge_sobel(himg, FHANDLE.Zero, ref param, f_edge_feature_mode.F_EDGE_FEAT_DIRECT, f_border_mode.F_BORDER_CONTINUOUS, offset, ref edges, ref edge_num); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_edge_sobel: エラーが発生しました。({0})", (f_err)status); // 投票. int vot_width = 10; int voting_num = 0; fnFIE_hough_lines_voting(hHough, edges, edge_num, vot_width, ref voting_num); // 検出. int request_line_num = 10; ans_lines = F_LH_LINE_PTR.alloc(request_line_num); int rgn_r = 10; int rgn_q = 10; int line_num = 0; status = api.fnFIE_hough_lines_detection(hHough, request_line_num, rgn_r, rgn_q, ans_lines, ref line_num); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_hough_lines_detection: エラーが発生しました。({0})", (f_err)status); Console.WriteLine("fnFIE_hough_lines_detection"); Console.WriteLine("line_num={0}", line_num); for (int i = 0; i < line_num; i++) { Console.WriteLine("a,b,c={0},{1},{2} q={3},score={4}", ans_lines[i].a, ans_lines[i].b, ans_lines[i].c, ans_lines[i].q, ans_lines[i].score); } // 直線係数の求め直し. F_LH_LINE ans_line = ans_lines[0]; int err_r = 10; int err_q = 10; int pnt_num = 0; fnFIE_hough_lines_refine_line(ref ans_line, edges, edge_num, err_r, err_q, ref pnt_num); ans_lines[0] = ans_line; // 直線に近いエッジ点群の取得. int neib_num = 0; int sort_type = 0; fnFIE_hough_lines_get_support_edges(ref ans_line, edges, edge_num, err_r, err_q, ref support_edges, ref neib_num, ref sort_type); } finally { hHough.Dispose(); himg.Dispose(); edges.Dispose(); support_edges.Dispose(); ans_lines.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> ''' <remarks> ''' 検査対象関数 <br/> ''' fnFIE_hough_lines_open <br/> ''' fnFIE_hough_lines_init_space <br/> ''' fnFIE_hough_lines_voting <br/> ''' fnFIE_hough_lines_detection <br/> ''' </remarks> <FvPluginExecute> _ Public Sub fnFIE_hough_lines_detection() 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_EDGE_PTR = IntPtr.Zero Dim support_edges As F_EDGE_PTR = IntPtr.Zero Dim ans_lines As F_LH_LINE_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 PNT_T() Dim edge_num As Integer = 0 status = api.fnFIE_edge_sobel(himg, FHANDLE.Zero, param, f_edge_feature_mode.F_EDGE_FEAT_DIRECT, f_border_mode.F_BORDER_CONTINUOUS, offset, _ edges, edge_num) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_edge_sobel: エラーが発生しました。({0})", CType(status, f_err)) ' 投票. Dim vot_width As Integer = 10 Dim voting_num As Integer = 0 fnFIE_hough_lines_voting(hHough, edges, edge_num, vot_width, voting_num) ' 検出. Dim request_line_num As Integer = 10 ans_lines = F_LH_LINE_PTR.alloc(request_line_num) Dim rgn_r As Integer = 10 Dim rgn_q As Integer = 10 Dim line_num As Integer = 0 status = api.fnFIE_hough_lines_detection(hHough, request_line_num, rgn_r, rgn_q, ans_lines, line_num) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_hough_lines_detection: エラーが発生しました。({0})", CType(status, f_err)) Console.WriteLine("fnFIE_hough_lines_detection") Console.WriteLine("line_num={0}", line_num) For i As Integer = 0 To line_num - 1 Console.WriteLine("a,b,c={0},{1},{2} q={3},score={4}", ans_lines(i).a, ans_lines(i).b, ans_lines(i).c, ans_lines(i).q, ans_lines(i).score) Next ' 直線係数の求め直し. Dim ans_line As F_LH_LINE = ans_lines(0) Dim err_r As Integer = 10 Dim err_q As Integer = 10 Dim pnt_num As Integer = 0 fnFIE_hough_lines_refine_line(ans_line, edges, edge_num, err_r, err_q, pnt_num) ans_lines(0) = ans_line ' 直線に近いエッジ点群の取得. Dim neib_num As Integer = 0 Dim sort_type As Integer = 0 fnFIE_hough_lines_get_support_edges(ans_line, edges, edge_num, err_r, err_q, support_edges, _ neib_num, sort_type) Finally hHough.Dispose() himg.Dispose() edges.Dispose() support_edges.Dispose() ans_lines.Dispose() End Try End Sub End Class |