Paul Bird
commited on
Commit
•
905e832
1
Parent(s):
92c260e
Upload RunYOLO.cs
Browse files- RunYOLO.cs +13 -5
RunYOLO.cs
CHANGED
@@ -22,7 +22,7 @@ public class RunYOLO : MonoBehaviour
|
|
22 |
const string videoName = "giraffes.mp4";
|
23 |
// Link the classes.txt here:
|
24 |
public TextAsset labelsAsset;
|
25 |
-
// Create a Raw Image in the scene
|
26 |
public RawImage displayImage;
|
27 |
// Link to a bounding box texture here:
|
28 |
public Sprite boxTexture;
|
@@ -35,6 +35,8 @@ public class RunYOLO : MonoBehaviour
|
|
35 |
private string[] labels;
|
36 |
private RenderTexture targetRT;
|
37 |
const BackendType backend = BackendType.GPUCompute;
|
|
|
|
|
38 |
private const int imageWidth = 640;
|
39 |
private const int imageHeight = 640;
|
40 |
|
@@ -112,15 +114,21 @@ public class RunYOLO : MonoBehaviour
|
|
112 |
var output = engine.PeekOutput() as TensorFloat;
|
113 |
output.MakeReadable();
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
//Draw the bounding boxes
|
116 |
for (int n = 0; n < output.shape[0]; n++)
|
117 |
{
|
118 |
var box = new BoundingBox
|
119 |
{
|
120 |
-
centerX = (output[n, 1] + output[n, 3] -
|
121 |
-
centerY = (output[n, 2] + output[n, 4] -
|
122 |
-
width = output[n, 3] - output[n, 1],
|
123 |
-
height = output[n, 4] - output[n, 2],
|
124 |
label = labels[(int)output[n, 5]],
|
125 |
confidence = Mathf.FloorToInt(output[n, 6] * 100 + 0.5f)
|
126 |
};
|
|
|
22 |
const string videoName = "giraffes.mp4";
|
23 |
// Link the classes.txt here:
|
24 |
public TextAsset labelsAsset;
|
25 |
+
// Create a Raw Image in the scene and link it here:
|
26 |
public RawImage displayImage;
|
27 |
// Link to a bounding box texture here:
|
28 |
public Sprite boxTexture;
|
|
|
35 |
private string[] labels;
|
36 |
private RenderTexture targetRT;
|
37 |
const BackendType backend = BackendType.GPUCompute;
|
38 |
+
|
39 |
+
//Image size for the model
|
40 |
private const int imageWidth = 640;
|
41 |
private const int imageHeight = 640;
|
42 |
|
|
|
114 |
var output = engine.PeekOutput() as TensorFloat;
|
115 |
output.MakeReadable();
|
116 |
|
117 |
+
float displayWidth = displayImage.rectTransform.rect.width;
|
118 |
+
float displayHeight = displayImage.rectTransform.rect.height;
|
119 |
+
|
120 |
+
float scaleX = displayWidth / imageWidth;
|
121 |
+
float scaleY = displayHeight / imageHeight;
|
122 |
+
|
123 |
//Draw the bounding boxes
|
124 |
for (int n = 0; n < output.shape[0]; n++)
|
125 |
{
|
126 |
var box = new BoundingBox
|
127 |
{
|
128 |
+
centerX = ((output[n, 1] + output[n, 3])*scaleX - displayWidth) / 2,
|
129 |
+
centerY = ((output[n, 2] + output[n, 4])*scaleY - displayHeight) / 2,
|
130 |
+
width = (output[n, 3] - output[n, 1])*scaleX,
|
131 |
+
height = (output[n, 4] - output[n, 2])*scaleY,
|
132 |
label = labels[(int)output[n, 5]],
|
133 |
confidence = Mathf.FloorToInt(output[n, 6] * 100 + 0.5f)
|
134 |
};
|