Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="objectKeypoints"></param>
        /// <param name="objectDescriptors"></param>
        /// <param name="imageKeypoints"></param>
        /// <param name="imageDescriptors"></param>
        /// <returns></returns>
        private static int[] FindPairs(CvSeq <CvSURFPoint> objectKeypoints, CvSeq <float> objectDescriptors, CvSeq <CvSURFPoint> imageKeypoints, CvSeq <float> imageDescriptors)
        {
            CvSeqReader <float>       reader  = new CvSeqReader <float>();
            CvSeqReader <CvSURFPoint> kreader = new CvSeqReader <CvSURFPoint>();

            Cv.StartReadSeq(objectDescriptors, reader);
            Cv.StartReadSeq(objectKeypoints, kreader);

            List <int> ptpairs = new List <int>();

            for (int i = 0; i < objectDescriptors.Total; i++)
            {
                CvSURFPoint kp         = CvSURFPoint.FromPtr(kreader.Ptr);
                IntPtr      descriptor = reader.Ptr;
                Cv.NEXT_SEQ_ELEM(kreader.Seq.ElemSize, kreader);
                Cv.NEXT_SEQ_ELEM(reader.Seq.ElemSize, reader);
                int nearestNeighbor = NaiveNearestNeighbor(descriptor, kp.Laplacian, imageKeypoints, imageDescriptors);
                if (nearestNeighbor >= 0)
                {
                    ptpairs.Add(i);
                    ptpairs.Add(nearestNeighbor);
                }
            }
            return(ptpairs.ToArray());
        }
Пример #2
0
        /// <summary>
        /// 画像の外側輪郭線,または内側輪郭線を描画する
        /// </summary>
        /// <param name="img">輪郭を描画する元画像.輪郭はROIで切り取られる.</param>
        /// <param name="contour">最初の輪郭へのポインタ</param>
        /// <param name="externalColor">外側輪郭線の色</param>
        /// <param name="holeColor">内側輪郭線(穴)の色</param>
        /// <param name="maxLevel">描画される輪郭の最大レベル. 0にした場合,contourのみが描画される. 1にした場合,先頭の輪郭と,同レベルのすべての輪郭が描画される. 2にした場合,先頭の輪郭と同レベルのすべての輪郭と,先頭の輪郭の一つ下のレベルのすべての輪郭が描画される.以下同様.</param>
        /// <param name="thickness">描画される輪郭線の太さ. 負(例えば=Cv.FILLED)にした場合には,内部を塗りつぶす.</param>
        /// <param name="lineType">線の種類</param>
        /// <param name="offset">全ての座標を指定した値だけシフトする</param>
#else
        /// <summary>
        /// Draws contour outlines or interiors in the image
        /// </summary>
        /// <param name="img">Image where the contours are to be drawn. Like in any other drawing function, the contours are clipped with the ROI. </param>
        /// <param name="contour">Reference to the first contour. </param>
        /// <param name="externalColor">Color of the external contours. </param>
        /// <param name="holeColor">Color of internal contours (holes). </param>
        /// <param name="maxLevel">Maximal level for drawn contours. If 0, only contour is drawn. If 1, the contour and all contours after it on the same level are drawn. If 2, all contours after and all contours one level below the contours are drawn, etc. If the value is negative, the function does not draw the contours following after contour but draws child contours of contour up to abs(max_level)-1 level. </param>
        /// <param name="thickness">Thickness of lines the contours are drawn with. If it is negative (e.g. =CV_FILLED), the contour interiors are drawn. </param>
        /// <param name="lineType">Type of the contour segments.</param>
        /// <param name="offset">Shift all the point coordinates by the specified value. It is useful in case if the contours retrieved in some image ROI and then the ROI offset needs to be taken into account during the rendering. </param>
#endif
        public static void DrawContours(CvArr img, CvSeq<CvPoint> contour, CvScalar externalColor, CvScalar holeColor, int maxLevel, int thickness, LineType lineType, CvPoint offset)
        {
            if (img == null)
                throw new ArgumentNullException("img");
            if (contour == null)
                throw new ArgumentNullException("contour");
            NativeMethods.cvDrawContours(img.CvPtr, contour.CvPtr, externalColor, holeColor, maxLevel, thickness, lineType, offset);
        }
Пример #3
0
        /// <summary>
        /// シーケンスへのデータ書き込み処理を初期化する (cvStartAppendToSeq).
        /// </summary>
        /// <param name="seq">シーケンスのポインタ</param>
        /// <returns>ライタ(Writer)の状態.この関数で初期化される.</returns>
#else
        /// <summary>
        /// Initializes process of writing data to sequence (cvStartAppendToSeq).
        /// </summary>
        /// <param name="seq">Pointer to the sequence. </param>
        /// <returns>Writer state; initialized by the function. </returns>
#endif
        public CvSeqWriter(CvSeq seq)
            : this()
        {
            if (seq == null)
            {
                throw new ArgumentNullException(nameof(seq));
            }
            NativeMethods.cvStartAppendToSeq(seq.CvPtr, ptr);
        }
Пример #4
0
        /// <summary>
        /// 配列からインスタンスを生成する
        /// </summary>
        /// <param name="array">IEnumerableインタフェースを実装するオブジェクト。ArrayやList&lt;t&gt;など。</param>
        /// <param name="seqFlags">生成されたシーケンスのフラグ</param>
        /// <param name="storage">シーケンスが保存される場所</param>
        /// <returns>CvSeq&lt;t&gt;</returns>
#else
        /// <summary>
        /// Creates CvSeq&lt;t&gt; from an IEnumerable&lt;t&gt; instance (ex. Array, List&lt;t&gt;)
        /// </summary>
        /// <param name="array">IEnumerable&lt;t&gt; instance</param>
        /// <param name="seqFlags">Flags of the created sequence</param>
        /// <param name="storage">Sequence location</param>
        /// <returns>CvSeq&lt;t&gt;</returns>
#endif
        public static CvSeq <T> FromArray(IEnumerable <T> array, SeqType seqFlags, CvMemStorage storage)
        {
            CvSeq <T> seq = new CvSeq <T>(seqFlags, storage);

            foreach (var item in array)
            {
                Cv.SeqPush(seq, item);
            }
            return(seq);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="vec">Cではconst float*</param>
        /// <param name="laplacian"></param>
        /// <param name="model_keypoints"></param>
        /// <param name="model_descriptors"></param>
        /// <returns></returns>
        private static int NaiveNearestNeighbor(IntPtr vec, int laplacian, CvSeq <CvSURFPoint> model_keypoints, CvSeq <float> model_descriptors)
        {
            int    length = (int)(model_descriptors.ElemSize / sizeof(float));
            int    neighbor = -1;
            double dist1 = 1e6, dist2 = 1e6;
            CvSeqReader <float>       reader = new CvSeqReader <float>();
            CvSeqReader <CvSURFPoint> kreader = new CvSeqReader <CvSURFPoint>();

            Cv.StartReadSeq(model_keypoints, kreader, false);
            Cv.StartReadSeq(model_descriptors, reader, false);

            IntPtr      mvec;
            CvSURFPoint kp;
            double      d;

            for (int i = 0; i < model_descriptors.Total; i++)
            {
                // const CvSURFPoint* kp = (const CvSURFPoint*)kreader.ptr; が結構曲者。
                // OpenCvSharpの構造体はFromPtrでポインタからインスタンス生成できるようにしてるので、こう書ける。
                kp = CvSURFPoint.FromPtr(kreader.Ptr);
                // まともにキャストする場合はこんな感じか
                // CvSURFPoint kp = (CvSURFPoint)Marshal.PtrToStructure(kreader.Ptr, typeof(CvSURFPoint));

                mvec = reader.Ptr;
                Cv.NEXT_SEQ_ELEM(kreader.Seq.ElemSize, kreader);
                Cv.NEXT_SEQ_ELEM(reader.Seq.ElemSize, reader);
                if (laplacian != kp.Laplacian)
                {
                    continue;
                }
                d = CompareSurfDescriptors(vec, mvec, dist2, length);
                if (d < dist1)
                {
                    dist2    = dist1;
                    dist1    = d;
                    neighbor = i;
                }
                else if (d < dist2)
                {
                    dist2 = d;
                }
            }
            if (dist1 < 0.6 * dist2)
            {
                return(neighbor);
            }
            else
            {
                return(-1);
            }
        }
Пример #6
0
        /// <summary>
        /// ハフ(Hough)変換で、method=CV_HOUGH_PROBABILISTICを用いて2値画像から直線を検出する
        /// </summary>
        /// <param name="rho">距離解像度(1ピクセル当たりの単位)</param>
        /// <param name="theta">角度解像度(ラジアン単位で計測)</param>
        /// <param name="threshold">閾値パラメータ.対応する投票数がthresholdより大きい場合のみ,抽出された線が返される.</param>
        /// <param name="param1">各手法に応じた1番目のパラメータ.標準的ハフ変換では,使用しない(0).確率的ハフ変換では,最小の線の長さ.マルチスケールハフ変換では, 距離解像度rhoの除数.(荒い距離解像度では rho であり,詳細な解像度では (rho / param1) となる).</param>
        /// <param name="param2">各手法に応じた2番目のパラメータ.標準的ハフ変換では,使用しない(0).確率的ハフ変換では,同一線上に存在する線分として扱う(つまり,それらを統合しても問題ない),二つの線分の最大の間隔. マルチスケールハフ変換では,角度解像度 thetaの除数. (荒い角度解像度では theta であり,詳細な解像度では (theta / param2) となる). </param>
        /// <returns>検出した直線を両端の点で表した形式、の配列</returns>
#else
        /// <summary>
        /// Finds lines in binary image using Hough transform.
        /// </summary>
        /// <param name="rho">Distance resolution in pixel-related units. </param>
        /// <param name="theta">Angle resolution measured in radians. </param>
        /// <param name="threshold">Threshold parameter. A line is returned by the function if the corresponding accumulator value is greater than threshold. </param>
        /// <param name="param1">The first method-dependent parameter.</param>
        /// <param name="param2">The second method-dependent parameter.</param>
        /// <returns></returns>
#endif
        public CvLineSegmentPoint[] HoughLinesProbabilistic(double rho, double theta, int threshold, double param1, double param2)
        {
            using (CvMemStorage lineStorage = new CvMemStorage())
            {
                IntPtr result = NativeMethods.cvHoughLines2(CvPtr, lineStorage.CvPtr, HoughLinesMethod.Probabilistic, rho, theta, threshold, param1, param2);
                if (result == IntPtr.Zero)
                {
                    throw new OpenCvSharpException();
                }

                CvSeq <CvLineSegmentPoint> seq = new CvSeq <CvLineSegmentPoint>(result);
                return(seq.ToArray());
            }
        }
Пример #7
0
        /// <summary>
        /// 指定した精度でポリラインを近似する
        /// </summary>
        /// <param name="srcSeq">点のシーケンスまたは配列</param>
        /// <param name="headerSize">近似されたポリラインのヘッダサイズ.</param>
        /// <param name="storage">近似された輪郭の保存場所.nullの場合,入力シーケンスのストレージが使われる. </param>
        /// <param name="method">近似方法</param>
        /// <param name="parameter">近似方法に依存するパラメータ.CV_POLY_APPROX_DPの場合には,要求する近似精度である.</param>
        /// <param name="parameter2">src_seqが点の配列(CvMat)の場合, このパラメータは輪郭が閉じている(parameter2=true)か,開いているか(parameter2=false)を指定する.</param>
        /// <returns>単一もしくは複数の近似曲線を計算した結果</returns>
#else
        /// <summary>
        /// Approximates polygonal curve(s) with desired precision.
        /// </summary>
        /// <param name="srcSeq">Sequence of array of points. </param>
        /// <param name="headerSize">Header size of approximated curve[s]. </param>
        /// <param name="storage">Container for approximated contours. If it is null, the input sequences' storage is used. </param>
        /// <param name="method">Approximation method; only ApproxPolyMethod.DP is supported, that corresponds to Douglas-Peucker algorithm. </param>
        /// <param name="parameter">Method-specific parameter; in case of CV_POLY_APPROX_DP it is a desired approximation accuracy. </param>
        /// <param name="parameter2">If case if src_seq is sequence it means whether the single sequence should be approximated
        /// or all sequences on the same level or below src_seq (see cvFindContours for description of hierarchical contour structures).
        /// And if src_seq is array (CvMat*) of points, the parameter specifies whether the curve is closed (parameter2==true) or not (parameter2==false). </param>
        /// <returns></returns>
#endif
        public static CvSeq <CvPoint> ApproxPoly(CvSeq <CvPoint> srcSeq, int headerSize, CvMemStorage storage, ApproxPolyMethod method, double parameter, bool parameter2)
        {
            if (srcSeq == null)
            {
                throw new ArgumentNullException("srcSeq");
            }
            IntPtr storagePtr = (storage == null) ? IntPtr.Zero : storage.CvPtr;
            IntPtr result     = NativeMethods.cvApproxPoly(srcSeq.CvPtr, headerSize, storagePtr, method, parameter, parameter2);

            if (result == IntPtr.Zero)
            {
                return(null);
            }
            return(new CvSeq <CvPoint>(result));
        }
Пример #8
0
 /// <summary>
 /// Returns an enumerator that iterates through the collection.
 /// </summary>
 /// <returns> A System.Collections.Generic.IEnumerator&lt;T&gt; that can be used to iterate through the collection.</returns>
 public IEnumerator <CvSeq <CvPoint> > GetEnumerator()
 {
     Initialize();
     while (true)
     {
         CvSeq <CvPoint> c = Cv.FindNextContour(this);
         if (c == null)
         {
             break;
         }
         else
         {
             yield return(c);
         }
     }
     Cv.EndFindContours(this);
 }
Пример #9
0
        /// <summary>
        /// a rough implementation for object location
        /// </summary>
        /// <param name="objectKeypoints"></param>
        /// <param name="objectDescriptors"></param>
        /// <param name="imageKeypoints"></param>
        /// <param name="imageDescriptors"></param>
        /// <param name="srcCorners"></param>
        /// <returns></returns>
        private static CvPoint[] LocatePlanarObject(CvSeq <CvSURFPoint> objectKeypoints, CvSeq <float> objectDescriptors,
                                                    CvSeq <CvSURFPoint> imageKeypoints, CvSeq <float> imageDescriptors,
                                                    CvPoint[] srcCorners)
        {
            CvMat h = new CvMat(3, 3, MatrixType.F64C1);

            int[] ptpairs = FindPairs(objectKeypoints, objectDescriptors, imageKeypoints, imageDescriptors);
            int   n       = ptpairs.Length / 2;

            if (n < 4)
            {
                return(null);
            }

            CvPoint2D32f[] pt1 = new CvPoint2D32f[n];
            CvPoint2D32f[] pt2 = new CvPoint2D32f[n];
            for (int i = 0; i < n; i++)
            {
                pt1[i] = (Cv.GetSeqElem <CvSURFPoint>(objectKeypoints, ptpairs[i * 2])).Value.Pt;
                pt2[i] = (Cv.GetSeqElem <CvSURFPoint>(imageKeypoints, ptpairs[i * 2 + 1])).Value.Pt;
            }

            CvMat pt1Mat = new CvMat(1, n, MatrixType.F32C2, pt1);
            CvMat pt2Mat = new CvMat(1, n, MatrixType.F32C2, pt2);

            if (Cv.FindHomography(pt1Mat, pt2Mat, h, HomographyMethod.Ransac, 5) == 0)
            {
                return(null);
            }

            CvPoint[] dstCorners = new CvPoint[4];
            for (int i = 0; i < 4; i++)
            {
                double x = srcCorners[i].X;
                double y = srcCorners[i].Y;
                double Z = 1.0 / (h[6] * x + h[7] * y + h[8]);
                double X = (h[0] * x + h[1] * y + h[2]) * Z;
                double Y = (h[3] * x + h[4] * y + h[5]) * Z;
                dstCorners[i] = new CvPoint(Cv.Round(X), Cv.Round(Y));
            }

            return(dstCorners);
        }
Пример #10
0
        /// <summary>
        /// 指定した精度でポリラインを近似する
        /// </summary>
        /// <param name="srcSeq">点のシーケンスまたは配列</param>
        /// <param name="headerSize">近似されたポリラインのヘッダサイズ.</param>
        /// <param name="storage">近似された輪郭の保存場所.nullの場合,入力シーケンスのストレージが使われる. </param>
        /// <param name="method">近似方法</param>
        /// <param name="parameter">近似方法に依存するパラメータ.CV_POLY_APPROX_DPの場合には,要求する近似精度である.</param>
        /// <param name="parameter2">src_seqが点の配列(CvMat)の場合, このパラメータは輪郭が閉じている(parameter2=true)か,開いているか(parameter2=false)を指定する.</param>
        /// <returns>単一もしくは複数の近似曲線を計算した結果</returns>
#else
        /// <summary>
        /// Approximates polygonal curve(s) with desired precision.
        /// </summary>
        /// <param name="srcSeq">Sequence of array of points. </param>
        /// <param name="headerSize">Header size of approximated curve[s]. </param>
        /// <param name="storage">Container for approximated contours. If it is null, the input sequences' storage is used. </param>
        /// <param name="method">Approximation method; only ApproxPolyMethod.DP is supported, that corresponds to Douglas-Peucker algorithm. </param>
        /// <param name="parameter">Method-specific parameter; in case of CV_POLY_APPROX_DP it is a desired approximation accuracy. </param>
        /// <param name="parameter2">If case if src_seq is sequence it means whether the single sequence should be approximated
        /// or all sequences on the same level or below src_seq (see cvFindContours for description of hierarchical contour structures).
        /// And if src_seq is array (CvMat*) of points, the parameter specifies whether the curve is closed (parameter2==true) or not (parameter2==false). </param>
        /// <returns></returns>
#endif
        public static CvSeq <CvPoint> ApproxPoly(CvSeq <CvPoint> srcSeq, int headerSize, CvMemStorage storage, ApproxPolyMethod method, double parameter, bool parameter2)
        {
            if (srcSeq == null)
            {
                throw new ArgumentNullException(nameof(srcSeq));
            }

            IntPtr result = NativeMethods.cvApproxPoly(srcSeq.CvPtr, headerSize, ToPtr(storage), method, parameter, parameter2);

            if (result == IntPtr.Zero)
            {
                return(null);
            }

            GC.KeepAlive(srcSeq);
            GC.KeepAlive(storage);

            return(new CvSeq <CvPoint>(result));
        }
Пример #11
0
        /// <summary>
        /// 2次元点列を包含するまっすぐな矩形を返す.
        /// </summary>
        /// <param name="points">CvPointの列挙子(CvPoint[], List&lt;CvPoint&gt;など). 内部でCvSeqに変換される.</param>
        /// <returns>矩形</returns>
#else
        /// <summary>
        /// Calculates up-right bounding rectangle of point set.
        /// </summary>
        /// <param name="points">An IEnumerable&lt;CvPoint&gt; object (ex. CvPoint[], List&lt;CvPoint&gt;, ....)</param>
        /// <returns></returns>
#endif
        public static CvRect BoundingRect(IEnumerable <CvPoint> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            CvRect result;

            using (CvMemStorage storage = new CvMemStorage(0))
            {
                CvSeq <CvPoint> seq = new CvSeq <CvPoint>(SeqType.EltypePoint, CvSeq.SizeOf, storage);
                foreach (CvPoint p in points)
                {
                    SeqPush(seq, p);
                }
                result = NativeMethods.cvBoundingRect(seq.CvPtr, false);
            }

            return(result);
        }
Пример #12
0
        /// <summary>
        /// フリーマンチェーン(Freeman chain)をポリラインで近似する
        /// </summary>
        /// <param name="srcSeq">他のチェーンから参照可能なチェーンへの参照.</param>
        /// <param name="storage">計算結果保存用のストレージ.</param>
        /// <param name="method">推定手法.</param>
        /// <param name="parameter">メソッドパラメータ(現在は使われていない).</param>
        /// <param name="minimalPerimeter">minimal_perimeter以上の周囲長をもつ輪郭のみを計算する.その他のチェーンは結果の構造体から削除される.</param>
        /// <param name="recursive">trueの場合,src_seqからh_nextあるいはv_nextによって辿ることができる全てのチェーンを近似する.falseの場合,単一のチェーンを近似する. </param>
        /// <returns></returns>
#else
        /// <summary>
        /// Approximates Freeman chain(s) with polygonal curve
        /// </summary>
        /// <param name="srcSeq">Freeman chain(s) </param>
        /// <param name="storage">Storage location for the resulting polylines. </param>
        /// <param name="method">Approximation method.</param>
        /// <param name="parameter">Method parameter (not used now). </param>
        /// <param name="minimalPerimeter">Approximates only those contours whose perimeters are not less than minimal_perimeter. Other chains are removed from the resulting structure. </param>
        /// <param name="recursive">If true, the function approximates all chains that access can be obtained to from src_seq by h_next or v_next links. If false, the single chain is approximated. </param>
        /// <returns></returns>
#endif
        public static CvSeq <CvPoint> ApproxChains(CvChain srcSeq, CvMemStorage storage, ContourChain method, double parameter, int minimalPerimeter, bool recursive)
        {
            if (srcSeq == null)
            {
                throw new ArgumentNullException("srcSeq");
            }
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }
            IntPtr resultPtr = NativeMethods.cvApproxChains(srcSeq.CvPtr, storage.CvPtr, method, parameter, minimalPerimeter, recursive);

            if (resultPtr == IntPtr.Zero)
            {
                return(null);
            }

            CvSeq <CvPoint> result = new CvSeq <CvPoint>(resultPtr);

            return(result);
        }
Пример #13
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IEnumerator <CvPoint> GetEnumerator()
        {
            if (chain == null)
            {
                throw new NotSupportedException();
            }
            Cv.StartReadChainPoints(chain, this);

            CvSeq seq = Seq;

            if (seq == null)
            {
                throw new OpenCvSharpException();
            }

            int total = seq.Total;

            for (int i = 0; i < total; i++)
            {
                yield return(Cv.ReadChainPoint(this));
            }
        }
Пример #14
0
 /// <summary>
 /// CvSeq -> CvSeq&lt;t&gt;
 /// </summary>
 /// <param name="seq"></param>
 public CvSeq(CvSeq seq)
     : base(seq.CvPtr)
 {
 }
Пример #15
0
        /// <summary>
        /// データシーケンスを同値類(同じクラスに属すると定義されたデータ群)に分割する
        /// </summary>
        /// <param name="storage">同値類として分割されたシーケンスの保存領域.nullの場合は,seq->storage を使用する.</param>
        /// <param name="labels">出力パラメータ.入力シーケンスの各要素に割り振られた(分割結果を表す)0から始まるラベルシーケンスへのポインタのポインタ.</param>
        /// <param name="isEqual">2つのシーケンス要素が同じクラスである場合,関係関数は 0以外を返す. そうでなければ0を返す.分割アルゴリズムは,同値基準として関係関数の推移閉包を用いる.</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Splits sequence into equivalence classes
        /// </summary>
        /// <param name="storage">The storage to store the sequence of equivalence classes. If it is null, the function uses seq->storage for output labels. </param>
        /// <param name="labels">Output parameter. Double pointer to the sequence of 0-based labels of input sequence elements. </param>
        /// <param name="isEqual">The relation function that should return non-zero if the two particular sequence elements are from the same class, and zero otherwise. The partitioning algorithm uses transitive closure of the relation function as equivalence criteria. </param>
        /// <returns></returns>
#endif
        public int Partition(CvMemStorage storage, out CvSeq labels, CvCmpFunc <T> isEqual)
        {
            return(Cv.SeqPartition(this, storage, out labels, isEqual));
        }
Пример #16
0
        /// <summary>
        /// シーケンスのスライス長を計算する
        /// </summary>
        /// <param name="seq"></param>
        /// <returns></returns>
#else
        /// <summary>
        /// Calculates the sequence slice length
        /// </summary>
        /// <param name="seq">Sequence</param>
        /// <returns></returns>
#endif
        public int SliceLength(CvSeq seq)
        {
            return(Cv.SliceLength(this, seq));
        }
Пример #17
0
        /// <summary>
        /// 画像の外側輪郭線,または内側輪郭線を描画する
        /// </summary>
        /// <param name="img">輪郭を描画する元画像.輪郭はROIで切り取られる.</param>
        /// <param name="contour">最初の輪郭へのポインタ</param>
        /// <param name="externalColor">外側輪郭線の色</param>
        /// <param name="holeColor">内側輪郭線(穴)の色</param>
        /// <param name="maxLevel">描画される輪郭の最大レベル. 0にした場合,contourのみが描画される. 1にした場合,先頭の輪郭と,同レベルのすべての輪郭が描画される. 2にした場合,先頭の輪郭と同レベルのすべての輪郭と,先頭の輪郭の一つ下のレベルのすべての輪郭が描画される.以下同様.</param>
        /// <param name="thickness">描画される輪郭線の太さ. 負(例えば=Cv.FILLED)にした場合には,内部を塗りつぶす.</param>
        /// <param name="lineType">線の種類</param>
#else
        /// <summary>
        /// Draws contour outlines or interiors in the image
        /// </summary>
        /// <param name="img">Image where the contours are to be drawn. Like in any other drawing function, the contours are clipped with the ROI. </param>
        /// <param name="contour">Reference to the first contour. </param>
        /// <param name="externalColor">Color of the external contours. </param>
        /// <param name="holeColor">Color of internal contours (holes). </param>
        /// <param name="maxLevel">Maximal level for drawn contours. If 0, only contour is drawn. If 1, the contour and all contours after it on the same level are drawn. If 2, all contours after and all contours one level below the contours are drawn, etc. If the value is negative, the function does not draw the contours following after contour but draws child contours of contour up to abs(max_level)-1 level. </param>
        /// <param name="thickness">Thickness of lines the contours are drawn with. If it is negative (e.g. =CV_FILLED), the contour interiors are drawn. </param>
        /// <param name="lineType">Type of the contour segments.</param>
#endif
        public static void DrawContours(CvArr img, CvSeq <CvPoint> contour, CvScalar externalColor, CvScalar holeColor, int maxLevel, int thickness, LineType lineType)
        {
            DrawContours(img, contour, externalColor, holeColor, maxLevel, thickness, lineType, new CvPoint(0, 0));
        }
Пример #18
0
        /// <summary>
        /// 画像の外側輪郭線,または内側輪郭線を描画する
        /// </summary>
        /// <param name="img">輪郭を描画する元画像.輪郭はROIで切り取られる.</param>
        /// <param name="contour">最初の輪郭へのポインタ</param>
        /// <param name="externalColor">外側輪郭線の色</param>
        /// <param name="holeColor">内側輪郭線(穴)の色</param>
        /// <param name="maxLevel">描画される輪郭の最大レベル. 0にした場合,contourのみが描画される. 1にした場合,先頭の輪郭と,同レベルのすべての輪郭が描画される. 2にした場合,先頭の輪郭と同レベルのすべての輪郭と,先頭の輪郭の一つ下のレベルのすべての輪郭が描画される.以下同様.</param>
#else
        /// <summary>
        /// Draws contour outlines or interiors in the image
        /// </summary>
        /// <param name="img">Image where the contours are to be drawn. Like in any other drawing function, the contours are clipped with the ROI. </param>
        /// <param name="contour">Reference to the first contour. </param>
        /// <param name="externalColor">Color of the external contours. </param>
        /// <param name="holeColor">Color of internal contours (holes). </param>
        /// <param name="maxLevel">Maximal level for drawn contours. If 0, only contour is drawn. If 1, the contour and all contours after it on the same level are drawn. If 2, all contours after and all contours one level below the contours are drawn, etc. If the value is negative, the function does not draw the contours following after contour but draws child contours of contour up to abs(max_level)-1 level. </param>
#endif
        public static void DrawContours(CvArr img, CvSeq <CvPoint> contour, CvScalar externalColor, CvScalar holeColor, int maxLevel)
        {
            DrawContours(img, contour, externalColor, holeColor, maxLevel, 1, LineType.Link8, new CvPoint(0, 0));
        }
Пример #19
0
        /// <summary>
        /// 抽出された輪郭を置き換える
        /// </summary>
        /// <param name="newContour">新しく置き換える輪郭</param>
#else
        /// <summary>
        /// Replaces retrieved contour
        /// </summary>
        /// <param name="newContour">Substituting contour. </param>
#endif
        public void SubstituteContour(CvSeq <CvPoint> newContour)
        {
            Cv.SubstituteContour(this, newContour);
        }
Пример #20
0
 public void PyrSegmentation(IplImage dst, CvMemStorage storage, out CvSeq comp, int level, double threshold1,
                             double threshold2);
Пример #21
0
        /// <summary>
        /// 指定した精度でポリラインを近似する
        /// </summary>
        /// <param name="srcSeq">点のシーケンスまたは配列</param>
        /// <param name="headerSize">近似されたポリラインのヘッダサイズ.</param>
        /// <param name="storage">近似された輪郭の保存場所.nullの場合,入力シーケンスのストレージが使われる. </param>
        /// <param name="method">近似方法</param>
        /// <param name="parameter">近似方法に依存するパラメータ.CV_POLY_APPROX_DPの場合には,要求する近似精度である.</param>
        /// <returns>単一もしくは複数の近似曲線を計算した結果</returns>
#else
        /// <summary>
        /// Approximates polygonal curve(s) with desired precision.
        /// </summary>
        /// <param name="srcSeq">Sequence of array of points. </param>
        /// <param name="headerSize">Header size of approximated curve[s]. </param>
        /// <param name="storage">Container for approximated contours. If it is null, the input sequences' storage is used. </param>
        /// <param name="method">Approximation method; only ApproxPolyMethod.DP is supported, that corresponds to Douglas-Peucker algorithm. </param>
        /// <param name="parameter">Method-specific parameter; in case of CV_POLY_APPROX_DP it is a desired approximation accuracy. </param>
        /// <returns></returns>
#endif
        public static CvSeq <CvPoint> ApproxPoly(CvSeq <CvPoint> srcSeq, int headerSize, CvMemStorage storage, ApproxPolyMethod method, double parameter)
        {
            return(ApproxPoly(srcSeq, headerSize, storage, method, parameter, false));
        }
Пример #22
0
        /// <summary>
        /// 輪郭の階層的表現を生成する
        /// </summary>
        /// <param name="contour">入力輪郭</param>
        /// <param name="storage">結果のツリーの出力先</param>
        /// <param name="threshold">近似精度</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Creates hierarchical representation of contour
        /// </summary>
        /// <param name="contour">Input contour. </param>
        /// <param name="storage">Container for output tree. </param>
        /// <param name="threshold">Approximation accuracy. </param>
        /// <returns></returns>
#endif
        public CvContourTree(CvSeq contour, CvMemStorage storage, double threshold)
            : base(NativeMethods.cvCreateContourTree(contour.CvPtr, storage.CvPtr, threshold))
        {
        }
Пример #23
0
        /// <summary>
        /// シーケンスへのデータ書き込み処理を初期化する (cvStartAppendToSeq).
        /// </summary>
        /// <param name="seq">シーケンスのポインタ</param>
        /// <returns>ライタ(Writer)の状態.この関数で初期化される.</returns>
#else
        /// <summary>
        /// Initializes process of writing data to sequence (cvStartAppendToSeq).
        /// </summary>
        /// <param name="seq">Pointer to the sequence. </param>
        /// <returns>Writer state; initialized by the function. </returns>
#endif
        public CvSeqWriter(CvSeq seq)
            : base(seq)
        {
        }