Reputation: 57
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!");
}
}
Upvotes: 1
Views: 251
Reputation: 1138
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.
Upvotes: 2