コード例 #1
0
        void fnFindFacesThread()
        {
            while (IsRunning)
            {
                if (FSource.FrameChanged)
                {
                    lock (this)
                    {
                        FGrayImage = FSource.Img.Convert <Gray, Byte>();

                        var stride = (FGrayImage.Width * 3);
                        var align  = stride % 4;

                        if (align != 0)
                        {
                            stride += 4 - align;
                        }

                        FGrayImage._EqualizeHist();

                        MCvAvgComp[] faceDetected = FHaarCascade.Detect(FGrayImage, 1.8, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(FGrayImage.Width / 8, FGrayImage.Height / 8));


                        Faces.Clear();

                        foreach (MCvAvgComp f in faceDetected)
                        {
                            FaceTrackingFace face = new FaceTrackingFace();
                            var faceVector        = new Vector2D(f.rect.X + f.rect.Width / 2, f.rect.Y + f.rect.Height / 2);

                            Vector2D CMaximumSourceXY = new Vector2D(FGrayImage.Width, FGrayImage.Height);

                            face.Position = VMath.Map(faceVector, CMinimumSourceXY, CMaximumSourceXY, CMinimumDestXY, CMaximumDestXY, TMapMode.Float);
                            face.Scale    = VMath.Map(new Vector2D(f.rect.Width, f.rect.Height), CMinimumSourceXY.x, CMaximumSourceXY.x, 0, 2, TMapMode.Float);

                            Faces.Add(face);
                        }
                    }
                }
            }
        }
コード例 #2
0
		void fnFindFacesThread()
		{
			while (IsRunning)
			{
				if (FSource.FrameChanged)
					lock(this)
					{
						FGrayImage = FSource.Img.Convert<Gray, Byte>();

						var stride = (FGrayImage.Width * 3);
						var align = stride % 4;

						if (align != 0)
						{
							stride += 4 - align;
						}
						
						FGrayImage._EqualizeHist();

						MCvAvgComp[] faceDetected = FHaarCascade.Detect(FGrayImage, 1.8, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(FGrayImage.Width / 8, FGrayImage.Height / 8));


						Faces.Clear();

						foreach (MCvAvgComp f in faceDetected)
						{
							FaceTrackingFace face = new FaceTrackingFace();
							var faceVector = new Vector2D(f.rect.X + f.rect.Width / 2, f.rect.Y + f.rect.Height / 2);

							Vector2D CMaximumSourceXY = new Vector2D(FGrayImage.Width, FGrayImage.Height);

							face.Position = VMath.Map(faceVector, CMinimumSourceXY, CMaximumSourceXY, CMinimumDestXY, CMaximumDestXY, TMapMode.Float);
							face.Scale = VMath.Map(new Vector2D(f.rect.Width, f.rect.Height), CMinimumSourceXY.x, CMaximumSourceXY.x, 0, 2, TMapMode.Float);

							Faces.Add(face);
						}
					}
				
			}
		}