1

I am trying to get the results of the Onclassify call into a usable format. I cannot seem figure out how to return classResult.m_class into a usable format such as updating a Text object or to store it in a variable.

Can someone please advise what is a good recommended way to pass the results from classResult.m_class for multiple or single classifiers into variables which I can action on later or pass on to other functions.

private void OnClassify(ClassifyTopLevelMultiple classify, string data)
{
    if (classify != null)
    {
        Log.Debug("WebCamRecognition", "images processed: " + classify.images_processed);
        foreach (ClassifyTopLevelSingle image in classify.images)
        {

            Log.Debug("WebCamRecognition", "\tsource_url: " + image.source_url + ", resolved_url: " + image.resolved_url);
            foreach (ClassifyPerClassifier classifier in image.classifiers) {

                Log.Debug ("WebCamRecognition", "\t\tclassifier_id: " + classifier.classifier_id + ", name: " + classifier.name);
                foreach (ClassResult classResult in classifier.classes) {
                    Log.Debug ("WebCamRecognition", "\t\t\tclass: " + classResult.m_class + ", score: " + classResult.score + ", type_hierarchy: " + classResult.type_hierarchy);
                }
            }
        }
    }
    else
    {
        Log.Debug("WebCamRecognition", "Classification failed!");
    }
}
mayo
  • 3,845
  • 1
  • 32
  • 42

1 Answers1

2

The ClassifyTopLevelMultiple object contains an array of ClassifyTopLevelSingle objects in the images property. Within each of those ClassifyTopLevelSingle objects, there is an array of ClassifyPerClassifier objects which give you the result per custom classifier. Each ClassifyPerClassifier object has a list of ClassResult objects which contain the class and the score.

You can pull out the class and the score for each result for the first item in each array like this:

private void OnClassifyGet(ClassifyTopLevelMultiple classify, string data)
{
    string class = classify.images[0].classifiers[0].classes[0].m_class;
    string classScore= classify.images[0].classifiers[0].classes[0].score;
}

The example code you posted will iterate through all images, classifiers and classes to list all classes and scores in each ClassifyTopLevelMultiple result.

Also it is worth noting that there is an updated version of the Watson Unity SDK. If you are just beginning a project it might be worth it to start with the latest SDK version since the latest release is a breaking change from all previous releases.

taj
  • 1,128
  • 1
  • 9
  • 23
  • thanks Taj ! I wasn't aware there was a new SDK. I Has the documentation been updated ? – Leon Moodley Sep 07 '17 at 10:17
  • just one thing i noticed taj in the code samples/snippets(https://github.com/watson-developer-cloud/unity-sdk/tree/develop/Scripts/Services/VisualRecognition/v3) you are referencing data but its not declaring the variable in the call. private void OnUpdateClassifier(GetClassifiersPerClassifierVerbose classifier) { Log.Debug("ExampleVisualRecognition", "Update classifier result: {0}", data); } – Leon Moodley Sep 07 '17 at 12:17
  • Data is a string you can pass any data through. If data is null when you initially make the call, I add the raw json that is returned from the service. It's an easy way to see what the object looks like. – taj Sep 07 '17 at 12:18
  • Taj just to confirm, my project is still using the previous unity SDK. Do i need to update this or will my code function as normal . For the last day or so the platform has indicated I am making too many concurrent http requests and I use the service on the Standard Package. there is no way I did more than 25 000 calls in one day. any advice ? – Leon Moodley Sep 08 '17 at 11:13
  • In my experience the limit for Visual Recognition is much lower than 25k API calls. This has nothing to do with the SDK. I think all users should update to the latest version of the Unity SDK. You should have minimal changes if you are only using Visual Recognition. – taj Sep 08 '17 at 11:17
  • Thanks Taj. I'll move over to the newer SDK anyways for consistency though I have to say I liked applying the service credentials in the drop down menu. Thanks for the great work on the SDK and for supporting Unity. – Leon Moodley Sep 08 '17 at 11:32