当前位置: 首页>>代码示例>>C#>>正文


C# CvRect类代码示例

本文整理汇总了C#中CvRect的典型用法代码示例。如果您正苦于以下问题:C# CvRect类的具体用法?C# CvRect怎么用?C# CvRect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CvRect类属于命名空间,在下文中一共展示了CvRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSub

        public static OpenCvSharp.IplImage GetSub(this OpenCvSharp.IplImage ipl, OpenCvSharp.CvRect subRect)
        {
            if (ipl == null)
                throw new ArgumentNullException("ipl", "ipl is null.");

            var boundingRect = new CvRect(0, 0, ipl.Width, ipl.Height);

            if (!boundingRect.Contains(subRect))
                throw new InvalidOperationException("subRect is outside of ipl");

            try
            {
                ipl.SetROI(subRect);

                OpenCvSharp.IplImage sub = new IplImage(
                    ipl.GetSize(),
                    ipl.Depth,
                    ipl.NChannels);

                ipl.Copy(sub);
                return sub;
            }
            finally
            {
                ipl.ResetROI();
            }
        }
开发者ID:dalinhuang,项目名称:appcollection,代码行数:27,代码来源:Extensions.cs

示例2: SampleFileStorageWriteImage

        /// <summary>
        /// 画像データのファイルストレージへの書き込み
        /// </summary>
        /// <param name="fileName">書きこむXML or YAMLファイル</param>
        private static void SampleFileStorageWriteImage(string fileName)
        {
            // cvWrite, cvWriteComment
            // IplImage構造体の情報をファイルに保存する

            // (1)画像を読み込む
            using (IplImage colorImg = new IplImage(Const.ImageLenna, LoadMode.Color))
            using (IplImage grayImg = new IplImage(colorImg.Size, BitDepth.U8, 1))
            {
                // (2)ROIの設定と二値化処理
                colorImg.CvtColor(grayImg, ColorConversion.BgrToGray);
                CvRect roi = new CvRect(0, 0, colorImg.Width / 2, colorImg.Height / 2);
                grayImg.SetROI(roi);
                colorImg.SetROI(roi);
                grayImg.Threshold(grayImg, 90, 255, ThresholdType.Binary);
                // (3)xmlファイルへの書き出し 
                using (CvFileStorage fs = new CvFileStorage(fileName, null, FileStorageMode.Write))
                {
                    fs.WriteComment("This is a comment line.", false);
                    fs.Write("color_img", colorImg);
                    fs.StartNextStream();
                    fs.Write("gray_img", grayImg);
                }
                // (4)書きこんだxmlファイルを開く
                //using (Process p = Process.Start(fileName)) {
                //    p.WaitForExit();
                //}                
            }
        }
开发者ID:qxp1011,项目名称:opencvsharp,代码行数:33,代码来源:FileStorage.cs

示例3: DrawRect

 public static void DrawRect(this IplImage ipl, CvRect rect, CvColor color, int thickNess)
 {
     var roi = ipl.ROI;
     ipl.ResetROI();
     ipl.DrawRect(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height, color, thickNess);
     ipl.SetROI(roi);
 }
开发者ID:dalinhuang,项目名称:appcollection,代码行数:7,代码来源:IplExtensions.cs

示例4: AddRect

 public void AddRect(CvRect r)
 {
     if (xs.Count < 1)
     {
         xs.Add(r);
     }
     else
     {
         for (int i = 0; i < xs.Count; i++)
         {
             var c = xs[i];
             if (r.X <= c.X)
             {
                 xs.Insert(i, r);
                 break;
             }
         }
     }
     if (ys.Count < 1)
     {
         ys.Add(r);
     }
     else
     {
         for (int i = 0; i < ys.Count; i++)
         {
             var c = ys[i];
             if (r.Y <= c.Y)
             {
                 ys.Insert(i, c);
                 break;
             }
         }
     }
 }
开发者ID:mind0n,项目名称:hive,代码行数:35,代码来源:EyeRects.cs

示例5: DrawToHdc

        public DrawToHdc()
        {
            CvRect roi = new CvRect(320, 260, 100, 100);        // region of roosevelt's face

            using (IplImage src = new IplImage(Const.ImageYalta, LoadMode.Color))
            using (IplImage dst = new IplImage(roi.Size, BitDepth.U8, 3))
            {
                src.ROI = roi;

                using (Bitmap bitmap = new Bitmap(roi.Width, roi.Height, PixelFormat.Format32bppArgb))
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    //BitmapConverter.DrawToGraphics(src, g, new CvRect(new CvPoint(0, 0), roi.Size));
                    IntPtr hdc = g.GetHdc();
                    BitmapConverter.DrawToHdc(src, hdc, new CvRect(new CvPoint(0,0), roi.Size));
                    g.ReleaseHdc(hdc);

                    g.DrawString("Roosevelt", new Font(FontFamily.GenericSerif, 12), Brushes.Red, 20, 0);
                    g.DrawEllipse(new Pen(Color.Red, 4), new Rectangle(20, 20, roi.Width/2, roi.Height/2));

                    dst.CopyFrom(bitmap);
                }

                src.ResetROI();                

                using (new CvWindow("src", src))
                using (new CvWindow("dst", dst))
                {
                    Cv.WaitKey();
                }
            }
        }
开发者ID:healtech,项目名称:opencvsharp,代码行数:32,代码来源:DrawToHDC.cs

示例6: recognizeDigit

        // 数字認識
        internal static int recognizeDigit(CvMat image)
        {
            int nonzero = 0;

            nonzero = image.GetCols( image.Cols-2, image.Cols ).CountNonZero();
            if ( image.Rows * 2 == nonzero )
                // 1 右端2列がすべて輝点
                return 1;

            nonzero = image.GetRows( image.Rows-2, image.Rows ).CountNonZero();
            if ( image.Cols * 2 == nonzero )
                // 2 下端2行がすべて輝点
                return 2;

            nonzero = image.GetRows ( 0, 2 ).CountNonZero();
            if ( image.Cols * 2 - 2 < nonzero )
                // 7 上端2行がすべて輝点.ただし1ピクセルまで欠けても良い
                return 7;

            nonzero = image.GetCols ( image.Cols-3, image.Cols-1 ).CountNonZero();
            if ( image.Rows * 2 == nonzero )
                // 4 右端の左2列がすべて輝点
                return 4;

            CvRect rect = new CvRect( 0, 0, 1, image.Rows*2/3 );
            CvMat subarr;
            nonzero = image.GetSubArr ( out subarr, rect ).CountNonZero();
            if ( 0 == nonzero )
                // 3 左端の上部3分の2がすべて暗点
                return 3;

            rect = new CvRect ( 0, image.Rows/2, 3, 2 );
            nonzero = image.GetSubArr ( out subarr, rect ).CountNonZero();
            if ( 0 == nonzero )
                // 5 左端の下半分開始すぐのwidth3 height2 がすべて暗点
                return 5;

            rect = new CvRect ( image.Cols/2, image.Rows/2-1, 1, 3 );
            nonzero = image.GetSubArr( out subarr, rect ).CountNonZero();
            if ( 0 == nonzero )
                // 0 中央列中央3ピクセルがすべて暗点
                return 0;

            rect = new CvRect ( image.Cols-1, 0, 1, image.Rows*2/5 );
            nonzero = image.GetSubArr( out subarr, rect ).CountNonZero();
            if ( 0 == nonzero )
                // 6 右端上部5分の2がすべて暗点
                return 6;

            rect = new CvRect ( image.Cols-1, image.Rows-3, 1, 3 );
            nonzero = image.GetSubArr( out subarr, rect ).CountNonZero();
            if ( 0 == nonzero )
                // 右端下部3ピクセルがすべて暗点
                return 9;

            // 8 上記条件を満たさない
            return 8;
        }
开发者ID:ustreamer-01647,项目名称:fezScore2text,代码行数:59,代码来源:recognize.cs

示例7: HOG

        public HOG()
        {
            CPP.Mat img = CPP.CvCpp.ImRead(Const.ImageAsahiyama, LoadMode.Color);

            /*
            if (GPU.CvGpu.IsEnabled)
            {
                GPU.GpuMat imgGpu = new GPU.GpuMat(img);

                GPU.HOGDescriptor hog = new GPU.HOGDescriptor();
                hog.SetSVMDetector(OpenCvSharp.CPlusPlus.HOGDescriptor.GetDefaultPeopleDetector());

                //bool b = hog.CheckDetectorSize();
                //b.ToString();
            }
            else
            //*/
            {
                CPP.HOGDescriptor hog = new CPP.HOGDescriptor();
                hog.SetSVMDetector(CPP.HOGDescriptor.GetDefaultPeopleDetector());

                bool b = hog.CheckDetectorSize();
                b.ToString();

                Stopwatch watch = Stopwatch.StartNew();

                // run the detector with default parameters. to get a higher hit-rate
                // (and more false alarms, respectively), decrease the hitThreshold and
                // groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
                CvRect[] found = hog.DetectMultiScale(img, 0, new CvSize(8, 8), new CvSize(24, 16), 1.05, 2);

                watch.Stop();
                Console.WriteLine("Detection time = {0}ms", watch.ElapsedMilliseconds);
                Console.WriteLine("{0} region(s) found", found.Length);

                foreach (CvRect rect in found)
                {
                    // the HOG detector returns slightly larger rectangles than the real objects.
                    // so we slightly shrink the rectangles to get a nicer output.
                    CvRect r = new CvRect
                    {
                        X = rect.X + (int)Math.Round(rect.Width * 0.1),
                        Y = rect.Y + (int)Math.Round(rect.Height * 0.1),
                        Width = (int)Math.Round(rect.Width * 0.8),
                        Height = (int)Math.Round(rect.Height * 0.8)
                    };
                    img.Rectangle(r.TopLeft, r.BottomRight, CvColor.Red, 3, LineType.Link8, 0);
                }

                using (CvWindow window = new CvWindow("people detector", WindowMode.None, img.ToIplImage()))
                {
                    window.SetProperty(WindowProperty.Fullscreen, 1);
                    Cv.WaitKey(0);
                }
            }
        }
开发者ID:neoxeo,项目名称:opencvsharp,代码行数:56,代码来源:HOG.cs

示例8: LocateFaces

        public static CvRect[] LocateFaces(this IplImage img, FaceSearchWrapper.FaceSearch searcher, CvRect rectToLookin)
        {
            var frame = new Common.Frame(img);
            frame.MotionRectangles.Add(rectToLookin);
            var faces = searcher.SearchFace(frame.GetImage());

            var faceRects = from f in faces
                            select f.Bounds;

            return faceRects.ToArray();
        }
开发者ID:dalinhuang,项目名称:appcollection,代码行数:11,代码来源:IplImageExtensions.cs

示例9: CvFaceTracker

        /// <summary>
        /// 
        /// </summary>
        /// <param name="imgGray"></param>
        /// <param name="pRects"></param>
        /// <returns></returns>
        public CvFaceTracker(IplImage imgGray, CvRect[] pRects)
        {
            if (imgGray == null)
                throw new ArgumentNullException("imgGray");
            if (pRects == null)
                throw new ArgumentNullException("pRects");
            if (pRects.Length != 3)
                throw new ArgumentException("pRects.Length must be 3");

            _ptr = CvInvoke.cvInitFaceTracker(IntPtr.Zero, imgGray.CvPtr, pRects, 3);
            if (_ptr == IntPtr.Zero)
                throw new OpenCvSharpException("Failed to create CvFaceTracker");
        }
开发者ID:sanglin307,项目名称:UnityOpenCV,代码行数:19,代码来源:CvFaceTracker.cs

示例10: Delaunay

        public Delaunay()
        {
            CvRect rect = new CvRect(0, 0, 600, 600);
            CvColor activeFacetColor = new CvColor(255, 0, 0);
            CvColor delaunayColor = new CvColor(0, 0, 0);
            CvColor voronoiColor = new CvColor(0, 180, 0);
            CvColor bkgndColor = new CvColor(255, 255, 255);
            Random rand = new Random();
            
            using (CvMemStorage storage = new CvMemStorage(0))
            using (IplImage img = new IplImage(rect.Size, BitDepth.U8, 3))
            using (CvWindow window = new CvWindow("delaunay"))
            {
                img.Set(bkgndColor);
                CvSubdiv2D subdiv = new CvSubdiv2D(rect, storage);
                for (int i = 0; i < 200; i++)
                {
                    CvPoint2D32f fp = new CvPoint2D32f
                    {
                        X = (float)rand.Next(5, rect.Width - 10),
                        Y = (float)rand.Next(5, rect.Height - 10)
                    };
                    LocatePoint(subdiv, fp, img, activeFacetColor);
                    window.Image = img;

                    if (CvWindow.WaitKey(100) >= 0)
                    {
                        break;
                    }
                    subdiv.Insert(fp);
                    subdiv.CalcVoronoi2D();
                    img.Set(bkgndColor);
                    DrawSubdiv(img, subdiv, delaunayColor, voronoiColor);
                    window.Image = img;
                    if (CvWindow.WaitKey(100) >= 0)
                    {
                        break;
                    }
                }
                img.Set(bkgndColor);
                PaintVoronoi(subdiv, img);
                window.Image = img;

                CvWindow.WaitKey(0);
            }
        }
开发者ID:qxp1011,项目名称:opencvsharp,代码行数:46,代码来源:Delaunay.cs

示例11: PyrSegmentation

        public PyrSegmentation()
        {
            // cvPyrSegmentation
            // レベルを指定して画像ピラミッドを作成し,その情報を用いて画像のセグメント化を行なう.

            const double threshold1 = 255.0;
            const double threshold2 = 50.0; 

            // (1)画像の読み込み
            using (IplImage srcImg = new IplImage(Const.ImageGoryokaku, LoadMode.AnyDepth | LoadMode.AnyColor))
            {
                // level1から4それぞれでやってみる
                IplImage[] dstImg = new IplImage[4];
                for (int level = 0; level < dstImg.Length; level++)
                {
                    // (2)領域分割のためにROIをセットする
                    CvRect roi = new CvRect()
                    {
                        X = 0,
                        Y = 0,
                        Width = srcImg.Width & -(1 << (level + 1)),
                        Height = srcImg.Height & -(1 << (level + 1))
                    };
                    srcImg.ROI = roi;
                    // (3)分割結果画像出力用の画像領域を確保し,領域分割を実行
                    dstImg[level] = srcImg.Clone();
                    Cv.PyrSegmentation(srcImg, dstImg[level], level + 1, threshold1, threshold2);
                }

                // (4)入力画像と分割結果画像の表示
                CvWindow wSrc = new CvWindow("src", srcImg);
                CvWindow[] wDst = new CvWindow[dstImg.Length];
                for (int i = 0; i < dstImg.Length; i++)
                {
                    wDst[i] = new CvWindow("dst" + i, dstImg[i]);
                }
                CvWindow.WaitKey();
                CvWindow.DestroyAllWindows();

                foreach (IplImage item in dstImg)
                {
                    item.Dispose();
                }
            }

        }
开发者ID:qxp1011,项目名称:opencvsharp,代码行数:46,代码来源:PyrSegmentation.cs

示例12: PyrMeanShiftFiltering

        public PyrMeanShiftFiltering()
        {
            // cvPyrMeanShiftFiltering
            // 平均値シフト法による画像のセグメント化を行う

            const int level = 2;

            // (1)画像の読み込み
            using (IplImage srcImg = new IplImage(Const.ImageGoryokaku, LoadMode.AnyDepth | LoadMode.AnyColor))
            {
                if (srcImg.NChannels != 3)
                {
                    throw new Exception();
                }
                if (srcImg.Depth != BitDepth.U8)
                {
                    throw new Exception();
                }

                // (2)領域分割のためにROIをセットする
                CvRect roi = new CvRect
                {
                    X = 0,
                    Y = 0,
                    Width = srcImg.Width & -(1 << level),
                    Height = srcImg.Height & -(1 << level)
                };
                srcImg.ROI = roi;

                // (3)分割結果画像出力用の画像領域を確保し,領域分割を実行
                using (IplImage dstImg = srcImg.Clone())
                {
                    Cv.PyrMeanShiftFiltering(srcImg, dstImg, 30.0, 30.0, level, new CvTermCriteria(5, 1));
                    // (4)入力画像と分割結果画像の表示
                    using (CvWindow wSrc = new CvWindow("Source", srcImg))
                    using (CvWindow wDst = new CvWindow("MeanShift", dstImg))
                    {
                        CvWindow.WaitKey();
                    }
                }
            }

        }
开发者ID:qxp1011,项目名称:opencvsharp,代码行数:43,代码来源:PyrMeanShiftFiltering.cs

示例13: extractScoreRows

        // スコア表からキャラクタ単位に切り分ける
        static void extractScoreRows(CvMat scoreTable, ref List<CvMat> scoreRows)
        {
            CvMat scoreRow;
            CvRect rect;
            // ランキングスコア10件
            for ( int i = 0; i < ScoreTop10Rows; i++ )
            {
                rect = new CvRect ( 0, i * ( ScoreRowHeight + ScoreRowInterval ),
                    scoreTable.Cols, ScoreRowHeight );
                scoreTable.GetSubArr ( out scoreRow, rect );

                scoreRows.Add( scoreRow );
            }

            // プレイヤースコア
            rect = new CvRect ( 0, scoreTable.Rows - ScoreRowHeight, scoreTable.Cols, ScoreRowHeight );
            scoreTable.GetSubArr ( out scoreRow, rect );

            scoreRows.Add ( scoreRow );
        }
开发者ID:ustreamer-01647,项目名称:fezScore2text,代码行数:21,代码来源:extract.cs

示例14: Test

        public void Test()
        {
            var faceSearcher = new FaceSearchWrapper.FaceSearch();

            int count = 0;
            var timer = new System.Diagnostics.Stopwatch();
            timer.Start();

            foreach (var file in System.IO.Directory.EnumerateFiles(@"G:\pic", "*.jpg"))
            {
                var img = IplImage.FromFile(file);
                var rect = new CvRect(0, 0, img.Width, img.Height);
                var faces = faceSearcher.SearchFace(img, rect);
                System.Diagnostics.Debug.WriteLine(faces.Length);
                count++;
            }

            var msPerPic = timer.ElapsedMilliseconds/count;
            System.Diagnostics.Debug.WriteLine("millisecond per picture: " + msPerPic);
        }
开发者ID:dalinhuang,项目名称:appcollection,代码行数:20,代码来源:FaceSearcherTest.cs

示例15: CvSubdiv2D

        /// <summary>
	    /// cvCreateSubdivDelaunay2Dで初期化
	    /// </summary>
        /// <param name="rect"></param>
	    /// <param name="storage"></param>
#else
        /// <summary>
        /// Initializes using cvCreateSubdivDelaunay2D
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="storage"></param>
#endif
        public CvSubdiv2D(CvRect rect, CvMemStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException();
            }

            IntPtr subdiv = CvInvoke.cvCreateSubdiv2D(
                SeqType.KindSubdiv2D, CvSubdiv2D.SizeOf, CvSubdiv2DPoint.SizeOf, CvQuadEdge2D.SizeOf, storage.CvPtr
            );

            if (subdiv == IntPtr.Zero)
            {
                throw new OpenCvSharpException("Failed to create CvSubdiv2D");
            }

            CvInvoke.cvInitSubdivDelaunay2D(subdiv, rect);

            Initialize(subdiv);
            holdingStorage = storage;
        }
开发者ID:neoxeo,项目名称:opencvsharp,代码行数:33,代码来源:CvSubdiv2D.cs


注:本文中的CvRect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。