private IEnumerator Examples() { // Get all classifiers Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiers(OnGetClassifiers, OnFail)) Log.Debug("ExampleVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); while (!_getClassifiersTested) yield return null; #if TRAIN_CLASSIFIER // Train classifier Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary<string, string> positiveExamples = new Dictionary<string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) Log.Debug("ExampleVisualRecognition.TrainClassifier()", "Failed to train classifier!"); while (!_trainClassifierTested) yield return null; // Find classifier by ID Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) Log.Debug("ExampleVisualRecognition.GetClassifier()", "Failed to get classifier!"); while (!_getClassifierTested) yield return null; #endif // Classify get Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) Log.Debug("ExampleVisualRecognition.Classify()", "Classify image failed!"); while (!_classifyGetTested) yield return null; // Classify post image Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) Log.Debug("ExampleVisualRecognition.Classify()", "Classify image failed!"); while (!_classifyPostTested) yield return null; // Detect faces get Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) Log.Debug("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!"); while (!_detectFacesGetTested) yield return null; // Detect faces post image Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) Log.Debug("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!"); while (!_detectFacesPostTested) yield return null; #if DELETE_TRAINED_CLASSIFIER #region Delay Runnable.Run(Delay(_delayTime)); while (_isWaitingForDelay) yield return null; #endregion // Delete classifier by ID Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) Log.Debug("ExampleVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); while (!_deleteClassifierTested) yield return null; #endif Log.Debug("ExampleVisualRecognition.Examples()", "Visual Recogition tests complete"); }
void Start() { LogSystem.InstallDefaultReactors(); // Get all classifiers if (!m_VisualRecognition.GetClassifiers(OnGetClassifiers)) { Log.Debug("ExampleVisualRecognition", "Getting classifiers failed!"); } // Find classifier by name m_VisualRecognition.FindClassifier(m_classifierName, OnFindClassifier); // Find classifier by ID if (!m_VisualRecognition.GetClassifier(m_classifierID, OnGetClassifier)) { Log.Debug("ExampleVisualRecognition", "Getting classifier failed!"); } // Delete classifier by ID if (!m_VisualRecognition.DeleteClassifier(m_classifierToDelete, OnDeleteClassifier)) { Log.Debug("ExampleVisualRecognition", "Deleting classifier failed!"); } // Train classifier string m_positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/taj_positive_examples.zip"; string m_negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/negative_examples.zip"; if (!m_VisualRecognition.TrainClassifier("unity-test-classifier5", "taj", m_positiveExamplesPath, m_negativeExamplesPath, OnTrainClassifier)) { Log.Debug("ExampleVisualRecognition", "Train classifier failed!"); } // Classify get if (!m_VisualRecognition.Classify(m_imageURL, OnClassify)) { Log.Debug("ExampleVisualRecognition", "Classify image failed!"); } // Classify post image string m_imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/obama.jpg"; string[] m_owners = { "IBM", "me" }; string[] m_classifierIDs = { "default" }; if (!m_VisualRecognition.Classify(OnClassify, m_imagesPath, m_owners, m_classifierIDs, 0.5f)) { Log.Debug("ExampleVisualRecognition", "Classify image failed!"); } // Detect faces get if (!m_VisualRecognition.DetectFaces(m_imageURL, OnDetectFaces)) { Log.Debug("ExampleVisualRecogntiion", "Detect faces failed!"); } // Detect faces post image string m_faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/obama.jpg"; if (!m_VisualRecognition.DetectFaces(OnDetectFaces, m_faceExamplePath)) { Log.Debug("ExampleVisualRecognition", "Detect faces failed!"); } // Recognize text get if (!m_VisualRecognition.RecognizeText(m_imageTextURL, OnRecognizeText)) { Log.Debug("ExampleVisualRecognition", "Recognize text failed!"); } // Recognize text post image string m_textExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/from_platos_apology.png"; if (!m_VisualRecognition.RecognizeText(OnRecognizeText, m_textExamplePath)) { Log.Debug("ExampleVisualRecognition", "Recognize text failed!"); } }
private string m_ImageTextURL = "http://i.stack.imgur.com/ZS6nH.png"; // image with text public override IEnumerator RunTest() { // test get classifiers Log.Debug("TestVisualRecognition", "Getting all classifiers!"); m_VisualRecognition.GetClassifiers(OnGetClassifiers); while (!m_GetClassifiersTested) { yield return(null); } // test find classifier Log.Debug("TestVisualRecognition", "Finding classifier {0}!", m_ClassifierName); m_VisualRecognition.FindClassifier(m_ClassifierName, OnFindClassifier); while (!m_FindClassifierTested) { yield return(null); } if (m_TrainClassifier) { // test train classifier Log.Debug("TestVisualRecognition", "Training classifier!"); string m_positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string m_negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Test(m_VisualRecognition.TrainClassifier(m_ClassifierName, "giraffe", m_positiveExamplesPath, m_negativeExamplesPath, OnTrainClassifier)); while (!m_TrainClasifierTested) { yield return(null); } Log.Debug("TestVisualRecognition", "Checking classifier {0} status!", m_ClassifierId); CheckClassifierStatus(OnCheckClassifierStatus); while (!m_IsClassifierReady) { yield return(null); } } if (!string.IsNullOrEmpty(m_ClassifierId)) { // test get classifier Log.Debug("TestVisualRecognition", "Getting classifier {0}!", m_ClassifierId); m_VisualRecognition.GetClassifier(m_ClassifierId, OnGetClassifier); while (!m_GetClassifierTested) { yield return(null); } string[] m_owners = { "IBM", "me" }; string[] m_classifierIds = { "default", m_ClassifierId }; // test classify image get Log.Debug("TestVisualRecognition", "Classifying image using GET!"); m_VisualRecognition.Classify(m_ImageURL, OnClassifyGet, m_owners, m_classifierIds); while (!m_ClassifyGETTested) { yield return(null); } // test classify image post Log.Debug("TestVisualRecognition", "Classifying image using POST!"); string m_classifyImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; m_VisualRecognition.Classify(OnClassifyPost, m_classifyImagePath, m_owners, m_classifierIds); while (!m_ClassifyPOSTTested) { yield return(null); } } // test detect faces get Log.Debug("TestVisualRecognition", "Detecting face image using GET!"); m_VisualRecognition.DetectFaces(m_ImageFaceURL, OnDetectFacesGet); while (!m_DetectFacesGETTested) { yield return(null); } // test detect faces post Log.Debug("TestVisualRecognition", "Detecting face image using POST!"); string m_detectFaceImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; m_VisualRecognition.DetectFaces(OnDetectFacesPost, m_detectFaceImagePath); while (!m_DetectFacesPOSTTested) { yield return(null); } // test recognize text get Log.Debug("TestVisualRecognition", "Recognizing text image using GET!"); m_VisualRecognition.RecognizeText(m_ImageTextURL, OnRecognizeTextGet); while (!m_RecognizeTextGETTested) { yield return(null); } // test recognize text post Log.Debug("TestVisualRecognition", "Recognizing text image using POST!"); string m_recognizeTextImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/from_platos_apology.png"; m_VisualRecognition.RecognizeText(OnRecognizeTextPost, m_recognizeTextImagePath); while (!m_RecognizeTextPOSTTested) { yield return(null); } // test delete classifier Log.Debug("TestVisualRecognition", "Deleting classifier {0}!", m_ClassifierId); m_VisualRecognition.DeleteClassifier(m_ClassifierId, OnDeleteClassifier); while (!m_DeleteTested) { yield return(null); } yield break; }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); try { VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; // Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format. // See https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html. var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES"); var fileContent = File.ReadAllText(environmentalVariable); // Add in a parent object because Unity does not like to deserialize root level collection types. fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(fileContent, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["visual_recognition"][TestCredentialIndex].Credentials; _apikey = credential.Apikey.ToString(); _url = credential.Url.ToString(); } catch { Log.Debug("TestVisualRecognition.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication"); } // Create credential and instantiate service Credentials credentials = new Credentials(_apikey, _url); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; // Get all classifiers Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiers(OnGetClassifiers, OnFail)) { Log.Debug("TestVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER // Train classifier Log.Debug("TestVisualRecognition.RunTest()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) { Log.Debug("TestVisualRecognition.TrainClassifier()", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) { Log.Debug("TestVisualRecognition.GetClassifier()", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } #endif // Classify get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyGetTested) { yield return(null); } // Classify post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyPostTested) { yield return(null); } // Detect faces get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesGetTested) { yield return(null); } // Detect faces post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesPostTested) { yield return(null); } #if DELETE_TRAINED_CLASSIFIER #region Delay Runnable.Run(Delay(_delayTime)); while (_isWaitingForDelay) { yield return(null); } #endregion // Delete classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) { Log.Debug("TestVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); } while (!_deleteClassifierTested) { yield return(null); } #endif Log.Debug("TestVisualRecognition.RunTest()", "Visual Recogition tests complete"); yield break; }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL"); var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME"); var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD"); using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword)) { while (!simpleGet.IsComplete) { yield return(null); } result = simpleGet.Result; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["visual_recognition"]; _apikey = credential.Apikey.ToString(); _url = credential.Url.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_apikey, _url); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; // Get all classifiers Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiers(OnGetClassifiers, OnFail)) { Log.Debug("TestVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER // Train classifier Log.Debug("TestVisualRecognition.RunTest()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) { Log.Debug("TestVisualRecognition.TrainClassifier()", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) { Log.Debug("TestVisualRecognition.GetClassifier()", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } #endif // Classify get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyGetTested) { yield return(null); } // Classify post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyPostTested) { yield return(null); } // Detect faces get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesGetTested) { yield return(null); } // Detect faces post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesPostTested) { yield return(null); } #if DELETE_TRAINED_CLASSIFIER #region Delay Runnable.Run(Delay(_delayTime)); while (_isWaitingForDelay) { yield return(null); } #endregion // Delete classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) { Log.Debug("TestVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); } while (!_deleteClassifierTested) { yield return(null); } #endif Log.Debug("TestVisualRecognition.RunTest()", "Visual Recogition tests complete"); yield break; }
public override IEnumerator RunTest() { // test get classifiers Log.Debug("TestVisualRecognition", "Getting all classifiers!"); m_VisualRecognition.GetClassifiers(OnGetClassifiers); while (!m_GetClassifiersTested) { yield return(null); } // test find classifier Log.Debug("TestVisualRecognition", "Finding classifier {0}!", m_ClassifierName); m_VisualRecognition.FindClassifier(OnFindClassifier, m_ClassifierName); while (!m_FindClassifierTested) { yield return(null); } if (m_TrainClassifier) { // test train classifier Log.Debug("TestVisualRecognition", "Training classifier!"); string m_positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string m_negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add(m_ClassName_Giraffe, m_positiveExamplesPath); Test(m_VisualRecognition.TrainClassifier(OnTrainClassifier, m_ClassifierName, positiveExamples, m_negativeExamplesPath)); while (!m_TrainClasifierTested) { yield return(null); } } // Wait until classifier is ready if (!m_IsClassifierReady) { Log.Debug("TestVisualRecognition", "Checking classifier {0} status!", m_ClassifierId); CheckClassifierStatus(OnCheckClassifierStatus); while (!m_IsClassifierReady) { yield return(null); } } if (!string.IsNullOrEmpty(m_ClassifierId)) { // test get classifier Log.Debug("TestVisualRecognition", "Getting classifier {0}!", m_ClassifierId); m_VisualRecognition.GetClassifier(OnGetClassifier, m_ClassifierId); while (!m_GetClassifierTested) { yield return(null); } // Update classifier Log.Debug("TestVisualRecognition", "Updating classifier {0}", m_ClassifierId); string m_positiveUpdated = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/turtle_positive_examples.zip"; Dictionary <string, string> positiveUpdatedExamples = new Dictionary <string, string>(); positiveUpdatedExamples.Add(m_ClassName_Turtle, m_positiveUpdated); m_VisualRecognition.UpdateClassifier(OnUpdateClassifier, m_ClassifierId, m_ClassifierName, positiveUpdatedExamples); while (!m_UpdateClassifierTested) { yield return(null); } // Wait for updated classifier to be ready. Log.Debug("TestVisualRecognition", "Checking updated classifier {0} status!", m_ClassifierId); CheckClassifierStatus(OnCheckUpdatedClassifierStatus); while (!m_IsUpdatedClassifierReady) { yield return(null); } string[] m_owners = { "IBM", "me" }; string[] m_classifierIds = { "default", m_ClassifierId }; // test classify image get Log.Debug("TestVisualRecognition", "Classifying image using GET!"); m_VisualRecognition.Classify(OnClassifyGet, m_ImageURL, m_owners, m_classifierIds); while (!m_ClassifyGETTested) { yield return(null); } // test classify image post Log.Debug("TestVisualRecognition", "Classifying image using POST!"); string m_classifyImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; m_VisualRecognition.Classify(m_classifyImagePath, OnClassifyPost, m_owners, m_classifierIds); while (!m_ClassifyPOSTTested) { yield return(null); } } // test detect faces get Log.Debug("TestVisualRecognition", "Detecting face image using GET!"); m_VisualRecognition.DetectFaces(OnDetectFacesGet, m_ImageFaceURL); while (!m_DetectFacesGETTested) { yield return(null); } // test detect faces post Log.Debug("TestVisualRecognition", "Detecting face image using POST!"); string m_detectFaceImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; m_VisualRecognition.DetectFaces(m_detectFaceImagePath, OnDetectFacesPost); while (!m_DetectFacesPOSTTested) { yield return(null); } // test recognize text get Log.Debug("TestVisualRecognition", "Recognizing text image using GET!"); m_VisualRecognition.RecognizeText(OnRecognizeTextGet, m_ImageTextURL); while (!m_RecognizeTextGETTested) { yield return(null); } // test recognize text post Log.Debug("TestVisualRecognition", "Recognizing text image using POST!"); string m_recognizeTextImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/from_platos_apology.png"; m_VisualRecognition.RecognizeText(m_recognizeTextImagePath, OnRecognizeTextPost); while (!m_RecognizeTextPOSTTested) { yield return(null); } // test delete classifier Log.Debug("TestVisualRecognition", "Deleting classifier {0}!", m_ClassifierId); m_VisualRecognition.DeleteClassifier(OnDeleteClassifier, m_ClassifierId); while (!m_DeleteClassifierTested) { yield return(null); } // test list collections Log.Debug("TestVisualRecognition", "Attempting to list collections!"); m_VisualRecognition.GetCollections(OnGetCollections); while (!m_ListCollectionsTested) { yield return(null); } // test create collection Log.Debug("TestVisualRecognition", "Attempting to create collection!"); m_VisualRecognition.CreateCollection(OnCreateCollection, "unity-integration-test-collection"); while (!m_CreateCollectionTested) { yield return(null); } // test retrive collection details Log.Debug("TestVisualRecognition", "Attempting to retrieve collection details!"); m_VisualRecognition.GetCollection(OnGetCollection, m_CreatedCollectionID); while (!m_RetrieveCollectionDetailsTested) { yield return(null); } // test add images to collection Log.Debug("TestVisualRecognition", "Attempting to add images to collection!"); string m_collectionImagePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; Dictionary <string, string> imageMetadata = new Dictionary <string, string>(); imageMetadata.Add("key1", "value1"); imageMetadata.Add("key2", "value2"); imageMetadata.Add("key3", "value3"); m_VisualRecognition.AddCollectionImage(OnAddImageToCollection, m_CreatedCollectionID, m_collectionImagePath, imageMetadata); while (!m_AddImagesToCollectionTested) { yield return(null); } // test list images Log.Debug("TestVisualRecognition", "Attempting to list images!"); m_VisualRecognition.GetCollectionImages(OnGetCollectionImages, m_CreatedCollectionID); while (!m_ListImagesTested) { yield return(null); } // test list image details Log.Debug("TestVisualRecognition", "Attempting to list image details!"); m_VisualRecognition.GetImage(OnGetImage, m_CreatedCollectionID, m_CreatedCollectionImage); while (!m_ListImageDetailsTested) { yield return(null); } // test list image metadata Log.Debug("TestVisualRecognition", "Attempting to list image metadata!"); m_VisualRecognition.GetMetadata(OnGetMetadata, m_CreatedCollectionID, m_CreatedCollectionImage); while (!m_ListImageMetadataTested) { yield return(null); } // test find similar Log.Debug("TestVisualRecognition", "Attempting to find similar!"); m_VisualRecognition.FindSimilar(OnFindSimilar, m_CreatedCollectionID, m_collectionImagePath); while (!m_FindSimilarTested) { yield return(null); } // test delete image metadata Log.Debug("TestVisualRecognition", "Attempting to delete metadata!"); m_VisualRecognition.DeleteCollectionImageMetadata(OnDeleteMetadata, m_CreatedCollectionID, m_CreatedCollectionImage); while (!m_DeleteImageMetadataTested) { yield return(null); } // test delete image from collection Log.Debug("TestVisualRecognition", "Attempting to delete image from collection!"); m_VisualRecognition.DeleteCollectionImage(OnDeleteCollectionImage, m_CreatedCollectionID, m_CreatedCollectionImage); while (!m_DeleteImageFromCollectionTested) { yield return(null); } // test delete collection Log.Debug("TestVisualRecognition", "Attempting to delete collection!"); m_VisualRecognition.DeleteCollection(OnDeleteCollection, m_CreatedCollectionID); while (!m_DeleteCollectionTested) { yield return(null); } yield break; }
private IEnumerator Examples() { // Get all classifiers Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiers(OnGetClassifiers, OnFail)) { Log.Debug("ExampleVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER // Train classifier Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) { Log.Debug("ExampleVisualRecognition.TrainClassifier()", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) { Log.Debug("ExampleVisualRecognition.GetClassifier()", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } #endif /* * // Classify get * Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to get classify via URL"); * if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) * Log.Debug("ExampleVisualRecognition.Classify()", "Classify image failed!"); * * while (!_classifyGetTested) * yield return null; * * // Classify post image * Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to classify via image on file system"); * string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; * string[] owners = { "IBM", "me" }; * string[] classifierIDs = { "default", _classifierID }; * if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) * Log.Debug("ExampleVisualRecognition.Classify()", "Classify image failed!"); * * while (!_classifyPostTested) * yield return null; * * // Detect faces get * Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to detect faces via URL"); * if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) * Log.Debug("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!"); * * while (!_detectFacesGetTested) * yield return null; * * // Detect faces post image * Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to detect faces via image"); * string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; * if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) * Log.Debug("ExampleVisualRecognition.DetectFaces()", "Detect faces failed!"); */ //Avishek Code //Take image from webcam and display results /*WebCamTexture webcamTex = new WebCamTexture(); * Color32Array colorArray = new Color32Array(); * colorArray.colors = new Color32[webcamTex.width * webcamTex.height]; * webcamTex.GetPixels32(colorArray.colors); * if (!_visualRecognition.Classify(OnClassifyGet, OnFail , colorArray.byteArray , "image/jpg")) * Log.Debug("ExampleVisualRecognition", "Classify image failed!"); * */ /*WebCamTexture webCamTexture = new WebCamTexture(); * //renderer.material.mainTexture = webCamTexture; * webCamTexture.Play(); * Texture2D photo = new Texture2D(webCamTexture.width, webCamTexture.height); * photo.SetPixels(webCamTexture.GetPixels()); * photo.Apply(); * byte[] bytes = photo.EncodeToPNG(); */ StartCoroutine("TakePhoto"); //Avishek code end while (!_detectFacesPostTested) { yield return(null); } #if DELETE_TRAINED_CLASSIFIER #region Delay Runnable.Run(Delay(_delayTime)); while (_isWaitingForDelay) { yield return(null); } #endregion // Delete classifier by ID Log.Debug("ExampleVisualRecognition.Examples()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) { Log.Debug("ExampleVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); } while (!_deleteClassifierTested) { yield return(null); } #endif Log.Debug("ExampleVisualRecognition.Examples()", "Visual Recogition tests complete"); }
private IEnumerator Examples() { // Get all classifiers Log.Debug("ExampleVisualRecognition", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiers(OnGetClassifiers)) { Log.Debug("ExampleVisualRecognition", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER // Train classifier Log.Debug("ExampleVisualRecognition", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) { Log.Debug("ExampleVisualRecognition", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("ExampleVisualRecognition", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, _classifierID)) { Log.Debug("ExampleVisualRecognition", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } #endif #if DELETE_TRAINED_CLASSIFIER // Delete classifier by ID Log.Debug("ExampleVisualRecognition", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, _classifierToDelete)) { Log.Debug("ExampleVisualRecognition", "Failed to delete classifier!"); } #endif while (!_deleteClassifierTested) { yield return(null); } // Classify get Log.Debug("ExampleVisualRecognition", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(OnClassifyGet, _imageURL)) { Log.Debug("ExampleVisualRecognition", "Classify image failed!"); } while (!_classifyGetTested) { yield return(null); } // Classify post image Log.Debug("ExampleVisualRecognition", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(imagesPath, OnClassifyPost, owners, classifierIDs, 0.5f)) { Log.Debug("ExampleVisualRecognition", "Classify image failed!"); } while (!_classifyPostTested) { yield return(null); } // Detect faces get Log.Debug("ExampleVisualRecognition", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(OnDetectFacesGet, _imageURL)) { Log.Debug("ExampleVisualRecogntiion", "Detect faces failed!"); } while (!_detectFacesGetTested) { yield return(null); } // Detect faces post image Log.Debug("ExampleVisualRecognition", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(faceExamplePath, OnDetectFacesPost)) { Log.Debug("ExampleVisualRecognition", "Detect faces failed!"); } while (!_detectFacesPostTested) { yield return(null); } //// Recognize text get //Log.Debug("ExampleVisualRecognition", "Attempting to recognizeText via URL"); //if (!_visualRecognition.RecognizeText(OnRecognizeTextGet, _imageTextURL)) // Log.Debug("ExampleVisualRecognition", "Recognize text failed!"); //while (!_recognizeTextGetTested) // yield return null; //// Recognize text post image //Log.Debug("ExampleVisualRecognition", "Attempting to recognizeText via image"); //string textExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/from_platos_apology.png"; //if (!_visualRecognition.RecognizeText(textExamplePath, OnRecognizeTextPost)) // Log.Debug("ExampleVisualRecognition", "Recognize text failed!"); //while (!_recognizeTextPostTested) // yield return null; Log.Debug("ExampleVisualRecognition", "Visual Recogition tests complete"); }