コード例 #1
0
        private static OpenCvSharp.CvRect FrameToPortrait(OpenCvSharp.CvRect bounds, OpenCvSharp.CvRect faceBounds)
        {
            faceBounds.X -= bounds.X;
            faceBounds.Y -= bounds.Y;

            return(faceBounds);
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
ファイル: Cv_B.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#endif
        public static void BGCodeBookUpdate(CvBGCodeBookModel model, CvArr image, CvRect roi, CvArr mask)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            NativeMethods.cvBGCodeBookUpdate(model.CvPtr, image.CvPtr, roi, ToPtr(mask));
            KeepAlive(model, image, mask);
        }
コード例 #4
0
ファイル: Cv_B.cs プロジェクト: tuanthng/opencvsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#endif
        public static void BGCodeBookUpdate(CvBGCodeBookModel model, CvArr image, CvRect roi, CvArr mask)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            IntPtr maskPtr = ToPtr(mask);

            NativeMethods.cvBGCodeBookUpdate(model.CvPtr, image.CvPtr, roi, maskPtr);
        }
コード例 #5
0
        /// <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 = NativeMethods.cvCreateSubdiv2D(
                SeqType.KindSubdiv2D, SizeOf, CvSubdiv2DPoint.SizeOf, CvQuadEdge2D.SizeOf, storage.CvPtr
                );

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

            NativeMethods.cvInitSubdivDelaunay2D(subdiv, rect);

            Initialize(subdiv);
            holdingStorage = storage;
        }
コード例 #6
0
ファイル: Cv_B.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="roi"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="roi"></param>
#endif
        public static void BGCodeBookUpdate(CvBGCodeBookModel model, CvArr image, CvRect roi)
        {
            BGCodeBookUpdate(model, image, roi, null);
        }
コード例 #7
0
ファイル: Cv_B.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#endif
        public static void BGCodeBookClearStale(CvBGCodeBookModel model, int staleThresh, CvRect roi, CvArr mask)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            NativeMethods.cvBGCodeBookClearStale(model.CvPtr, staleThresh, roi, ToPtr(mask));
            KeepAlive(model, mask);
        }
コード例 #8
0
ファイル: Cv_B.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="fgmask"></param>
        /// <param name="roi"></param>
        /// <returns></returns>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="fgmask"></param>
        /// <param name="roi"></param>
        /// <returns></returns>
#endif
        public static int BGCodeBookDiff(CvBGCodeBookModel model, CvArr image, CvArr fgmask, CvRect roi)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (fgmask == null)
            {
                throw new ArgumentNullException(nameof(fgmask));
            }
            try
            {
                return(NativeMethods.cvBGCodeBookDiff(model.CvPtr, image.CvPtr, fgmask.CvPtr, roi));
            }
            finally
            {
                KeepAlive(model, image, fgmask);
            }
        }
コード例 #9
0
 public void DrawToGraphics(Graphics g, CvRect dstRect);
コード例 #10
0
ファイル: CvAvgComp.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        /// 初期化
        /// </summary>
        /// <param name="rect">オブジェクトを内包する矩形(グループの平均矩形)</param>
        /// <param name="neighbors">グループ内に存在する隣接矩形の数</param>
#else
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rect">Bounding rectangle for the object (average rectangle of a group)</param>
        /// <param name="neighbors">number of neighbor rectangles in the group</param>
#endif
        public CvAvgComp(CvRect rect, int neighbors)
        {
            this.Rect      = rect;
            this.Neighbors = neighbors;
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="fgmask"></param>
        /// <param name="roi"></param>
        /// <returns></returns>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="fgmask"></param>
        /// <param name="roi"></param>
        /// <returns></returns>
#endif
        public int Diff(CvArr image, CvArr fgmask, CvRect roi)
        {
            return(Cv.BGCodeBookDiff(this, image, fgmask, roi));
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
#endif
        public void ClearStale(int staleThresh, CvRect roi)
        {
            Cv.BGCodeBookClearStale(this, staleThresh, roi);
        }
コード例 #13
0
ファイル: Cv_B.cs プロジェクト: tuanthng/opencvsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#endif
        public static void BGCodeBookClearStale(CvBGCodeBookModel model, int staleThresh, CvRect roi, CvArr mask)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            IntPtr maskPtr = ToPtr(mask);

            NativeMethods.cvBGCodeBookClearStale(model.CvPtr, staleThresh, roi, maskPtr);
        }
コード例 #14
0
ファイル: Cv_B.cs プロジェクト: tuanthng/opencvsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="fgmask"></param>
        /// <param name="roi"></param>
        /// <returns></returns>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="image"></param>
        /// <param name="fgmask"></param>
        /// <param name="roi"></param>
        /// <returns></returns>
#endif
        public static int BGCodeBookDiff(CvBGCodeBookModel model, CvArr image, CvArr fgmask, CvRect roi)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (fgmask == null)
            {
                throw new ArgumentNullException("fgmask");
            }

            return(NativeMethods.cvBGCodeBookDiff(model.CvPtr, image.CvPtr, fgmask.CvPtr, roi));
        }
コード例 #15
0
ファイル: CvFaceData.cs プロジェクト: inohiroki/opencvsharp
 /// <summary>
 ///
 /// </summary>
 /// <param name="mouthRect"></param>
 /// <param name="leftEyeRect"></param>
 /// <param name="rightEyeRect"></param>
 public CvFaceData(CvRect mouthRect, CvRect leftEyeRect, CvRect rightEyeRect)
 {
     this.MouthRect    = mouthRect;
     this.LeftEyeRect  = leftEyeRect;
     this.RightEyeRect = rightEyeRect;
 }
コード例 #16
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.picTargetPerson.Image == null)
            {
                MessageBox.Show("请选定一张人脸图片");
                return;
            }

            if (drawRectangle == Rectangle.Empty)
            {
                MessageBox.Show("请定位人脸");
                return;
            }


            String oldFileName = this.picTargetPerson.Image.Tag as string;

            String fileName = System.Guid.NewGuid().ToString().ToUpper() + System.IO.Path.GetExtension(oldFileName);

            //搜索人脸
            OpenCvSharp.IplImage iplFace = BitmapConverter.ToIplImage((Bitmap)this.picTargetPerson.Image);

            string savePath = Path.Combine(FileSavePath, fileName);

            iplFace.SaveImage(savePath);

            //归一化
            OpenCvSharp.CvRect rect = new OpenCvSharp.CvRect(
                this.drawRectangle.X,
                this.drawRectangle.Y,
                this.drawRectangle.Width,
                this.drawRectangle.Height);

            OpenCvSharp.IplImage[] normalizedImages =
                Program.searcher.NormalizeImageForTraining(iplFace, rect);

            for (int i = 0; i < normalizedImages.Length; ++i)
            {
                string normalizedFaceName = string.Format("{0}_{1:d4}.jpg",
                                                          System.IO.Path.GetFileNameWithoutExtension(fileName), i);

                string fullPath = System.IO.Path.Combine(faceFeatureImagePath,
                                                         normalizedFaceName);

                normalizedImages[i].SaveImage(fullPath);
            }

            string id   = txtId.Text.ToString();
            string name = txtName.Text.ToString();
            string sex  = rabMan.Checked ? "男" : "女";
            int    age  = 0;

            int.TryParse(txtAge.Text, out age);

            string card = txtCard.Text.ToString();

            PersonInfo info = new PersonInfo();

            info.ID         = id;
            info.Name       = name;
            info.Sex        = sex;
            info.Age        = age;
            info.CardId     = card;
            info.FileName   = fileName;
            info.Similarity = 0;

            perinfo.WriteInfo(info);

            MessageBox.Show("添加成功");

            Array.ForEach(normalizedImages, ipl => ipl.Dispose());
        }
コード例 #17
0
 public IplImage GetSubImage(CvRect rect);
コード例 #18
0
ファイル: Cv_B.cs プロジェクト: shimat/opencvsharp_2410
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
#endif
        public static void BGCodeBookClearStale(CvBGCodeBookModel model, int staleThresh, CvRect roi)
        {
            BGCodeBookClearStale(model, staleThresh, roi, null);
        }
コード例 #19
0
        /// <summary>
        /// CvSubdiv2Dの初期化
        /// </summary>
        /// <param name="rect"></param>
#else
        /// <summary>
        /// CvSubdiv2Dの初期化
        /// </summary>
        /// <param name="rect"></param>
#endif
        public void InitSubdivDelaunay2D(CvRect rect)
        {
            Cv.InitSubdivDelaunay2D(this, rect);
        }
コード例 #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="score"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="score"></param>
#endif
        public CvObjectDetection(CvRect rect, float score)
        {
            this.Rect  = rect;
            this.Score = score;
        }
コード例 #21
0
 public void SetROI(CvRect rect);
コード例 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="staleThresh"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#endif
        public void ClearStale(int staleThresh, CvRect roi, CvArr mask)
        {
            Cv.BGCodeBookClearStale(this, staleThresh, roi, mask);
        }
コード例 #23
0
 public void DrawToHDC(IntPtr hdc, CvRect dstRect);
コード例 #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="roi"></param>
        /// <param name="mask"></param>
#endif
        public void Update(CvArr image, CvRect roi, CvArr mask)
        {
            Cv.BGCodeBookUpdate(this, image, roi, mask);
        }
コード例 #25
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.picTargetPerson.Image == null)
            {
                MessageBox.Show("请选定一张人脸图片");
                return;
            }

            if (drawRectangle == Rectangle.Empty)
            {
                MessageBox.Show("请定位人脸");
                return;
            }

            String oldFileName = this.picTargetPerson.Image.Tag as string;

            String fileName = System.Guid.NewGuid().ToString().ToUpper() + System.IO.Path.GetExtension(oldFileName);

            //搜索人脸
            OpenCvSharp.IplImage iplFace = BitmapConverter.ToIplImage((Bitmap)this.picTargetPerson.Image);

            string savePath = Path.Combine(FileSavePath, fileName);
            iplFace.SaveImage(savePath);

            //归一化
            OpenCvSharp.CvRect rect = new OpenCvSharp.CvRect(
                this.drawRectangle.X,
                this.drawRectangle.Y,
                this.drawRectangle.Width,
                this.drawRectangle.Height);

            OpenCvSharp.IplImage[] normalizedImages =
                Program.searcher.NormalizeImageForTraining(iplFace, rect);

            for (int i = 0; i < normalizedImages.Length; ++i)
            {
                string normalizedFaceName = string.Format("{0}_{1:d4}.jpg",
                    System.IO.Path.GetFileNameWithoutExtension(fileName), i);

                string fullPath = System.IO.Path.Combine(faceFeatureImagePath,
                    normalizedFaceName);

                normalizedImages[i].SaveImage(fullPath);
            }

            string id = txtId.Text.ToString();
            string name = txtName.Text.ToString();
            string sex = rabMan.Checked ? "男" : "女";
            int age = 0;

            int.TryParse(txtAge.Text, out age);

            string card = txtCard.Text.ToString();

            PersonInfo info = new PersonInfo();
            info.ID = id;
            info.Name = name;
            info.Sex = sex;
            info.Age = age;
            info.CardId = card;
            info.FileName = fileName;
            info.Similarity = 0;

            perinfo.WriteInfo(info);

            MessageBox.Show("添加成功");

            Array.ForEach(normalizedImages, ipl => ipl.Dispose());
        }