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() { // 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; }
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!"); } }