root/lang/cpluspluscli/OpenCvSharp2/trunk/OpenCvSharp.Test/Samples/ContourScanner.cs @ 32042

Revision 32042, 2.1 kB (checked in by schima, 4 years ago)

added comments in English (CvColor?, BitDepth?, LoadMode?)

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace KwsmLab.OpenCvSharp.Test
7{
8    /// <summary>
9    /// CvContourScanner Sample
10    /// </summary>
11    class ContourScanner
12    {
13        public ContourScanner()
14        {
15            // create IplImages
16            using (IplImage src = new IplImage(Const.IMAGE_LENNA, LoadMode.Color))
17            using (IplImage gray = new IplImage(src.Size, BitDepth.U8, 1))
18            using (IplImage canny = new IplImage(src.Size, BitDepth.U8, 1))
19            using (IplImage result = src.Clone())
20            {
21                // detect edges
22                Cv.CvtColor(src, gray, ColorConversion.BgrToGray);
23                Cv.Canny(gray, canny, 50, 200);
24
25                // find all contours
26                using (CvMemStorage storage = new CvMemStorage())
27                {
28                    // find contours by CvContourScanner
29                    CvContourScanner scanner = Cv.StartFindContours(canny, storage, CvContour<CvPoint>.SizeOf, ContourRetrieval.Tree, ContourChain.ApproxSimple);
30                    //CvContourScanner scanner = new CvContourScanner(canny, storage, CvContour<CvPoint>.SizeOf, ContourRetrieval.Tree, ContourChain.ApproxSimple);
31                    while (true)
32                    {
33                        CvSeq<CvPoint> c = Cv.FindNextContour(scanner);
34                        if (c == null)
35                            break;
36                        else
37                            result.DrawContours(c, CvColor.Red, CvColor.Green, 0, 3, LineType.AntiAlias);
38                    }
39                    Cv.EndFindContours(scanner);
40                    //scanner.Dispose();
41                }
42
43                // show canny and result
44                using (CvWindow window1 = new CvWindow("ContourScanner canny", canny))
45                using (CvWindow window2 = new CvWindow("ContourScanner result", result))
46                {
47                    Cv.WaitKey();
48                }             
49            }
50        }
51    }
52}
Note: See TracBrowser for help on using the browser.