2121using IBM . Watson . DeveloperCloud . Logging ;
2222using IBM . Watson . DeveloperCloud . Utilities ;
2323
24- public class ExampleVisualRecognition : MonoBehaviour {
24+ public class ExampleVisualRecognition : MonoBehaviour
25+ {
2526 private VisualRecognition m_VisualRecognition = new VisualRecognition ( ) ;
2627 private string m_classifierName = "Apples_OptionalParams" ;
2728 private string m_classifierID = "ApplesClassifierNameWithSpaces_73100404" ;
2829 private string m_classifierToDelete = "unitytestclassifier2b_37849361" ;
2930 private string m_imageURL = "https://upload.wikimedia.org/wikipedia/commons/e/e9/Official_portrait_of_Barack_Obama.jpg" ;
3031 private string m_imageTextURL = "http://i.stack.imgur.com/ZS6nH.png" ;
31-
32- void Start ( )
32+
33+ void Start ( )
3334 {
3435 LogSystem . InstallDefaultReactors ( ) ;
3536
36- // Get all classifiers
37- if ( ! m_VisualRecognition . GetClassifiers ( OnGetClassifiers ) )
37+ // Get all classifiers
38+ if ( ! m_VisualRecognition . GetClassifiers ( OnGetClassifiers ) )
3839 Log . Debug ( "ExampleVisualRecognition" , "Getting classifiers failed!" ) ;
39- //
40- // Find classifier by name
40+ //
41+ // Find classifier by name
4142 m_VisualRecognition . FindClassifier ( m_classifierName , OnFindClassifier ) ;
4243
43- // Find classifier by ID
44- if ( ! m_VisualRecognition . GetClassifier ( m_classifierID , OnGetClassifier ) )
44+ // Find classifier by ID
45+ if ( ! m_VisualRecognition . GetClassifier ( m_classifierID , OnGetClassifier ) )
4546 Log . Debug ( "ExampleVisualRecognition" , "Getting classifier failed!" ) ;
4647
47- // Delete classifier by ID
48- if ( ! m_VisualRecognition . DeleteClassifier ( m_classifierToDelete , OnDeleteClassifier ) )
48+ // Delete classifier by ID
49+ if ( ! m_VisualRecognition . DeleteClassifier ( m_classifierToDelete , OnDeleteClassifier ) )
4950 Log . Debug ( "ExampleVisualRecognition" , "Deleting classifier failed!" ) ;
5051
51- // Train classifier
52+ // Train classifier
5253 string m_positiveExamplesPath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip" ;
5354 string m_negativeExamplesPath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip" ;
54- if ( ! m_VisualRecognition . TrainClassifier ( "unity-test-classifier5" , "giraffe" , m_positiveExamplesPath , m_negativeExamplesPath , OnTrainClassifier ) )
55+ if ( ! m_VisualRecognition . TrainClassifier ( "unity-test-classifier5" , "giraffe" , m_positiveExamplesPath , m_negativeExamplesPath , OnTrainClassifier ) )
5556 Log . Debug ( "ExampleVisualRecognition" , "Train classifier failed!" ) ;
5657
57- // Classify get
58- if ( ! m_VisualRecognition . Classify ( m_imageURL , OnClassify ) )
58+ // Classify get
59+ if ( ! m_VisualRecognition . Classify ( m_imageURL , OnClassify ) )
5960 Log . Debug ( "ExampleVisualRecognition" , "Classify image failed!" ) ;
6061
61- // Classify post image
62+ // Classify post image
6263 string m_imagesPath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg" ;
63- string [ ] m_owners = { "IBM" , "me" } ;
64- string [ ] m_classifierIDs = { "default" } ;
65- if ( ! m_VisualRecognition . Classify ( OnClassify , m_imagesPath , m_owners , m_classifierIDs , 0.5f ) )
64+ string [ ] m_owners = { "IBM" , "me" } ;
65+ string [ ] m_classifierIDs = { "default" } ;
66+ if ( ! m_VisualRecognition . Classify ( OnClassify , m_imagesPath , m_owners , m_classifierIDs , 0.5f ) )
6667 Log . Debug ( "ExampleVisualRecognition" , "Classify image failed!" ) ;
6768
6869
69- // Detect faces get
70- if ( ! m_VisualRecognition . DetectFaces ( m_imageURL , OnDetectFaces ) )
70+ // Detect faces get
71+ if ( ! m_VisualRecognition . DetectFaces ( m_imageURL , OnDetectFaces ) )
7172 Log . Debug ( "ExampleVisualRecogntiion" , "Detect faces failed!" ) ;
7273
73- // Detect faces post image
74+ // Detect faces post image
7475 string m_faceExamplePath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg" ;
75- if ( ! m_VisualRecognition . DetectFaces ( OnDetectFaces , m_faceExamplePath ) )
76+ if ( ! m_VisualRecognition . DetectFaces ( OnDetectFaces , m_faceExamplePath ) )
7677 Log . Debug ( "ExampleVisualRecognition" , "Detect faces failed!" ) ;
7778
7879
7980
80- // Recognize text get
81- if ( ! m_VisualRecognition . RecognizeText ( m_imageTextURL , OnRecognizeText ) )
81+ // Recognize text get
82+ if ( ! m_VisualRecognition . RecognizeText ( m_imageTextURL , OnRecognizeText ) )
8283 Log . Debug ( "ExampleVisualRecognition" , "Recognize text failed!" ) ;
8384
84- // Recognize text post image
85+ // Recognize text post image
8586 string m_textExamplePath = Application . dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/from_platos_apology.png" ;
86- if ( ! m_VisualRecognition . RecognizeText ( OnRecognizeText , m_textExamplePath ) )
87+ if ( ! m_VisualRecognition . RecognizeText ( OnRecognizeText , m_textExamplePath ) )
8788 Log . Debug ( "ExampleVisualRecognition" , "Recognize text failed!" ) ;
88- }
89+ }
8990
90- private void OnGetClassifiers ( GetClassifiersTopLevelBrief classifiers )
91+ private void OnGetClassifiers ( GetClassifiersTopLevelBrief classifiers )
9192 {
92- if ( classifiers != null && classifiers . classifiers . Length > 0 )
93+ if ( classifiers != null && classifiers . classifiers . Length > 0 )
9394 {
94- foreach ( GetClassifiersPerClassifierBrief classifier in classifiers . classifiers )
95+ foreach ( GetClassifiersPerClassifierBrief classifier in classifiers . classifiers )
9596 {
9697 Log . Debug ( "ExampleVisualRecognition" , "Classifier: " + classifier . name + ", " + classifier . classifier_id ) ;
9798 }
@@ -104,7 +105,7 @@ private void OnGetClassifiers (GetClassifiersTopLevelBrief classifiers)
104105
105106 private void OnFindClassifier ( GetClassifiersPerClassifierVerbose classifier )
106107 {
107- if ( classifier != null )
108+ if ( classifier != null )
108109 {
109110 Log . Debug ( "ExampleVisualRecognition" , "Classifier " + m_classifierName + " found! ClassifierID: " + classifier . classifier_id ) ;
110111 }
@@ -116,7 +117,7 @@ private void OnFindClassifier(GetClassifiersPerClassifierVerbose classifier)
116117
117118 private void OnGetClassifier ( GetClassifiersPerClassifierVerbose classifier )
118119 {
119- if ( classifier != null )
120+ if ( classifier != null )
120121 {
121122 Log . Debug ( "ExampleVisualRecognition" , "Classifier " + m_classifierID + " found! Classifier name: " + classifier . name ) ;
122123 }
@@ -128,7 +129,7 @@ private void OnGetClassifier(GetClassifiersPerClassifierVerbose classifier)
128129
129130 private void OnDeleteClassifier ( bool success )
130131 {
131- if ( success )
132+ if ( success )
132133 {
133134 Log . Debug ( "ExampleVisualRecognition" , "Deleted classifier " + m_classifierToDelete ) ;
134135 }
@@ -137,10 +138,10 @@ private void OnDeleteClassifier(bool success)
137138 Log . Debug ( "ExampleVisualRecognition" , "Failed to delete classifier by ID!" ) ;
138139 }
139140 }
140-
141+
141142 private void OnTrainClassifier ( GetClassifiersPerClassifierVerbose classifier )
142143 {
143- if ( classifier != null )
144+ if ( classifier != null )
144145 {
145146 Log . Debug ( "ExampleVisualRecognition" , "Classifier is training! " + classifier ) ;
146147 }
@@ -152,16 +153,16 @@ private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier)
152153
153154 private void OnClassify ( ClassifyTopLevelMultiple classify )
154155 {
155- if ( classify != null )
156+ if ( classify != null )
156157 {
157158 Log . Debug ( "ExampleVisualRecognition" , "images processed: " + classify . images_processed ) ;
158- foreach ( ClassifyTopLevelSingle image in classify . images )
159+ foreach ( ClassifyTopLevelSingle image in classify . images )
159160 {
160161 Log . Debug ( "ExampleVisualRecognition" , "\t source_url: " + image . source_url + ", resolved_url: " + image . resolved_url ) ;
161- foreach ( ClassifyPerClassifier classifier in image . classifiers )
162+ foreach ( ClassifyPerClassifier classifier in image . classifiers )
162163 {
163164 Log . Debug ( "ExampleVisualRecognition" , "\t \t classifier_id: " + classifier . classifier_id + ", name: " + classifier . name ) ;
164- foreach ( ClassResult classResult in classifier . classes )
165+ foreach ( ClassResult classResult in classifier . classes )
165166 Log . Debug ( "ExampleVisualRecognition" , "\t \t \t class: " + classResult . m_class + ", score: " + classResult . score + ", type_hierarchy: " + classResult . type_hierarchy ) ;
166167 }
167168 }
@@ -174,13 +175,13 @@ private void OnClassify(ClassifyTopLevelMultiple classify)
174175
175176 private void OnDetectFaces ( FacesTopLevelMultiple multipleImages )
176177 {
177- if ( multipleImages != null )
178+ if ( multipleImages != null )
178179 {
179180 Log . Debug ( "ExampleVisualRecognition" , "images processed: {0}" , multipleImages . images_processed ) ;
180- foreach ( FacesTopLevelSingle faces in multipleImages . images )
181+ foreach ( FacesTopLevelSingle faces in multipleImages . images )
181182 {
182183 Log . Debug ( "ExampleVisualRecognition" , "\t source_url: {0}, resolved_url: {1}" , faces . source_url , faces . resolved_url ) ;
183- foreach ( OneFaceResult face in faces . faces )
184+ foreach ( OneFaceResult face in faces . faces )
184185 {
185186 Log . Debug ( "ExampleVisulaRecognition" , "\t \t Face location: {0}, {1}, {2}, {3}" , face . face_location . left , face . face_location . top , face . face_location . width , face . face_location . height ) ;
186187 Log . Debug ( "ExampleVisulaRecognition" , "\t \t Gender: {0}, Score: {1}" , face . gender . gender , face . gender . score ) ;
@@ -197,14 +198,14 @@ private void OnDetectFaces(FacesTopLevelMultiple multipleImages)
197198
198199 private void OnRecognizeText ( TextRecogTopLevelMultiple multipleImages )
199200 {
200- if ( multipleImages != null )
201+ if ( multipleImages != null )
201202 {
202203 Log . Debug ( "ExampleVisualRecognition" , "images processed: {0}" , multipleImages . images_processed ) ;
203- foreach ( TextRecogTopLevelSingle texts in multipleImages . images )
204+ foreach ( TextRecogTopLevelSingle texts in multipleImages . images )
204205 {
205206 Log . Debug ( "ExampleVisualRecognition" , "\t source_url: {0}, resolved_url: {1}" , texts . source_url , texts . resolved_url ) ;
206207 Log . Debug ( "ExampleVisualRecognition" , "\t text: {0}" , texts . text ) ;
207- foreach ( TextRecogOneWord text in texts . words )
208+ foreach ( TextRecogOneWord text in texts . words )
208209 {
209210 Log . Debug ( "ExampleVisulaRecognition" , "\t \t text location: {0}, {1}, {2}, {3}" , text . location . left , text . location . top , text . location . width , text . location . height ) ;
210211 Log . Debug ( "ExampleVisulaRecognition" , "\t \t Line number: {0}" , text . line_number ) ;
0 commit comments