public void WriteExifMetaData(string imagePath, PhotoAnalysisResult photoAnalysisResult)
        {
            var data = photoAnalysisResult.Data;

            if (data.Description != null)
            {
                TextWithConfidence captionWithConfidence = data.Description.Captions.FirstOrDefault();
            }

            using (Image <Rgba32> image = Image.Load(imagePath))
            {
                if (image.MetaData.ExifProfile == null)
                {
                    image.MetaData.ExifProfile = new ExifProfile();
                }

                TextWithConfidence captionWithConfidence = data.Description.Captions.FirstOrDefault();
                if (captionWithConfidence != null)
                {
                    if (captionWithConfidence.Confidence >= highConfidenceThreshold)
                    {
                        image.MetaData.ExifProfile.SetValue(ExifTag.ImageDescription, captionWithConfidence.Text);
                        image.MetaData.ExifProfile.SetValue(ExifTag.XPTitle, ToExifByteArray(captionWithConfidence.Text));
                    }
                    else
                    {
                        // Add them for manual review.
                    }
                }

                List <string>             highConfidenceTags = new List <string>();
                List <NameWithConfidence> lowConfidenceTags  = new List <NameWithConfidence>();
                foreach (NameWithConfidence tag in data.Tags)
                {
                    if (tag.Confidence >= highConfidenceThreshold)
                    {
                        highConfidenceTags.Add(tag.Name);
                    }
                    else
                    {
                        lowConfidenceTags.Add(tag);
                    }
                }

                if (highConfidenceTags.Any())
                {
                    image.MetaData.ExifProfile.SetValue(ExifTag.XPKeywords,
                                                        ToExifByteArray(string.Join(',', highConfidenceTags)));
                }
                else
                {
                    // Add them for manual review
                }

                image.Save(imagePath);
            }
        }
Beispiel #2
0
        static void OnPhotoProcessingDone(PhotoAnalysisResult photoAnalysisResult)
        {
            _exifProcessor.WriteExifMetaData(photoAnalysisResult.PhotoAnalysisRequest.FullPath, photoAnalysisResult);
            photosProcessed++;

            if (photosProcessed == photosToProcess)
            {
                autoResetEvent.Set();
            }
        }