示例#1
0
        public void GetCollection()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

            var result = service.GetCollection(
                collectionId: "5826c5ec-6f86-44b1-ab2b-cca6c75f2fc7"
                );

            Console.WriteLine(result.Response);
        }
示例#2
0
        public void ListClassifiers()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            VisualRecognitionService service = new VisualRecognitionService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.ListClassifiers();

            Console.WriteLine(result.Response);
        }
示例#3
0
        public void t10_CreateCollection_Success()
        {
            DeleteDotnetCollections();

            VisualRecognitionService service = new VisualRecognitionService();
            service.SetCredential(apikey);

            var result = service.CreateCollection(_collectionNameToCreate);

            _createdCollectionId = result.CollectionId;
            Console.WriteLine(string.Format("Created collection {0}", _createdCollectionId));

            Assert.IsNotNull(result);
            Assert.IsTrue(!string.IsNullOrEmpty(_createdCollectionId));
        }
        public void t01_ClassifyPost_Success()
        {
            VisualRecognitionService service = new VisualRecognitionService();

            service.SetCredential(apikey);

            using (FileStream fs = File.OpenRead(_localGiraffeFilePath))
            {
                var result = service.Classify((fs as Stream).ReadAllBytes(), Path.GetFileName(_localGiraffeFilePath), "image/jpeg");

                Assert.IsNotNull(result);
                Assert.IsNotNull(result.Images);
                Assert.IsTrue(result.Images.Count > 0);
            }
        }
示例#5
0
        public void t19_DeleteCollectionImage_Success()
        {
            if (string.IsNullOrEmpty(_createdCollectionId))
                Assert.Fail("Created collection ID is null or empty.");

            if (string.IsNullOrEmpty(_addedImageId))
                Assert.Fail("Added image ID is null or empty.");

            VisualRecognitionService service = new VisualRecognitionService();
            service.SetCredential(apikey);

            var result = service.DeleteImage(_createdCollectionId, _addedImageId);

            Assert.IsNotNull(result);
        }
        public void t21_DeleteClassifier_Success()
        {
            if (string.IsNullOrEmpty(_createdClassifierId))
            {
                Assert.Fail("Created classsifier ID is null or empty.");
            }

            VisualRecognitionService service = new VisualRecognitionService();

            service.SetCredential(apikey);

            var result = service.DeleteClassifier(_createdClassifierId);

            Assert.IsNotNull(result);
        }
        public void CreateCollection()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

            var result = service.CreateCollection(
                name: Utility.ConvertToUtf8("my-collection"),
                description: Utility.ConvertToUtf8("A description of my collection")
                );

            Console.WriteLine(result.Response);
        }
        public void t01_ClassifyPost_Success()
        {
            VisualRecognitionService _visualRecognition = new VisualRecognitionService(_apikey, _endpoint);

            _visualRecognition.Client.BaseClient.Timeout = TimeSpan.FromMinutes(60);

            using (FileStream fs = File.OpenRead(_localGiraffeFilePath))
            {
                var result = _visualRecognition.Classify((fs as Stream).ReadAllBytes(), Path.GetFileName(_localGiraffeFilePath), "image/jpeg");

                Assert.IsNotNull(result);
                Assert.IsNotNull(result.Images);
                Assert.IsTrue(result.Images.Count > 0);
            }
        }
        public void DeleteImage()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

            var result = service.DeleteImage(
                collectionId: "60b4a98f-2472-4e2b-9c73-28bcaea6fa00",
                imageId: "2018-Honda-Fit_dc0e7bbb5169dd0337ef5b753027ca90"
                );

            Console.WriteLine(result.StatusCode);
        }
        public void GetTrainingUsage()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

            var result = service.GetTrainingUsage(
                startTime: "2019-01-01",
                endTime: "2019-01-31"
                );

            Console.WriteLine(result.Response);
        }
        public void t12_GetCollectionImages_Success()
        {
            if (string.IsNullOrEmpty(_createdCollectionId))
            {
                Assert.Fail("Created collection ID is null or empty.");
            }

            VisualRecognitionService service = new VisualRecognitionService();

            service.SetCredential(apikey);

            var result = service.GetCollectionImages(_createdCollectionId);

            Assert.IsNotNull(result);
        }
        public void DeleteUserData()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            VisualRecognitionService service = new VisualRecognitionService(tokenOptions, versionDate);

            var result = service.DeleteUserData(
                customerId: "customerId"
                );

            Console.WriteLine(result.Response);
        }
        public void GetCoreMlModel()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            VisualRecognitionService service = new VisualRecognitionService(tokenOptions, versionDate);

            var result = service.GetCoreMlModel(
                classifierId: classifierId
                );

            Console.WriteLine(result.Response);
        }
示例#14
0
        public void DeleteClassifier()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            VisualRecognitionService service = new VisualRecognitionService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.DeleteClassifier(
                classifierId: classifierId
                );

            Console.WriteLine(result.StatusCode);
        }
示例#15
0
        public DetailedResponse <ClassifiedImages> GetImageInfo(IFormFile file)
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey:);

            VisualRecognitionService service = new VisualRecognitionService("2018-03-19", authenticator);

            //DetailedResponse<ClassifiedImages> result;
            /// upload to aws bucket and create url
            ///
            Task <string> uploadFile = _fileService.UploadAsync(file);

            string imageUrl = uploadFile.Result;

            return(service.Classify(url: imageUrl));
        }
示例#16
0
        public VisualRecognitionServiceExample(string apikey, string versionDate)
        {
            var options = new TokenOptions()
            {
                IamApiKey = _apikey,
            };

            _service = new VisualRecognitionService(options, versionDate);
            _service.Client.BaseClient.Timeout = TimeSpan.FromMinutes(120);

            ClassifyImage();
            ClassifyUrl();
            //ListAllClassifiers();

            Console.WriteLine("\n~ VisualRecognition examples complete.");
        }
示例#17
0
        public void GetCoreMlModel()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            VisualRecognitionService service = new VisualRecognitionService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.GetCoreMlModel(
                classifierId: classifierId
                );

            Console.WriteLine(result.Response);
        }
示例#18
0
        public void DeleteUserData()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            VisualRecognitionService service = new VisualRecognitionService(versionDate, config);

            service.SetEndpoint(url);

            var result = service.DeleteUserData(
                customerId: "customerId"
                );

            Console.WriteLine(result.Response);
        }
        public void DeleteClassifier()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            VisualRecognitionService service = new VisualRecognitionService(tokenOptions, versionDate);

            var result = service.DeleteClassifier(
                classifierId: classifierId
                );

            Console.WriteLine(result.StatusCode);
        }
        public void Analyze()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

            DetailedResponse <AnalyzeResponse> result     = null;
            List <FileWithMetadata>            imagesFile = new List <FileWithMetadata>();

            using (FileStream hondaFilestream = File.OpenRead("./honda.jpg"), diceFilestream = File.OpenRead("./dice.png"))
            {
                using (MemoryStream hondaMemoryStream = new MemoryStream(), diceMemoryStream = new MemoryStream())
                {
                    hondaFilestream.CopyTo(hondaMemoryStream);
                    diceFilestream.CopyTo(diceMemoryStream);
                    FileWithMetadata hondaFile = new FileWithMetadata()
                    {
                        Data        = hondaMemoryStream,
                        ContentType = "image/jpeg",
                        Filename    = "honda.jpg"
                    };
                    FileWithMetadata diceFile = new FileWithMetadata()
                    {
                        Data        = diceMemoryStream,
                        ContentType = "image/png",
                        Filename    = "dice.png"
                    };
                    imagesFile.Add(hondaFile);
                    imagesFile.Add(diceFile);

                    result = service.Analyze(
                        collectionIds: new List <string>()
                    {
                        "{collectionId}"
                    },
                        features: new List <string>()
                    {
                        "objects"
                    },
                        imagesFile: imagesFile);

                    Console.WriteLine(result.Response);
                }
            }
        }
        public void UpdateObject()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

            var result = service.UpdateObjectMetadata(
                collectionId: "5826c5ec-6f86-44b1-ab2b-cca6c75f2fc7",
                _object: "2018-Fit",
                newObject: "subcompact"
                );


            Console.WriteLine(result.Response);
        }
示例#22
0
        public void t13_AddCollectionImages_Success()
        {
            VisualRecognitionService service = new VisualRecognitionService();
            service.SetCredential(apikey);

            using (FileStream imageStream = File.OpenRead(_localGiraffeFilePath), metadataStream = File.OpenRead(_localImageMetadataPath))
            {
                var result = service.AddImage(_createdCollectionId, imageStream.ReadAllBytes(), Path.GetFileName(_localGiraffeFilePath), metadataStream.ReadAllBytes());

                _addedImageId = result.Images[0].ImageId;
                Console.WriteLine(string.Format("Added image {0}", _addedImageId));

                Assert.IsNotNull(result);
                Assert.IsTrue(result.ImagesProcessed > 0);
                Assert.IsTrue(!string.IsNullOrEmpty(_addedImageId));
            }
        }
示例#23
0
        private void handleAsyncCalls(string fileId)
        {
            string accounSid = "AC74db4dcc60f91702206b697c0ef368e0";
            string authToken = "1c7051f8bb5fdda9d0e55c053f8fd62a";

            VisualRecognitionService vr = new VisualRecognitionService();

            vr.SetCredential("8f93d643451fc90c6047cdb1074cd2369bd1cbd8");
            string[] classifierIds = { "Falling_1776823743" };
            var      uri           = "http://9c2d7edd.ngrok.io/api/image/" + fileId + ".png";

            IBM.WatsonDeveloperCloud.VisualRecognition.v3.Model.ClassifyTopLevelMultiple result = null;
            try
            {
                result = vr.Classify(uri, classifierIds);
                //result = await Task.Run(() => vr.Classify(uri, classifierIds));
                //Thread.Sleep(1000);
            }
            catch (AggregateException e)
            {
                var allo = e.Message;
            }

            if (result == null)
            {
                Debug.WriteLine("NULL");
                return;
            }
            System.Diagnostics.Debug.WriteLine("Fell: {0}, Standing {1}",
                                               result.Images.First().Classifiers.First().Classes[0].Score,
                                               result.Images.First().Classifiers.First().Classes[1].Score);

            if (!TwilioSent && result.Images.First().Classifiers.First().Classes[0].Score >= 0.45)
            {
                TwilioSent = !TwilioSent;
                TwilioClient.Init(accounSid, authToken);
                var message = MessageResource.Create(
                    to: new PhoneNumber("+14388883108"),
                    from: new PhoneNumber("+15146127729"),
                    mediaUrl: new List <Uri> {
                    new Uri(uri)
                },
                    body: "ElderVision: Your elder might be in danger!! See picture to confirm");
            }
        }
        public void ListCollections_Success()
        {
            IClient  client  = Substitute.For <IClient>();
            IRequest request = Substitute.For <IRequest>();

            client.GetAsync(Arg.Any <string>())
            .Returns(request);

            VisualRecognitionService service = new VisualRecognitionService(client);
            var versionDate = "versionDate";

            service.VersionDate = versionDate;


            var result = service.ListCollections();

            request.Received().WithArgument("version", versionDate);
        }
示例#25
0
        public void t08_UpdateClassifier_Success()
        {
            if (string.IsNullOrEmpty(_createdClassifierId))
                Assert.Fail("Created classsifier ID is null or empty.");

            VisualRecognitionService service = new VisualRecognitionService();
            service.SetCredential(apikey);

            using (FileStream positiveExamplesStream = File.OpenRead(_localTurtlePositiveExamplesFilePath))
            {
                Dictionary<string, byte[]> positiveExamples = new Dictionary<string, byte[]>();
                positiveExamples.Add(_turtleClassname, positiveExamplesStream.ReadAllBytes());

                var result = service.UpdateClassifier(_createdClassifierId, positiveExamples);

                Assert.IsNotNull(result);
            }
        }
        public void DeleteUserData_Success()
        {
            IClient  client  = Substitute.For <IClient>();
            IRequest request = Substitute.For <IRequest>();

            client.DeleteAsync(Arg.Any <string>())
            .Returns(request);

            VisualRecognitionService service = new VisualRecognitionService(client);
            var versionDate = "versionDate";

            service.VersionDate = versionDate;

            var customerId = "customerId";

            var result = service.DeleteUserData(customerId: customerId);

            request.Received().WithArgument("version", versionDate);
        }
        public void Setup()
        {
            Console.WriteLine(string.Format("\nSetting up test"));

            #region Get Credentials
            if (string.IsNullOrEmpty(credentials))
            {
                var    parentDirectory     = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.Parent.FullName;
                string credentialsFilepath = parentDirectory + Path.DirectorySeparatorChar + "sdk-credentials" + Path.DirectorySeparatorChar + "credentials.json";
                if (File.Exists(credentialsFilepath))
                {
                    try
                    {
                        credentials = File.ReadAllText(credentialsFilepath);
                        credentials = Utility.AddTopLevelObjectToJson(credentials, "VCAP_SERVICES");
                    }
                    catch (Exception e)
                    {
                        throw new Exception(string.Format("Failed to load credentials: {0}", e.Message));
                    }
                }
                else
                {
                    Console.WriteLine("Credentials file does not exist.");
                }

                VcapCredentials vcapCredentials = JsonConvert.DeserializeObject <VcapCredentials>(credentials);
                var             vcapServices    = JObject.Parse(credentials);

                Credential credential = vcapCredentials.GetCredentialByname("visual-recognition-iam-sdk")[0].Credentials;
                _endpoint = credential.Url;
                _apikey   = credential.IamApikey;
            }
            #endregion

            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = _apikey,
                ServiceUrl = _endpoint
            };
            _service = new VisualRecognitionService(tokenOptions, "2018-03-19");
            _service.Client.BaseClient.Timeout = TimeSpan.FromMinutes(120);
        }
        public void AddImages()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

            string trainingData = File.ReadAllText("training_data.json");
            var    result       = service.AddImages(
                collectionId: "60b4a98f-2472-4e2b-9c73-28bcaea6fa00",
                imageUrl: new List <string> {
                "https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/2018-Honda-Fit.jpg"
            },
                trainingData: trainingData
                );

            Console.WriteLine(result.Response);
        }
示例#29
0
        public void t16_AddCollectionImageMetadata_Success()
        {
            if (string.IsNullOrEmpty(_createdCollectionId))
                Assert.Fail("Created collection ID is null or empty.");

            if (string.IsNullOrEmpty(_addedImageId))
                Assert.Fail("Added image ID is null or empty.");

            VisualRecognitionService service = new VisualRecognitionService();
            service.SetCredential(apikey);

            using (FileStream metadataStream = File.OpenRead(_localImageMetadataPath))
            {
                var result = service.AddImageMetadata(_createdCollectionId, _addedImageId, metadataStream.ReadAllBytes());

                Assert.IsNotNull(result);
                Assert.IsTrue(result.Count > 0);
            }
        }
        public void t10_DeleteClassifier_Success()
        {
            if (string.IsNullOrEmpty(_createdClassifierId))
            {
                Assert.Fail("Created classsifier ID is null or empty.");
            }

            VisualRecognitionService _visualRecognition = new VisualRecognitionService(_apikey, _endpoint);

            _visualRecognition.Client.BaseClient.Timeout = TimeSpan.FromMinutes(60);

            #region Delay
            Delay(_delayTime);
            #endregion

            var result = _visualRecognition.DeleteClassifier(_createdClassifierId);

            Assert.IsNotNull(result);
        }