/// <summary> /// MSERのすべての輪郭情報を抽出する /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <param name="contours"></param> /// <param name="storage"></param> /// <param name="params"></param> #else /// <summary> /// Extracts the contours of Maximally Stable Extremal Regions /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <param name="contours"></param> /// <param name="storage"></param> /// <param name="params"></param> #endif public static void ExtractMSER(CvArr img, CvArr mask, out CvContour[] contours, CvMemStorage storage, CvMSERParams @params) { if (img == null) throw new ArgumentNullException("img"); if (storage == null) throw new ArgumentNullException("storage"); IntPtr maskPtr = (mask == null) ? IntPtr.Zero : mask.CvPtr; IntPtr contoursPtr = IntPtr.Zero; CvInvoke.cvExtractMSER(img.CvPtr, maskPtr, ref contoursPtr, storage.CvPtr, @params.Struct); CvSeq<IntPtr> seq = new CvSeq<IntPtr>(contoursPtr); contours = Array.ConvertAll<IntPtr, CvContour>(seq.ToArray(), delegate(IntPtr p) { return new CvContour(p); }); }
/// <summary> /// 2値画像中の輪郭を見つける /// </summary> /// <param name="image">入力画像(8ビットシングルチャンネル).値が0以外のピクセルは「1」,0のピクセルは「0」とする.</param> /// <param name="storage">抽出された輪郭を保存する領域</param> /// <param name="firstContour">出力パラメータ.一番外側の輪郭へのポインタが入っている.</param> /// <param name="headerSize">シーケンスヘッダのサイズ.method=CV_CHAIN_CODEの場合,>=sizeof(CvChain) ,それ以外の場合 >=sizeof(CvContour).</param> /// <param name="mode">抽出モード </param> /// <param name="method">近似手法</param> /// <param name="offset">オフセット.全ての輪郭点はこれによってシフトされる.</param> /// <returns>抽出した輪郭の個数</returns> #else /// <summary> /// Retrieves contours from the binary image and returns the number of retrieved contours. /// </summary> /// <param name="image">The source 8-bit single channel image. Non-zero pixels are treated as 1’s, zero pixels remain 0’s - that is image treated as binary. /// To get such a binary image from grayscale, one may use cvThreshold, cvAdaptiveThreshold or cvCanny. The function modifies the source image content. </param> /// <param name="storage">Container of the retrieved contours. </param> /// <param name="firstContour">Output parameter, will contain the pointer to the first outer contour. </param> /// <param name="headerSize">Size of the sequence header, >=sizeof(CvChain) if method=CV_CHAIN_CODE, and >=sizeof(CvContour) otherwise. </param> /// <param name="mode">Retrieval mode. </param> /// <param name="method">Approximation method. </param> /// <param name="offset">Offset, by which every contour point is shifted. This is useful if the contours are extracted from the image ROI and then they should be analyzed in the whole image context. </param> /// <returns>The number of retrieved contours.</returns> #endif public static int FindContours(CvArr image, CvMemStorage storage, out CvSeq<CvPoint> firstContour, int headerSize, ContourRetrieval mode, ContourChain method, CvPoint offset) { if (image == null) throw new ArgumentNullException("image"); if (storage == null) throw new ArgumentNullException("storage"); IntPtr firstContourPtr = IntPtr.Zero; int result = NativeMethods.cvFindContours(image.CvPtr, storage.CvPtr, ref firstContourPtr, headerSize, mode, method, offset); if (firstContourPtr == IntPtr.Zero) firstContour = null; else if (method == ContourChain.Code) firstContour = new CvChain(firstContourPtr); else firstContour = new CvContour(firstContourPtr); return result; }