public async Task <IActionResult> Index(ImageIndexModel model)
        {
            var location = FileUploader.ProcessFormFile(_azureSettings.StorageAccount, _azureSettings.StorageAccountPassword, model.File, "images", ModelState).Result.ToString();

            _handler.Upsert(new ImageModel()
            {
                Name = model.Name, Location = location
            });
            return(RedirectToAction(nameof(Index)));
        }
Example #2
0
        /// <summary>
        /// 创建索引模型
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static IIndexModel CreateIndexModel(string address)
        {
            string      extension = Path.GetExtension(address).ToLower();
            IIndexModel indexModel;

            switch (extension)
            {
            case ".exe":
            {
                indexModel = new EXEIndexModel()
                {
                    Path = address
                };
                break;
            }

            case ".dll":
            {
                indexModel = new DLLIndexModel()
                {
                    Path = address
                };
                break;
            }

            case ".png":
            case ".jpg":
            case ".jpeg":
            case ".ico":
            {
                indexModel = new ImageIndexModel()
                {
                    Path = address
                };
                break;
            }

            default:
            {
                indexModel = new CommonIndexModel()
                {
                    Path           = address,
                    AttachedEntity = File.ReadAllText(address),
                };
                break;
            }
            }

            indexModel.Index       = Path.GetFileName(address);
            indexModel.Description = Path.GetFileName(address);

            return(indexModel);
        }
Example #3
0
        /// <summary>
        /// 创建索引模型
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static IIndexModel CreateIndexModel(Document document)
        {
            var         field     = document.Get(nameof(IIndexModel.IndexType));
            IndexTypes  indexType = Enum.TryParse(field, out indexType) ? indexType : IndexTypes.Common;
            IIndexModel indexModel;

            switch (indexType)
            {
            case IndexTypes.Exe:
            {
                indexModel = new EXEIndexModel();
                break;
            }

            case IndexTypes.Dll:
            {
                indexModel = new DLLIndexModel();
                break;
            }

            case IndexTypes.Image:
            {
                indexModel = new ImageIndexModel();
                break;
            }

            case IndexTypes.Common:
            default:
            {
                indexModel = new CommonIndexModel();
                break;
            }
            }

            indexModel.FromDocument(document);
            return(indexModel);
        }
Example #4
0
        //public async Task<string> get

        public async Task <ImageIndexModel> getIdentifyFace(int index)
        {
            DirectoryInfo d       = new DirectoryInfo(imageFolder + @"\" + _services.GetCurrentFolder());
            string        logfile = imageFolder + @"\log.txt";

            FileInfo[] files         = d.GetFiles("*.jpg");
            string     testImageFile = files[index].FullName;
            string     time_str      = files[index].Name.Split('.')[0];

            if (index == files.Length - 1 && _services.GetFolderKey() >= _services.GetReqFolder().Count - 1)
            {
                _services.SetAllowKey(0);
            }
            try
            {
                using (Stream s = File.OpenRead(testImageFile))
                {
                    var faces = await faceClient.Face.DetectWithStreamAsync(s);

                    IList <Guid>         faceIds = faces.Select <DetectedFace, Guid>(face => (Guid)face.FaceId).ToArray();//.Select(face => face.FaceId).ToList();
                    int                  result_index = faceIds.Count / 10 + 1;
                    List <IList <Guid> > faceIdContainer = new List <IList <Guid> >(result_index);
                    int                  c_index = 0, r_index = 0;
                    foreach (Guid guid in faceIds)
                    {
                        c_index++;
                        if (c_index / 10 >= r_index)
                        {
                            r_index++;
                            faceIdContainer.Add(new List <Guid>());
                        }
                        faceIdContainer[c_index / 10].Add(guid);
                    }
                    List <IList <IdentifyResult> > results1 = new List <IList <IdentifyResult> >();
                    foreach (IList <Guid> guids in faceIdContainer)
                    {
                        results1.Add(await faceClient.Face.IdentifyAsync(guids, personalGroupId));
                    }

                    List <string> personName = new List <string>();
                    PersonalModel persons    = _services.GetPersonal();
                    List <string> history    = new List <string>();
                    foreach (IList <IdentifyResult> identifies in results1)
                    {
                        foreach (var identifyResult in identifies)
                        {
                            Console.WriteLine("Result of face: {0}", identifyResult.FaceId);
                            if (identifyResult.Candidates.Count == 0)
                            {
                                personName.Add("No one identified");
                            }
                            else
                            {
                                // Get top 1 among all candidates returned
                                var candidateId = identifyResult.Candidates[0].PersonId;
                                foreach (var person in persons.persons)
                                {
                                    if (person.PersonId == identifyResult.Candidates[0].PersonId)
                                    {
                                        personName.Add(person.Name);
                                        CultureInfo provider = CultureInfo.InvariantCulture;
                                        //string dt1 = DateTime.Now.ToString("yyyyMMdd_HHmmss_FFF");
                                        DateTime dt  = DateTime.ParseExact(time_str, "yyyyMMdd_HHmmss_FFF", provider); //.Parse(time_str.Split('_')[0]);
                                        string   his = dt.ToString("yyyy/MM/dd HH:mm:ss ") + person.Name + " appeared";
                                        history.Add(his);
                                        if (!File.Exists(logfile))
                                        {
                                            File.WriteAllText(logfile, his);
                                        }
                                        else
                                        {
                                            his = $"{Environment.NewLine}{his}";
                                            File.AppendAllText(logfile, his);
                                        }
                                        break;
                                    }
                                }
                                //var person = new { Name = ""};// await faceClient.PersonGroupPerson.GetAsync(personalGroupId, candidateId);
                                //Console.WriteLine("Identified as {0}", person.Name);
                                //return "Idnetified as " + person.Name;
                            }
                        }
                    }


                    Image image = Image.FromFile(testImageFile);
                    using (Graphics g = Graphics.FromImage(image))
                    {
                        Pen  brush    = new Pen(Brushes.Red, 2);
                        Font drawFont = new Font("Arial", 16);
                        for (int i = 0; i < faces.Count; i++)
                        {
                            g.DrawRectangle(brush, new Rectangle(faces[i].FaceRectangle.Left, faces[i].FaceRectangle.Top, faces[i].FaceRectangle.Width, faces[i].FaceRectangle.Height));
                            //attr.Add(faces[i].Attributes);
                            g.DrawString(personName[i], drawFont, Brushes.Blue, faces[i].FaceRectangle.Left, faces[i].FaceRectangle.Top - 30);
                        }

                        string base64String = null;

                        using (MemoryStream m = new MemoryStream())
                        {
                            image.Save(m, image.RawFormat);
                            byte[] bytes = m.ToArray();
                            base64String = Convert.ToBase64String(bytes);
                            base64String = "data:image/jpg;base64," + base64String;
                        }

                        ImageIndexModel indexM = new ImageIndexModel();
                        indexM.index   = index;
                        indexM.src     = base64String;
                        indexM.history = history;

                        return(indexM);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ImageIndexModel indexM = new ImageIndexModel();
                indexM.index = index;
                indexM.src   = "Failed";
                //indexM.history = history;
                return(indexM);
            }
        }