Skip to content

Commit f0e55f0

Browse files
committed
forrmat widgetExamples and unittest scripts
1 parent 3797720 commit f0e55f0

File tree

5 files changed

+469
-453
lines changed

5 files changed

+469
-453
lines changed

Examples/WidgetExamples/Scripts/ReverseNormals.cs

100644100755
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@
2020
[RequireComponent(typeof(MeshFilter))]
2121
public class ReverseNormals : MonoBehaviour
2222
{
23-
void Start()
24-
{
25-
MeshFilter meshFilter = GetComponent(typeof(MeshFilter)) as MeshFilter;
26-
if (meshFilter != null)
27-
{
28-
Mesh mesh = meshFilter.mesh;
23+
void Start()
24+
{
25+
MeshFilter meshFilter = GetComponent(typeof(MeshFilter)) as MeshFilter;
26+
if (meshFilter != null)
27+
{
28+
Mesh mesh = meshFilter.mesh;
2929

30-
Vector3[] normals = mesh.normals;
31-
for (int i = 0; i < normals.Length; i++)
32-
normals[i] = -normals[i];
33-
mesh.normals = normals;
30+
Vector3[] normals = mesh.normals;
31+
for (int i = 0; i < normals.Length; i++)
32+
normals[i] = -normals[i];
33+
mesh.normals = normals;
3434

35-
for (int m = 0; m < mesh.subMeshCount; m++)
36-
{
37-
int[] triangles = mesh.GetTriangles(m);
38-
for (int i = 0; i < triangles.Length; i += 3)
39-
{
40-
int temp = triangles[i + 0];
41-
triangles[i + 0] = triangles[i + 1];
42-
triangles[i + 1] = temp;
43-
}
44-
mesh.SetTriangles(triangles, m);
45-
}
46-
}
47-
}
35+
for (int m = 0; m < mesh.subMeshCount; m++)
36+
{
37+
int[] triangles = mesh.GetTriangles(m);
38+
for (int i = 0; i < triangles.Length; i += 3)
39+
{
40+
int temp = triangles[i + 0];
41+
triangles[i + 0] = triangles[i + 1];
42+
triangles[i + 1] = temp;
43+
}
44+
mesh.SetTriangles(triangles, m);
45+
}
46+
}
47+
}
4848
}

Examples/WidgetExamples/Scripts/WebCamRecognition.cs

Lines changed: 161 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -27,183 +27,183 @@
2727
/// </summary>
2828
public class WebCamRecognition : MonoBehaviour
2929
{
30-
#region Private Data
31-
[SerializeField]
32-
private WebCamWidget m_WebCamWidget;
33-
[SerializeField]
34-
private WebCamDisplayWidget m_WebCamDisplayWidget;
30+
#region Private Data
31+
[SerializeField]
32+
private WebCamWidget m_WebCamWidget;
33+
[SerializeField]
34+
private WebCamDisplayWidget m_WebCamDisplayWidget;
3535

36-
VisualRecognition m_VisualRecognition;
37-
#endregion
36+
VisualRecognition m_VisualRecognition;
37+
#endregion
38+
39+
void Start()
40+
{
41+
m_VisualRecognition = new VisualRecognition();
42+
}
43+
44+
#region Public Functions
45+
public void SaveFile()
46+
{
47+
Log.Debug("WebCamRecognition", "Attempting to save file!");
48+
Runnable.Run(SaveImageFile());
49+
}
50+
51+
public void SaveFile(string filePath = default(string), string fileName = default(string))
52+
{
53+
Log.Debug("WebCamRecognition", "Attempting to save file!");
54+
Runnable.Run(SaveImageFile(filePath, fileName));
55+
}
56+
57+
public void Classify()
58+
{
59+
Log.Debug("WebCamRecognition", "Attempting to classify image!");
60+
Runnable.Run(ClassifyImage());
61+
}
62+
63+
public void DetectFaces()
64+
{
65+
Log.Debug("WebCamRecognition", "Attempting to detect faces!");
66+
Runnable.Run(DetectFacesInImage());
67+
}
68+
69+
public void RecognizeText()
70+
{
71+
Log.Debug("WebCamRecognition", "Attempting to recognize text!");
72+
Runnable.Run(RecognizeTextInImage());
73+
}
74+
#endregion
75+
76+
77+
#region Private Functions
78+
private IEnumerator SaveImageFile(string filePath = default(string), string fileName = default(string))
79+
{
80+
yield return new WaitForEndOfFrame();
81+
82+
if (filePath == default(string))
83+
filePath = Application.dataPath + "/../";
84+
if (fileName == default(string))
85+
fileName = "WebCamImage.png";
86+
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
87+
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
88+
image.Apply();
89+
90+
File.WriteAllBytes(filePath + fileName, image.EncodeToPNG());
91+
92+
Log.Debug("WebCamRecognition", "File writeen to {0}{1}", filePath, fileName);
93+
}
94+
95+
private IEnumerator ClassifyImage()
96+
{
97+
yield return new WaitForEndOfFrame();
98+
99+
//Color32[] colors = m_WebCamWidget.WebCamTexture.GetPixels32();
100+
//byte[] rawImageData = Utility.Color32ArrayToByteArray(colors);
101+
102+
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
103+
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
104+
105+
byte[] imageData = image.EncodeToPNG();
106+
107+
m_VisualRecognition.Classify(OnClassify, imageData);
108+
}
109+
110+
private IEnumerator DetectFacesInImage()
111+
{
112+
yield return new WaitForEndOfFrame();
113+
114+
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
115+
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
116+
117+
byte[] imageData = image.EncodeToPNG();
118+
119+
m_VisualRecognition.DetectFaces(OnDetectFaces, imageData);
120+
}
121+
122+
private IEnumerator RecognizeTextInImage()
123+
{
124+
yield return new WaitForEndOfFrame();
125+
126+
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
127+
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
128+
129+
byte[] imageData = image.EncodeToPNG();
130+
131+
m_VisualRecognition.RecognizeText(OnRecognizeText, imageData);
132+
}
133+
#endregion
38134

39-
void Start()
135+
#region Event Handlers
136+
private void OnClassify(ClassifyTopLevelMultiple classify, string data)
137+
{
138+
if (classify != null)
40139
{
41-
m_VisualRecognition = new VisualRecognition();
42-
}
43-
44-
#region Public Functions
45-
public void SaveFile()
46-
{
47-
Log.Debug("WebCamRecognition", "Attempting to save file!");
48-
Runnable.Run(SaveImageFile());
49-
}
50-
51-
public void SaveFile(string filePath = default(string), string fileName = default(string))
52-
{
53-
Log.Debug("WebCamRecognition", "Attempting to save file!");
54-
Runnable.Run(SaveImageFile(filePath, fileName));
55-
}
56-
57-
public void Classify()
58-
{
59-
Log.Debug("WebCamRecognition", "Attempting to classify image!");
60-
Runnable.Run(ClassifyImage());
61-
}
62-
63-
public void DetectFaces()
64-
{
65-
Log.Debug("WebCamRecognition", "Attempting to detect faces!");
66-
Runnable.Run(DetectFacesInImage());
67-
}
68-
69-
public void RecognizeText()
70-
{
71-
Log.Debug("WebCamRecognition", "Attempting to recognize text!");
72-
Runnable.Run(RecognizeTextInImage());
73-
}
74-
#endregion
75-
76-
77-
#region Private Functions
78-
private IEnumerator SaveImageFile(string filePath = default(string), string fileName = default(string))
79-
{
80-
yield return new WaitForEndOfFrame();
81-
82-
if (filePath == default(string))
83-
filePath = Application.dataPath + "/../";
84-
if (fileName == default(string))
85-
fileName = "WebCamImage.png";
86-
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
87-
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
88-
image.Apply();
89-
90-
File.WriteAllBytes(filePath + fileName, image.EncodeToPNG());
91-
92-
Log.Debug("WebCamRecognition", "File writeen to {0}{1}", filePath, fileName);
93-
}
94-
95-
private IEnumerator ClassifyImage()
96-
{
97-
yield return new WaitForEndOfFrame();
98-
99-
//Color32[] colors = m_WebCamWidget.WebCamTexture.GetPixels32();
100-
//byte[] rawImageData = Utility.Color32ArrayToByteArray(colors);
101-
102-
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
103-
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
104-
105-
byte[] imageData = image.EncodeToPNG();
106-
107-
m_VisualRecognition.Classify(OnClassify, imageData);
108-
}
109-
110-
private IEnumerator DetectFacesInImage()
111-
{
112-
yield return new WaitForEndOfFrame();
113-
114-
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
115-
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
116-
117-
byte[] imageData = image.EncodeToPNG();
118-
119-
m_VisualRecognition.DetectFaces(OnDetectFaces, imageData);
140+
Log.Debug("WebCamRecognition", "images processed: " + classify.images_processed);
141+
foreach (ClassifyTopLevelSingle image in classify.images)
142+
{
143+
Log.Debug("WebCamRecognition", "\tsource_url: " + image.source_url + ", resolved_url: " + image.resolved_url);
144+
foreach (ClassifyPerClassifier classifier in image.classifiers)
145+
{
146+
Log.Debug("WebCamRecognition", "\t\tclassifier_id: " + classifier.classifier_id + ", name: " + classifier.name);
147+
foreach (ClassResult classResult in classifier.classes)
148+
Log.Debug("WebCamRecognition", "\t\t\tclass: " + classResult.m_class + ", score: " + classResult.score + ", type_hierarchy: " + classResult.type_hierarchy);
149+
}
150+
}
120151
}
121-
122-
private IEnumerator RecognizeTextInImage()
152+
else
123153
{
124-
yield return new WaitForEndOfFrame();
125-
126-
Texture2D image = new Texture2D(m_WebCamWidget.WebCamTexture.width, m_WebCamWidget.WebCamTexture.height, TextureFormat.RGB24, false);
127-
image.SetPixels32(m_WebCamWidget.WebCamTexture.GetPixels32());
128-
129-
byte[] imageData = image.EncodeToPNG();
130-
131-
m_VisualRecognition.RecognizeText(OnRecognizeText, imageData);
154+
Log.Debug("WebCamRecognition", "Classification failed!");
132155
}
133-
#endregion
156+
}
134157

135-
#region Event Handlers
136-
private void OnClassify(ClassifyTopLevelMultiple classify, string data)
158+
private void OnDetectFaces(FacesTopLevelMultiple multipleImages, string data)
159+
{
160+
if (multipleImages != null)
137161
{
138-
if (classify != null)
139-
{
140-
Log.Debug("WebCamRecognition", "images processed: " + classify.images_processed);
141-
foreach (ClassifyTopLevelSingle image in classify.images)
142-
{
143-
Log.Debug("WebCamRecognition", "\tsource_url: " + image.source_url + ", resolved_url: " + image.resolved_url);
144-
foreach (ClassifyPerClassifier classifier in image.classifiers)
145-
{
146-
Log.Debug("WebCamRecognition", "\t\tclassifier_id: " + classifier.classifier_id + ", name: " + classifier.name);
147-
foreach (ClassResult classResult in classifier.classes)
148-
Log.Debug("WebCamRecognition", "\t\t\tclass: " + classResult.m_class + ", score: " + classResult.score + ", type_hierarchy: " + classResult.type_hierarchy);
149-
}
150-
}
151-
}
152-
else
162+
Log.Debug("WebCamRecognition", "images processed: {0}", multipleImages.images_processed);
163+
foreach (FacesTopLevelSingle faces in multipleImages.images)
164+
{
165+
Log.Debug("WebCamRecognition", "\tsource_url: {0}, resolved_url: {1}", faces.source_url, faces.resolved_url);
166+
foreach (OneFaceResult face in faces.faces)
153167
{
154-
Log.Debug("WebCamRecognition", "Classification failed!");
168+
if (face.face_location != null)
169+
Log.Debug("WebCamRecognition", "\t\tFace location: {0}, {1}, {2}, {3}", face.face_location.left, face.face_location.top, face.face_location.width, face.face_location.height);
170+
if (face.gender != null)
171+
Log.Debug("WebCamRecognition", "\t\tGender: {0}, Score: {1}", face.gender.gender, face.gender.score);
172+
if (face.age != null)
173+
Log.Debug("WebCamRecognition", "\t\tAge Min: {0}, Age Max: {1}, Score: {2}", face.age.min, face.age.max, face.age.score);
174+
175+
if (face.identity != null)
176+
Log.Debug("WebCamRecognition", "\t\tName: {0}, Score: {1}, Type Heiarchy: {2}", face.identity.name, face.identity.score, face.identity.type_hierarchy);
155177
}
178+
}
156179
}
157-
158-
private void OnDetectFaces(FacesTopLevelMultiple multipleImages, string data)
180+
else
159181
{
160-
if (multipleImages != null)
161-
{
162-
Log.Debug("WebCamRecognition", "images processed: {0}", multipleImages.images_processed);
163-
foreach (FacesTopLevelSingle faces in multipleImages.images)
164-
{
165-
Log.Debug("WebCamRecognition", "\tsource_url: {0}, resolved_url: {1}", faces.source_url, faces.resolved_url);
166-
foreach (OneFaceResult face in faces.faces)
167-
{
168-
if(face.face_location != null)
169-
Log.Debug("WebCamRecognition", "\t\tFace location: {0}, {1}, {2}, {3}", face.face_location.left, face.face_location.top, face.face_location.width, face.face_location.height);
170-
if(face.gender != null)
171-
Log.Debug("WebCamRecognition", "\t\tGender: {0}, Score: {1}", face.gender.gender, face.gender.score);
172-
if(face.age != null)
173-
Log.Debug("WebCamRecognition", "\t\tAge Min: {0}, Age Max: {1}, Score: {2}", face.age.min, face.age.max, face.age.score);
174-
175-
if(face.identity != null)
176-
Log.Debug("WebCamRecognition", "\t\tName: {0}, Score: {1}, Type Heiarchy: {2}", face.identity.name, face.identity.score, face.identity.type_hierarchy);
177-
}
178-
}
179-
}
180-
else
181-
{
182-
Log.Debug("WebCamRecognition", "Detect faces failed!");
183-
}
182+
Log.Debug("WebCamRecognition", "Detect faces failed!");
184183
}
184+
}
185185

186-
private void OnRecognizeText(TextRecogTopLevelMultiple multipleImages, string data)
186+
private void OnRecognizeText(TextRecogTopLevelMultiple multipleImages, string data)
187+
{
188+
if (multipleImages != null)
187189
{
188-
if (multipleImages != null)
189-
{
190-
Log.Debug("WebCamRecognition", "images processed: {0}", multipleImages.images_processed);
191-
foreach (TextRecogTopLevelSingle texts in multipleImages.images)
192-
{
193-
Log.Debug("WebCamRecognition", "\tsource_url: {0}, resolved_url: {1}", texts.source_url, texts.resolved_url);
194-
Log.Debug("WebCamRecognition", "\ttext: {0}", texts.text);
195-
foreach (TextRecogOneWord text in texts.words)
196-
{
197-
Log.Debug("WebCamRecognition", "\t\ttext location: {0}, {1}, {2}, {3}", text.location.left, text.location.top, text.location.width, text.location.height);
198-
Log.Debug("WebCamRecognition", "\t\tLine number: {0}", text.line_number);
199-
Log.Debug("WebCamRecognition", "\t\tword: {0}, Score: {1}", text.word, text.score);
200-
}
201-
}
202-
}
203-
else
190+
Log.Debug("WebCamRecognition", "images processed: {0}", multipleImages.images_processed);
191+
foreach (TextRecogTopLevelSingle texts in multipleImages.images)
192+
{
193+
Log.Debug("WebCamRecognition", "\tsource_url: {0}, resolved_url: {1}", texts.source_url, texts.resolved_url);
194+
Log.Debug("WebCamRecognition", "\ttext: {0}", texts.text);
195+
foreach (TextRecogOneWord text in texts.words)
204196
{
205-
Log.Debug("WebCamRecognition", "RecognizeText failed!");
197+
Log.Debug("WebCamRecognition", "\t\ttext location: {0}, {1}, {2}, {3}", text.location.left, text.location.top, text.location.width, text.location.height);
198+
Log.Debug("WebCamRecognition", "\t\tLine number: {0}", text.line_number);
199+
Log.Debug("WebCamRecognition", "\t\tword: {0}, Score: {1}", text.word, text.score);
206200
}
201+
}
202+
}
203+
else
204+
{
205+
Log.Debug("WebCamRecognition", "RecognizeText failed!");
207206
}
208-
#endregion
207+
}
208+
#endregion
209209
}

0 commit comments

Comments
 (0)