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
ClassifyTopLevelMultiple
object contains an array ofClassifyTopLevelSingle
objects in theimages
property. Within each of thoseClassifyTopLevelSingle
objects, there is an array ofClassifyPerClassifier
objects which give you the result per custom classifier. EachClassifyPerClassifier
object has a list ofClassResult
objects which contain theclass
and 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
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.