Paul Bird
commited on
Commit
·
8284277
1
Parent(s):
145a846
Upload RunYOLO.cs
Browse files- RunYOLO.cs +8 -11
RunYOLO.cs
CHANGED
@@ -21,7 +21,7 @@ public class RunYOLO : MonoBehaviour
|
|
21 |
const string videoName = "giraffes.mp4";
|
22 |
// Link the classes.txt here:
|
23 |
public TextAsset labelsAsset;
|
24 |
-
// Create a Raw Image of size 640x640 and link it here:
|
25 |
public RawImage displayImage;
|
26 |
// Link to a bounding box texture here:
|
27 |
public Sprite boxTexture;
|
@@ -115,42 +115,39 @@ public class RunYOLO : MonoBehaviour
|
|
115 |
{
|
116 |
var box = new BoundingBox
|
117 |
{
|
118 |
-
centerX = (output[n, 1] + output[n, 3]) / 2
|
119 |
-
centerY = (output[n, 2] + output[n, 4]) / 2
|
120 |
width = output[n, 3] - output[n, 1],
|
121 |
height = output[n, 4] - output[n, 2],
|
122 |
label = labels[(int)output[n, 5]],
|
123 |
-
confidence = output[n, 6]
|
124 |
};
|
125 |
DrawBox(box);
|
126 |
}
|
127 |
-
|
128 |
-
input.Dispose();
|
129 |
}
|
130 |
|
131 |
public void DrawBox(BoundingBox box)
|
132 |
{
|
133 |
Color color = Color.yellow;
|
134 |
|
135 |
-
|
|
|
136 |
panel.AddComponent<CanvasRenderer>();
|
137 |
Image img = panel.AddComponent<Image>();
|
138 |
img.color = color;
|
139 |
img.sprite = boxTexture;
|
140 |
-
|
141 |
panel.transform.SetParent(displayLocation, false);
|
142 |
panel.transform.localPosition = new Vector3(box.centerX, -box.centerY);
|
143 |
-
|
144 |
RectTransform rt = panel.GetComponent<RectTransform>();
|
145 |
rt.sizeDelta = new Vector2(box.width, box.height);
|
146 |
|
147 |
-
//
|
148 |
var text = new GameObject("ObjectLabel");
|
149 |
text.AddComponent<CanvasRenderer>();
|
150 |
Text txt = text.AddComponent<Text>();
|
151 |
text.transform.SetParent(panel.transform, false);
|
152 |
txt.font = font;
|
153 |
-
txt.text = box.label;
|
154 |
txt.color = color;
|
155 |
txt.fontSize = 40;
|
156 |
txt.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|
|
21 |
const string videoName = "giraffes.mp4";
|
22 |
// Link the classes.txt here:
|
23 |
public TextAsset labelsAsset;
|
24 |
+
// Create a Raw Image in the scene of size 640x640 and link it here:
|
25 |
public RawImage displayImage;
|
26 |
// Link to a bounding box texture here:
|
27 |
public Sprite boxTexture;
|
|
|
115 |
{
|
116 |
var box = new BoundingBox
|
117 |
{
|
118 |
+
centerX = (output[n, 1] + output[n, 3] - imageWidth) / 2,
|
119 |
+
centerY = (output[n, 2] + output[n, 4] - imageHeight) / 2,
|
120 |
width = output[n, 3] - output[n, 1],
|
121 |
height = output[n, 4] - output[n, 2],
|
122 |
label = labels[(int)output[n, 5]],
|
123 |
+
confidence = Mathf.FloorToInt(output[n, 6] * 100 + 0.5f)
|
124 |
};
|
125 |
DrawBox(box);
|
126 |
}
|
|
|
|
|
127 |
}
|
128 |
|
129 |
public void DrawBox(BoundingBox box)
|
130 |
{
|
131 |
Color color = Color.yellow;
|
132 |
|
133 |
+
//Create the bounding box graphic
|
134 |
+
var panel = new GameObject("ObjectBox");
|
135 |
panel.AddComponent<CanvasRenderer>();
|
136 |
Image img = panel.AddComponent<Image>();
|
137 |
img.color = color;
|
138 |
img.sprite = boxTexture;
|
|
|
139 |
panel.transform.SetParent(displayLocation, false);
|
140 |
panel.transform.localPosition = new Vector3(box.centerX, -box.centerY);
|
|
|
141 |
RectTransform rt = panel.GetComponent<RectTransform>();
|
142 |
rt.sizeDelta = new Vector2(box.width, box.height);
|
143 |
|
144 |
+
//Add the class label
|
145 |
var text = new GameObject("ObjectLabel");
|
146 |
text.AddComponent<CanvasRenderer>();
|
147 |
Text txt = text.AddComponent<Text>();
|
148 |
text.transform.SetParent(panel.transform, false);
|
149 |
txt.font = font;
|
150 |
+
txt.text = box.label + " (" + box.confidence + "%)";
|
151 |
txt.color = color;
|
152 |
txt.fontSize = 40;
|
153 |
txt.horizontalOverflow = HorizontalWrapMode.Overflow;
|