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!");
}
}
The
ClassifyTopLevelMultipleobject contains an array ofClassifyTopLevelSingleobjects in theimagesproperty. Within each of thoseClassifyTopLevelSingleobjects, there is an array ofClassifyPerClassifierobjects which give you the result per custom classifier. EachClassifyPerClassifierobject has a list ofClassResultobjects which contain theclassand thescore.You can pull out the class and the score for each result for the first item in each array like this:
The example code you posted will iterate through all images, classifiers and classes to list all classes and scores in each
ClassifyTopLevelMultipleresult.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.