public IImageAnalysis AnalyzeImage(MediaItem imageItem, Face[] facialAnalysis, OcrResults textAnalysis, AnalysisResult visionAnalysis, bool updateInIndex = true, bool overwrite = false) { var validationErrors = VisionService.ValidateVisionImage(imageItem); validationErrors.AddRange(FaceService.ValidateFaceImage(imageItem)); var imageAnalysis = ImageAnalysisFactory.Create(imageItem, facialAnalysis, textAnalysis, visionAnalysis, validationErrors); var isNewAnalysis = false; if (overwrite || facialAnalysis == null || facialAnalysis.Length == 0) { imageAnalysis.FacialAnalysis = GetFacialAnalysis(imageItem); isNewAnalysis = true; } if (overwrite || textAnalysis?.Regions == null) { imageAnalysis.TextAnalysis = GetTextualAnalysis(imageItem); } if (overwrite || visionAnalysis?.Description == null) { imageAnalysis.VisionAnalysis = GetVisualAnalysis(imageItem); } Dictionary <ID, string> fields = new Dictionary <ID, string> { { Settings.VisualAnalysisFieldId, JsonConvert.SerializeObject(imageAnalysis.VisionAnalysis) }, { Settings.TextualAnalysisFieldId, JsonConvert.SerializeObject(imageAnalysis.TextAnalysis) }, { Settings.FacialAnalysisFieldId, JsonConvert.SerializeObject(imageAnalysis.FacialAnalysis) }, { Settings.AnalyzedImageFieldId, imageItem.ID.ToString() } }; var analysisItem = SearchService.GetImageAnalysisItem(imageItem.ID.ToShortID().ToString(), imageItem.InnerItem.Language.Name, imageItem.Database.Name); if (analysisItem != null) { DataWrapper.UpdateFields(analysisItem, fields); } else { analysisItem = CreateAnalysisItem(imageItem, fields); } if (analysisItem == null) { return(imageAnalysis); } var faceIds = imageAnalysis.FacialAnalysis?.Select(a => a.FaceId).ToArray() ?? new Guid[0]; var peopleDiffer = imageAnalysis.People == null || imageAnalysis.People.Length != faceIds.Length; if (faceIds.Any() && (overwrite || peopleDiffer)) { if (isNewAnalysis) { PersonService.IdentifyPeople(analysisItem, faceIds, analysisItem.Database.Name, PersonService.GetAllGroupIds(analysisItem.Database.Name)); } else { PersonService.DetectAndIdentifyPeople(imageItem, analysisItem.Database.Name, PersonService.GetAllGroupIds(analysisItem.Database.Name)); } } if (updateInIndex) { SearchService.UpdateItemInIndex(imageItem, imageItem.Database.Name); } return(imageAnalysis); }