示例#1
0
        public static RecognizerResult DetectFromImage(string ImagePath)
        {
            RecognizerResult Result = new RecognizerResult();

            //Lay moi ten anh, ko lay toan bo duong dan
            Result.ImageLink = System.IO.Path.GetFileName(ImagePath);

            if (Haar == null)
            {
                Haar = new HaarCascade(HAAR_XML_PATH);
            }

            //Chuyen anh trang den roi bat dau recognize, dung using de tu giai phong memories
            using (Image <Gray, byte> Image = new Image <Bgr, byte>(ImagePath).Convert <Gray, byte>())
            {
                var FacesDetected = Image.DetectHaarCascade(Haar, DETECT_SCALE, MIN_NEIGHBOR,
                                                            0, new System.Drawing.Size(MIN_SIZE, MIN_SIZE))[0];
                foreach (var Face in FacesDetected)
                {
                    FaceRegion FaceReg = new FaceRegion(Face.rect.X, Face.rect.Y,
                                                        Face.rect.Width, Face.rect.Height);
                    Result.FaceList.Add(FaceReg);
                }
            }

            return(Result);
        }
示例#2
0
文件: Face.cs 项目: stnfttg/vignette
        public RectangleF GetRegionBounds(FaceRegion region)
        {
            var points  = Landmarks.Where(m => m.Region == region);
            var xValues = points.Select(p => p.Coordinates.X);
            var yValues = points.Select(p => p.Coordinates.Y);

            if (!xValues.Any() || !yValues.Any())
            {
                return(RectangleF.Empty);
            }

            float xMin = xValues.Min();
            float xMax = xValues.Max();
            float yMin = yValues.Min();
            float yMax = yValues.Max();

            return(new RectangleF(xMin, yMin, xMax - xMin, yMax - yMin));
        }
示例#3
0
文件: Plugins.cs 项目: varlo/Unona9
        public static FaceRegion[] FindFaces(byte[] image)
        {
            IPlugin facefinder = null;
            foreach (IPlugin plugin in Plugins.Instances)
            {
                if (plugin.Name == "FaceFinder")
                {
                    facefinder = plugin;
                    break;
                }
            }
            if (facefinder == null) return null;

            Type faceFinderType = facefinder.GetType();
            object results = faceFinderType.InvokeMember("FindFaces", BindingFlags.Default | BindingFlags.InvokeMethod,
                null, facefinder, new object[] {image});

            if (results == null)
            {
                Global.Logger.LogStatus("Plugins::FindFaces", "Application Pool is restarting...");
                ApplicationPoolRecycle.RecycleCurrentApplicationPool();
                return new FaceRegion[0];
            }

            List<FaceRegion> regions = new List<FaceRegion>();
            foreach (object result in (IEnumerable) results)
            {
                Type faceRegionType = result.GetType();
                FaceRegion region = new FaceRegion();
                region.X = (int) faceRegionType.GetField("X").GetValue(result);
                region.Y = (int) faceRegionType.GetField("Y").GetValue(result);
                region.Width = (int) faceRegionType.GetField("Width").GetValue(result);
                region.Height = (int) faceRegionType.GetField("Height").GetValue(result);
                regions.Add(region);
            }
            return regions.ToArray();
        }
示例#4
0
        private static RecognizerResult RecognizeFromImage(FaceRecognizer FaceRec, String ImagePath)
        {
            RecognizerResult Result = new RecognizerResult();

            //Lay moi ten anh, ko lay toan bo duong dan
            Result.ImageLink = System.IO.Path.GetFileName(ImagePath);

            //Dua anh vao, dua ket qua ra
            if (Haar == null)
            {
                Haar = new HaarCascade(HAAR_XML_PATH);
            }

            //Chuyen anh trang den roi bat dau recognize
            Image <Bgr, byte>  RawImage = new Image <Bgr, byte>(ImagePath);
            Image <Gray, byte> Image    = RawImage.Clone().Convert <Gray, byte>();

            var FacesDetected = Image.DetectHaarCascade(Haar, DETECT_SCALE, MIN_NEIGHBOR,
                                                        0, new System.Drawing.Size(MIN_SIZE, MIN_SIZE))[0];

            foreach (var Face in FacesDetected)
            {
                FaceRegion FaceReg = new FaceRegion(Face.rect.X, Face.rect.Y,
                                                    Face.rect.Width, Face.rect.Height);

                //Nhan dien face la cua ai.
                Image <Gray, byte> FaceImage = Image.Copy(Face.rect).Resize(TRAINING_DATA_SIZE,
                                                                            TRAINING_DATA_SIZE, INTER.CV_INTER_CUBIC);
                FaceImage._EqualizeHist();
                FaceRecognizer.PredictionResult PR = FaceRec.Predict(FaceImage);
                FaceReg.StudentID   = PR.Label;
                FaceReg.StudentName = GetUserName(PR);
                Result.FaceList.Add(FaceReg);
            }

            return(Result);
        }