Exemple #1
0
        private void OnFindSimilar(SimilarImagesConfig images, string customData)
        {
            if (images != null)
            {
                Log.Debug("TestVisualRecognition", "GetSimilar succeeded!");
                Log.Debug("TestVisualRecognition", "images processed: {0}", images.images_processed);
                foreach (SimilarImageConfig image in images.similar_images)
                {
                    Log.Debug("TestVisualRecognition", "image ID: {0} | image file: {1} | score: {2} | metadata: {3}", image.image_id, image.image_file, image.score, image.metadata.ToString());
                }
            }
            else
            {
                Log.Debug("TestVisualRecognition", "GetSimilar failed!");
            }

            Test(images != null);
            m_FindSimilarTested = true;
        }
        public SimilarImagesConfig FindSimilar(string collectionId, byte[] imageData, string imageFileName, int limit = 10)
        {
            SimilarImagesConfig result = null;

            if (string.IsNullOrEmpty(collectionId))
            {
                throw new ArgumentNullException(nameof(collectionId));
            }

            if (imageData == null || string.IsNullOrEmpty(imageFileName))
            {
                throw new ArgumentNullException("Image and image name required.");
            }

            try
            {
                var    formData      = new MultipartFormDataContent();
                string imageMimeType = GetImageMimeTypeFromFilename(imageFileName);

                var imageDataContent = new ByteArrayContent(imageData);
                imageDataContent.Headers.ContentType = MediaTypeHeaderValue.Parse(imageMimeType);
                formData.Add(imageDataContent, "image_file", imageFileName);

                result = this.Client.PostAsync($"{ this.Endpoint}{string.Format(PATH_FIND_SIMILAR, collectionId)}")
                         .WithArgument("version", VERSION_DATE_2016_05_20)
                         .WithArgument("api_key", ApiKey)
                         .WithArgument("limit", limit.ToString())
                         .WithBodyContent(formData)
                         .As <SimilarImagesConfig>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }