| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using System.Runtime.InteropServices;
|
|---|
| 5 | using System.Text;
|
|---|
| 6 |
|
|---|
| 7 | namespace KwsmLab.OpenCvSharp
|
|---|
| 8 | {
|
|---|
| 9 | #if LANG_JP
|
|---|
| 10 | /// <summary>
|
|---|
| 11 | /// 単一決定木による分類器(最も単純な場合は stump).これは個々の画像
|
|---|
| 12 | /// 位置における特徴に対する応答(つまりウィンドウ内の部分矩形におけるピクセル合計値)
|
|---|
| 13 | /// を返し,その応答に依存する値を出力する
|
|---|
| 14 | /// </summary>
|
|---|
| 15 | #else
|
|---|
| 16 | /// <summary>
|
|---|
| 17 | /// a single tree classifier (stump in the simplest case) that returns the response for the feature
|
|---|
| 18 | /// at the particular image location (i.e. pixel sum over subrectangles of the window) and gives out
|
|---|
| 19 | /// a value depending on the responce
|
|---|
| 20 | /// </summary>
|
|---|
| 21 | #endif
|
|---|
| 22 | public class CvHaarClassifier : CvObject
|
|---|
| 23 | {
|
|---|
| 24 | /// <summary>
|
|---|
| 25 | /// C++/CLI wrapper of data pointer
|
|---|
| 26 | /// </summary>
|
|---|
| 27 | private Extern.WCvHaarClassifier _data;
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | #region Init and Disposal
|
|---|
| 31 | #if LANG_JP
|
|---|
| 32 | /// <summary>
|
|---|
| 33 | /// ポインタで初期化
|
|---|
| 34 | /// </summary>
|
|---|
| 35 | /// <param name="ptr">struct CvHaarClassifier*</param>
|
|---|
| 36 | #else
|
|---|
| 37 | /// <summary>
|
|---|
| 38 | /// Initializes from native pointer
|
|---|
| 39 | /// </summary>
|
|---|
| 40 | /// <param name="ptr">struct CvHaarClassifier*</param>
|
|---|
| 41 | #endif
|
|---|
| 42 | public CvHaarClassifier(IntPtr ptr)
|
|---|
| 43 | {
|
|---|
| 44 | if (ptr == IntPtr.Zero)
|
|---|
| 45 | {
|
|---|
| 46 | throw new ArgumentNullException("ptr");
|
|---|
| 47 | }
|
|---|
| 48 | this._ptr = ptr;
|
|---|
| 49 | this._data = new Extern.WCvHaarClassifier(ptr);
|
|---|
| 50 | }
|
|---|
| 51 | #endregion
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | #region Properties
|
|---|
| 55 | /// <summary>
|
|---|
| 56 | /// sizeof(CvHaarClassifier)
|
|---|
| 57 | /// </summary>
|
|---|
| 58 | public const Int32 SizeOf = Extern.WCvHaarClassifier.SizeOf;
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | #if LANG_JP
|
|---|
| 62 | /// <summary>
|
|---|
| 63 | /// 決定木のノード数
|
|---|
| 64 | /// </summary>
|
|---|
| 65 | #else
|
|---|
| 66 | /// <summary>
|
|---|
| 67 | /// Number of nodes in the decision tree
|
|---|
| 68 | /// </summary>
|
|---|
| 69 | #endif
|
|---|
| 70 | public int Count
|
|---|
| 71 | {
|
|---|
| 72 | get { return _data.count; }
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | #if LANG_JP
|
|---|
| 76 | /// <summary>
|
|---|
| 77 | /// haar特徴の配列
|
|---|
| 78 | /// </summary>
|
|---|
| 79 | #else
|
|---|
| 80 | /// <summary>
|
|---|
| 81 | /// Array of haar features
|
|---|
| 82 | /// </summary>
|
|---|
| 83 | #endif
|
|---|
| 84 | public CvHaarFeature[] HaarFeature
|
|---|
| 85 | {
|
|---|
| 86 | get
|
|---|
| 87 | {
|
|---|
| 88 | int length = _data.count;
|
|---|
| 89 | CvHaarFeature[] result = new CvHaarFeature[length];
|
|---|
| 90 | for (int i = 0; i < length; i++)
|
|---|
| 91 | {
|
|---|
| 92 | result[i] = new CvHaarFeature(_data.haar_feature_at(i));
|
|---|
| 93 | }
|
|---|
| 94 | return result;
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | #if LANG_JP
|
|---|
| 99 | /// <summary>
|
|---|
| 100 | /// 枝の閾値.特徴応答 <= threshold となる場合は左側の枝が選択され,そうでない場合は右の枝が選択される.
|
|---|
| 101 | /// </summary>
|
|---|
| 102 | #else
|
|---|
| 103 | /// <summary>
|
|---|
| 104 | /// branch threshold. if feature responce is <= threshold, left branch is chosen, otherwise right branch is chosed.
|
|---|
| 105 | /// </summary>
|
|---|
| 106 | #endif
|
|---|
| 107 | public PointerAccessor.Single Threshold
|
|---|
| 108 | {
|
|---|
| 109 | get { unsafe { return new PointerAccessor.Single(_data.threshold); } }
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | #if LANG_JP
|
|---|
| 113 | /// <summary>
|
|---|
| 114 | /// 左側の子のインデックス(左側の子が葉だった場合には負のインデックス)
|
|---|
| 115 | /// </summary>
|
|---|
| 116 | #else
|
|---|
| 117 | /// <summary>
|
|---|
| 118 | /// index of the left child (or negated index if the left child is a leaf)
|
|---|
| 119 | /// </summary>
|
|---|
| 120 | #endif
|
|---|
| 121 | public PointerAccessor.Int32 Left
|
|---|
| 122 | {
|
|---|
| 123 | get { unsafe { return new PointerAccessor.Int32(_data.left); } }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | #if LANG_JP
|
|---|
| 127 | /// <summary>
|
|---|
| 128 | /// 右側の子のインデックス(右側の子が葉だった場合には負のインデックス)
|
|---|
| 129 | /// </summary>
|
|---|
| 130 | #else
|
|---|
| 131 | /// <summary>
|
|---|
| 132 | /// index of the right child (or negated index if the right child is a leaf)
|
|---|
| 133 | /// </summary>
|
|---|
| 134 | #endif
|
|---|
| 135 | public PointerAccessor.Int32 Right
|
|---|
| 136 | {
|
|---|
| 137 | get { unsafe { return new PointerAccessor.Int32(_data.right); } }
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | #if LANG_JP
|
|---|
| 141 | /// <summary>
|
|---|
| 142 | /// 葉に対応する出力値
|
|---|
| 143 | /// </summary>
|
|---|
| 144 | #else
|
|---|
| 145 | /// <summary>
|
|---|
| 146 | /// output value correponding to the leaf.
|
|---|
| 147 | /// </summary>
|
|---|
| 148 | #endif
|
|---|
| 149 | public PointerAccessor.Single Alpha
|
|---|
| 150 | {
|
|---|
| 151 | get { unsafe { return new PointerAccessor.Single(_data.alpha); } }
|
|---|
| 152 | }
|
|---|
| 153 | #endregion
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|