示例#1
0
        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;
        }