v1.0.6 Updated OpenCVForUnity version to 2.6.4. Change to image source input using MultiSource2MatHelper.
This commit is contained in:
Родитель
703ffecfa6
Коммит
92c4c4a2d0
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a884551bcad0b3f408d0c747915242b4
|
||||
guid: 89ee7c1476759804386ac6d9280f8776
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
Двоичные данные
Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample/TestVideos/6130363-sd_960_540_30fps.mp4
Normal file
Двоичные данные
Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample/TestVideos/6130363-sd_960_540_30fps.mp4
Normal file
Двоичный файл не отображается.
|
@ -1,8 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2698d63d6eb926847b0236e1917fe982
|
||||
NativeFormatImporter:
|
||||
guid: b78b2aa0f131b4b4d9c76196d5f1b8b4
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Двоичные данные
Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample/TestVideos/ObjectDetection_TestVideo_640_640_30fps.mp4
Normal file
Двоичные данные
Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample/TestVideos/ObjectDetection_TestVideo_640_640_30fps.mp4
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4c812c234a69e2a42b0e4df3fdf9f3ba
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Двоичный файл не отображается.
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 20a78f65a0b05a84c92b1cd7e9fef52f
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Двоичные данные
Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample/TestVideos/pexels-taryn-elliott-3770033-960x540-25fps.mp4
Normal file
Двоичные данные
Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample/TestVideos/pexels-taryn-elliott-3770033-960x540-25fps.mp4
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a3f15479abab80c4ab7adcc8828e5193
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,29 +0,0 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_Name: quad_material
|
||||
m_Shader: {fileID: 10750, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 5
|
||||
m_CustomRenderQueue: -1
|
||||
m_SavedProperties:
|
||||
serializedVersion: 2
|
||||
m_TexEnvs:
|
||||
data:
|
||||
first:
|
||||
name: _MainTex
|
||||
second:
|
||||
m_Texture: {fileID: 2800000, guid: 2babf6b881d10a647baa8b69d9e48aad, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats: {}
|
||||
m_Colors:
|
||||
data:
|
||||
first:
|
||||
name: _Color
|
||||
second: {r: 1, g: 1, b: 1, a: 1}
|
|
@ -1,9 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YOLOv5WithOpenCVForUnityExample
|
||||
{
|
||||
// v1.0.1
|
||||
// v1.0.2
|
||||
public class FpsMonitor : MonoBehaviour
|
||||
{
|
||||
int tick = 0;
|
||||
|
@ -26,7 +26,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
const float MARGIN_Y = 10f;
|
||||
const float INNER_X = 8f;
|
||||
const float INNER_Y = 5f;
|
||||
const float GUI_CONSOLE_HEIGHT = 50f;
|
||||
const float GUI_CONSOLE_HEIGHT = 100f;
|
||||
|
||||
public Vector2 offset = new Vector2(MARGIN_X, MARGIN_Y);
|
||||
public bool boxVisible = true;
|
||||
|
@ -123,7 +123,8 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
|
||||
if (!string.IsNullOrEmpty(consoleText))
|
||||
{
|
||||
if (toast_time != 0) {
|
||||
if (toast_time != 0)
|
||||
{
|
||||
if (boxVisible)
|
||||
{
|
||||
GUI.Box(console_outer, "");
|
||||
|
|
|
@ -14,6 +14,8 @@ using OpenCVForUnity.UnityUtils;
|
|||
using OpenCVForUnity.UnityUtils.Helper;
|
||||
using YOLOv5WithOpenCVForUnity;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace YOLOv5WithOpenCVForUnityExample
|
||||
{
|
||||
|
@ -22,9 +24,16 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// Referring to https://github.com/ultralytics/yolov5.
|
||||
/// https://github.com/ultralytics/yolov5/blob/master/classify/predict.py
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(WebCamTextureToMatHelper))]
|
||||
[RequireComponent(typeof(MultiSource2MatHelper))]
|
||||
public class YOLOv5ClassificationExample : MonoBehaviour
|
||||
{
|
||||
[Header("Output")]
|
||||
/// <summary>
|
||||
/// The RawImage for previewing the result.
|
||||
/// </summary>
|
||||
public RawImage resultPreview;
|
||||
|
||||
[Space(10)]
|
||||
|
||||
[TooltipAttribute("Path to a binary file of model contains trained weights.")]
|
||||
public string model = "yolov5n-cls.onnx";
|
||||
|
@ -38,20 +47,15 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
[TooltipAttribute("Preprocess input image by resizing to a specific height.")]
|
||||
public int inpHeight = 224;
|
||||
|
||||
[Header("TEST")]
|
||||
|
||||
[TooltipAttribute("Path to test input image.")]
|
||||
public string testInputImage;
|
||||
|
||||
/// <summary>
|
||||
/// The texture.
|
||||
/// </summary>
|
||||
protected Texture2D texture;
|
||||
|
||||
/// <summary>
|
||||
/// The webcam texture to mat helper.
|
||||
/// The multi source to mat helper.
|
||||
/// </summary>
|
||||
protected WebCamTextureToMatHelper webCamTextureToMatHelper;
|
||||
protected MultiSource2MatHelper multiSource2MatHelper;
|
||||
|
||||
/// <summary>
|
||||
/// The bgr mat.
|
||||
|
@ -71,65 +75,33 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
protected string classes_filepath;
|
||||
protected string model_filepath;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
protected IEnumerator getFilePath_Coroutine;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// The CancellationTokenSource.
|
||||
/// </summary>
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
// Use this for initialization
|
||||
protected virtual void Start()
|
||||
async void Start()
|
||||
{
|
||||
fpsMonitor = GetComponent<FpsMonitor>();
|
||||
|
||||
webCamTextureToMatHelper = gameObject.GetComponent<WebCamTextureToMatHelper>();
|
||||
multiSource2MatHelper = gameObject.GetComponent<MultiSource2MatHelper>();
|
||||
multiSource2MatHelper.outputColorFormat = Source2MatHelperColorFormat.RGBA;
|
||||
|
||||
// Asynchronously retrieves the readable file path from the StreamingAssets directory.
|
||||
if (fpsMonitor != null)
|
||||
fpsMonitor.consoleText = "Preparing file access...";
|
||||
|
||||
#if UNITY_WEBGL
|
||||
getFilePath_Coroutine = GetFilePath();
|
||||
StartCoroutine(getFilePath_Coroutine);
|
||||
#else
|
||||
if (!string.IsNullOrEmpty(classes))
|
||||
{
|
||||
classes_filepath = Utils.getFilePath("YOLOv5WithOpenCVForUnityExample/" + classes);
|
||||
if (string.IsNullOrEmpty(classes_filepath)) Debug.Log("The file:" + classes + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
classes_filepath = await Utils.getFilePathAsyncTask("YOLOv5WithOpenCVForUnityExample/" + classes, cancellationToken: cts.Token);
|
||||
if (!string.IsNullOrEmpty(model))
|
||||
{
|
||||
model_filepath = Utils.getFilePath("YOLOv5WithOpenCVForUnityExample/" + model);
|
||||
if (string.IsNullOrEmpty(model_filepath)) Debug.Log("The file:" + model + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
Run();
|
||||
#endif
|
||||
}
|
||||
model_filepath = await Utils.getFilePathAsyncTask("YOLOv5WithOpenCVForUnityExample/" + model, cancellationToken: cts.Token);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
protected virtual IEnumerator GetFilePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(classes))
|
||||
{
|
||||
var getFilePathAsync_0_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + classes, (result) =>
|
||||
{
|
||||
classes_filepath = result;
|
||||
});
|
||||
yield return getFilePathAsync_0_Coroutine;
|
||||
|
||||
if (string.IsNullOrEmpty(classes_filepath)) Debug.Log("The file:" + classes + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model))
|
||||
{
|
||||
var getFilePathAsync_1_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + model, (result) =>
|
||||
{
|
||||
model_filepath = result;
|
||||
});
|
||||
yield return getFilePathAsync_1_Coroutine;
|
||||
|
||||
if (string.IsNullOrEmpty(model_filepath)) Debug.Log("The file:" + model + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
|
||||
getFilePath_Coroutine = null;
|
||||
if (fpsMonitor != null)
|
||||
fpsMonitor.consoleText = "";
|
||||
|
||||
Run();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this for initialization
|
||||
protected virtual void Run()
|
||||
|
@ -146,131 +118,40 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
classPredictor = new YOLOv5ClassPredictor(model_filepath, classes_filepath, new Size(inpWidth, inpHeight));
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(testInputImage))
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
// Avoids the front camera low light issue that occurs in only some Android devices (e.g. Google Pixel, Pixel2).
|
||||
webCamTextureToMatHelper.avoidAndroidFrontCameraLowLightIssue = true;
|
||||
#endif
|
||||
webCamTextureToMatHelper.Initialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
/////////////////////
|
||||
// TEST
|
||||
|
||||
var getFilePathAsync_0_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + testInputImage, (result) =>
|
||||
{
|
||||
string test_input_image_filepath = result;
|
||||
if (string.IsNullOrEmpty(test_input_image_filepath)) Debug.Log("The file:" + testInputImage + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
|
||||
Mat img = Imgcodecs.imread(test_input_image_filepath);
|
||||
if (img.empty())
|
||||
{
|
||||
img = new Mat(424, 640, CvType.CV_8UC3, new Scalar(0, 0, 0));
|
||||
Imgproc.putText(img, testInputImage + " is not loaded.", new Point(5, img.rows() - 30), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
|
||||
Imgproc.putText(img, "Please read console message.", new Point(5, img.rows() - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
TickMeter tm = new TickMeter();
|
||||
tm.start();
|
||||
|
||||
Mat results = classPredictor.infer(img);
|
||||
|
||||
tm.stop();
|
||||
Debug.Log("YOLOv5ClassPredictor Inference time (preprocess + infer + postprocess), ms: " + tm.getTimeMilli());
|
||||
|
||||
classPredictor.visualize(img, results, true, false);
|
||||
|
||||
if (fpsMonitor != null)
|
||||
{
|
||||
var sortedData = classPredictor.getSortedData(results, 5);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < sortedData.Length; ++i)
|
||||
{
|
||||
sb.AppendLine((i + 1) + ". " + classPredictor.getClassLabel(sortedData[i].cls) + ", " + sortedData[i]);
|
||||
}
|
||||
fpsMonitor.consoleText = sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
gameObject.transform.localScale = new Vector3(img.width(), img.height(), 1);
|
||||
float imageWidth = img.width();
|
||||
float imageHeight = img.height();
|
||||
float widthScale = (float)Screen.width / imageWidth;
|
||||
float heightScale = (float)Screen.height / imageHeight;
|
||||
if (widthScale < heightScale)
|
||||
{
|
||||
Camera.main.orthographicSize = (imageWidth * (float)Screen.height / (float)Screen.width) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera.main.orthographicSize = imageHeight / 2;
|
||||
}
|
||||
|
||||
Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2RGB);
|
||||
Texture2D texture = new Texture2D(img.cols(), img.rows(), TextureFormat.RGB24, false);
|
||||
Utils.matToTexture2D(img, texture);
|
||||
gameObject.GetComponent<Renderer>().material.mainTexture = texture;
|
||||
|
||||
});
|
||||
StartCoroutine(getFilePathAsync_0_Coroutine);
|
||||
|
||||
/////////////////////
|
||||
}
|
||||
multiSource2MatHelper.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper initialized event.
|
||||
/// Raises the source to mat helper initialized event.
|
||||
/// </summary>
|
||||
public virtual void OnWebCamTextureToMatHelperInitialized()
|
||||
public virtual void OnSourceToMatHelperInitialized()
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperInitialized");
|
||||
Debug.Log("OnSourceToMatHelperInitialized");
|
||||
|
||||
Mat webCamTextureMat = webCamTextureToMatHelper.GetMat();
|
||||
Mat rgbaMat = multiSource2MatHelper.GetMat();
|
||||
|
||||
texture = new Texture2D(rgbaMat.cols(), rgbaMat.rows(), TextureFormat.RGBA32, false);
|
||||
|
||||
texture = new Texture2D(webCamTextureMat.cols(), webCamTextureMat.rows(), TextureFormat.RGBA32, false);
|
||||
resultPreview.texture = texture;
|
||||
resultPreview.GetComponent<AspectRatioFitter>().aspectRatio = (float)texture.width / texture.height;
|
||||
|
||||
gameObject.GetComponent<Renderer>().material.mainTexture = texture;
|
||||
|
||||
gameObject.transform.localScale = new Vector3(webCamTextureMat.cols(), webCamTextureMat.rows(), 1);
|
||||
Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
|
||||
|
||||
if (fpsMonitor != null)
|
||||
{
|
||||
fpsMonitor.Add("width", webCamTextureMat.width().ToString());
|
||||
fpsMonitor.Add("height", webCamTextureMat.height().ToString());
|
||||
fpsMonitor.Add("width", rgbaMat.width().ToString());
|
||||
fpsMonitor.Add("height", rgbaMat.height().ToString());
|
||||
fpsMonitor.Add("orientation", Screen.orientation.ToString());
|
||||
}
|
||||
|
||||
|
||||
float width = webCamTextureMat.width();
|
||||
float height = webCamTextureMat.height();
|
||||
|
||||
float widthScale = (float)Screen.width / width;
|
||||
float heightScale = (float)Screen.height / height;
|
||||
if (widthScale < heightScale)
|
||||
{
|
||||
Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera.main.orthographicSize = height / 2;
|
||||
}
|
||||
|
||||
|
||||
bgrMat = new Mat(webCamTextureMat.rows(), webCamTextureMat.cols(), CvType.CV_8UC3);
|
||||
bgrMat = new Mat(rgbaMat.rows(), rgbaMat.cols(), CvType.CV_8UC3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper disposed event.
|
||||
/// Raises the source to mat helper disposed event.
|
||||
/// </summary>
|
||||
public virtual void OnWebCamTextureToMatHelperDisposed()
|
||||
public virtual void OnSourceToMatHelperDisposed()
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperDisposed");
|
||||
Debug.Log("OnSourceToMatHelperDisposed");
|
||||
|
||||
if (bgrMat != null)
|
||||
bgrMat.Dispose();
|
||||
|
@ -283,21 +164,27 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper error occurred event.
|
||||
/// Raises the source to mat helper error occurred event.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">Error code.</param>
|
||||
public virtual void OnWebCamTextureToMatHelperErrorOccurred(WebCamTextureToMatHelper.ErrorCode errorCode)
|
||||
/// <param name="message">Message.</param>
|
||||
public void OnSourceToMatHelperErrorOccurred(Source2MatHelperErrorCode errorCode, string message)
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperErrorOccurred " + errorCode);
|
||||
Debug.Log("OnSourceToMatHelperErrorOccurred " + errorCode + ":" + message);
|
||||
|
||||
if (fpsMonitor != null)
|
||||
{
|
||||
fpsMonitor.consoleText = "ErrorCode: " + errorCode + ":" + message;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
|
||||
if (multiSource2MatHelper.IsPlaying() && multiSource2MatHelper.DidUpdateThisFrame())
|
||||
{
|
||||
|
||||
Mat rgbaMat = webCamTextureToMatHelper.GetMat();
|
||||
Mat rgbaMat = multiSource2MatHelper.GetMat();
|
||||
|
||||
if (classPredictor == null)
|
||||
{
|
||||
|
@ -343,20 +230,15 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
webCamTextureToMatHelper.Dispose();
|
||||
multiSource2MatHelper.Dispose();
|
||||
|
||||
if (classPredictor != null)
|
||||
classPredictor.dispose();
|
||||
|
||||
Utils.setDebugMode(false);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
if (getFilePath_Coroutine != null)
|
||||
{
|
||||
StopCoroutine(getFilePath_Coroutine);
|
||||
((IDisposable)getFilePath_Coroutine).Dispose();
|
||||
}
|
||||
#endif
|
||||
if (cts != null)
|
||||
cts.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -372,7 +254,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnPlayButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Play();
|
||||
multiSource2MatHelper.Play();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -380,7 +262,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnPauseButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Pause();
|
||||
multiSource2MatHelper.Pause();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -388,7 +270,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnStopButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Stop();
|
||||
multiSource2MatHelper.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -396,7 +278,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnChangeCameraButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
|
||||
multiSource2MatHelper.requestedIsFrontFacing = !multiSource2MatHelper.requestedIsFrontFacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,6 +152,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 558168709}
|
||||
m_RootOrder: 0
|
||||
|
@ -234,7 +235,9 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0, y: 0, z: 0}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1323128750}
|
||||
- {fileID: 693261578}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
|
@ -304,6 +307,7 @@ Canvas:
|
|||
m_OverrideSorting: 0
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_VertexColorAlwaysGammaSpace: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
|
@ -338,10 +342,11 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 305605057}
|
||||
m_Father: {fileID: 693261578}
|
||||
m_RootOrder: 1
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
|
@ -491,14 +496,15 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1542903296}
|
||||
- {fileID: 558168709}
|
||||
- {fileID: 1037313416}
|
||||
- {fileID: 1720400061}
|
||||
- {fileID: 558168709}
|
||||
- {fileID: 1939795811}
|
||||
m_Father: {fileID: 433884705}
|
||||
m_RootOrder: 0
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
|
@ -560,6 +566,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1037313416}
|
||||
m_RootOrder: 0
|
||||
|
@ -641,10 +648,11 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 823091893}
|
||||
m_Father: {fileID: 693261578}
|
||||
m_RootOrder: 2
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
|
@ -795,6 +803,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1542903296}
|
||||
m_RootOrder: 0
|
||||
|
@ -848,6 +857,94 @@ CanvasRenderer:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1105325470}
|
||||
m_CullTransparentMesh: 0
|
||||
--- !u!1 &1323128746
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1323128750}
|
||||
- component: {fileID: 1323128749}
|
||||
- component: {fileID: 1323128747}
|
||||
- component: {fileID: 1323128748}
|
||||
m_Layer: 5
|
||||
m_Name: PreviewRawImage
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1323128747
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1323128746}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Texture: {fileID: 2800000, guid: 9a89f0244015e104fb922e309d53caf1, type: 3}
|
||||
m_UVRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
--- !u!114 &1323128748
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1323128746}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 86710e43de46f6f4bac7c8e50813a599, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_AspectMode: 3
|
||||
m_AspectRatio: 1
|
||||
--- !u!222 &1323128749
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1323128746}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!224 &1323128750
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1323128746}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 433884705}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!1 &1478462775
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -857,14 +954,11 @@ GameObject:
|
|||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1478462780}
|
||||
- component: {fileID: 1478462779}
|
||||
- component: {fileID: 1478462778}
|
||||
- component: {fileID: 1478462777}
|
||||
- component: {fileID: 1478462782}
|
||||
- component: {fileID: 1478462776}
|
||||
- component: {fileID: 1478462782}
|
||||
- component: {fileID: 1478462781}
|
||||
m_Layer: 0
|
||||
m_Name: Quad
|
||||
m_Name: YOLOv5ClassificationExample
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
@ -882,74 +976,11 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: f4170580ab47af64bb61ad0afb294acd, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
resultPreview: {fileID: 1323128747}
|
||||
model: yolov5n-cls.onnx
|
||||
classes: imagenet_labels.txt
|
||||
inpWidth: 224
|
||||
inpHeight: 224
|
||||
testInputImage:
|
||||
--- !u!23 &1478462777
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 2698d63d6eb926847b0236e1917fe982, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 1
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!64 &1478462778
|
||||
MeshCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
m_Convex: 0
|
||||
m_CookingOptions: 30
|
||||
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!33 &1478462779
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &1478462780
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -959,7 +990,8 @@ Transform:
|
|||
m_GameObject: {fileID: 1478462775}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 400, y: 400, z: 1}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
|
@ -992,25 +1024,31 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 1478462775}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: df35b0c19ca97734e87299a664cea35f, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: e564a549956aebc4d9acef3ff91b0981, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_requestedSource2MatHelperClassName: 0
|
||||
_currentSource2MatHelperClassCategory: 0
|
||||
_requestedDeviceName:
|
||||
_requestedWidth: 640
|
||||
_requestedHeight: 480
|
||||
_requestedIsFrontFacing: 0
|
||||
_requestedFPS: 30
|
||||
_rotate90Degree: 0
|
||||
_flipVertical: 0
|
||||
_flipHorizontal: 0
|
||||
_requestedVideoFilePath: YOLOv5WithOpenCVForUnityExample\TestVideos\6130363-sd_960_540_30fps.mp4
|
||||
_loop: 1
|
||||
_requestedImageFilePath:
|
||||
_repeat: 1
|
||||
_sourceTexture: {fileID: 0}
|
||||
_customClassComponent: {fileID: 0}
|
||||
_outputColorFormat: 3
|
||||
_timeoutFrameCount: 1500
|
||||
onInitialized:
|
||||
_onInitialized:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperInitialized
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5ClassificationExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperInitialized
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -1020,12 +1058,13 @@ MonoBehaviour:
|
|||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
onDisposed:
|
||||
_onDisposed:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperDisposed
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5ClassificationExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperDisposed
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -1035,12 +1074,13 @@ MonoBehaviour:
|
|||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
onErrorOccurred:
|
||||
_onErrorOccurred:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperErrorOccurred
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5ClassificationExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperErrorOccurred
|
||||
m_Mode: 0
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -1050,7 +1090,6 @@ MonoBehaviour:
|
|||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
avoidAndroidFrontCameraLowLightIssue: 0
|
||||
--- !u!1 &1542644386
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1112,7 +1151,7 @@ Camera:
|
|||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic: 0
|
||||
orthographic size: 200
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
|
@ -1139,6 +1178,7 @@ Transform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
|
@ -1293,6 +1333,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1105325471}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -1333,10 +1374,11 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1780842961}
|
||||
m_Father: {fileID: 693261578}
|
||||
m_RootOrder: 3
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
|
@ -1485,6 +1527,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1720400061}
|
||||
m_RootOrder: 0
|
||||
|
@ -1568,6 +1611,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SendPointerHoverToParent: 1
|
||||
m_HorizontalAxis: Horizontal
|
||||
m_VerticalAxis: Vertical
|
||||
m_SubmitButton: Submit
|
||||
|
@ -1602,6 +1646,7 @@ Transform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 3
|
||||
|
@ -1636,6 +1681,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 2116763684}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -1788,6 +1834,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1939795811}
|
||||
m_RootOrder: 0
|
||||
|
|
|
@ -13,6 +13,8 @@ using OpenCVForUnity.ImgcodecsModule;
|
|||
using OpenCVForUnity.UnityUtils;
|
||||
using OpenCVForUnity.UnityUtils.Helper;
|
||||
using YOLOv5WithOpenCVForUnity;
|
||||
using System.Threading;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace YOLOv5WithOpenCVForUnityExample
|
||||
{
|
||||
|
@ -22,9 +24,16 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// https://github.com/ultralytics/yolov5/blob/master/detect.py
|
||||
/// https://github.com/ultralytics/yolov5/blob/master/utils/general.py
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(WebCamTextureToMatHelper))]
|
||||
[RequireComponent(typeof(MultiSource2MatHelper))]
|
||||
public class YOLOv5ObjectDetectionExample : MonoBehaviour
|
||||
{
|
||||
[Header("Output")]
|
||||
/// <summary>
|
||||
/// The RawImage for previewing the result.
|
||||
/// </summary>
|
||||
public RawImage resultPreview;
|
||||
|
||||
[Space(10)]
|
||||
|
||||
[TooltipAttribute("Path to a binary file of model contains trained weights.")]
|
||||
public string model = "yolov5n.onnx";
|
||||
|
@ -47,20 +56,15 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
[TooltipAttribute("Preprocess input image by resizing to a specific height.")]
|
||||
public int inpHeight = 640;
|
||||
|
||||
[Header("TEST")]
|
||||
|
||||
[TooltipAttribute("Path to test input image.")]
|
||||
public string testInputImage;
|
||||
|
||||
/// <summary>
|
||||
/// The texture.
|
||||
/// </summary>
|
||||
protected Texture2D texture;
|
||||
|
||||
/// <summary>
|
||||
/// The webcam texture to mat helper.
|
||||
/// The multi source to mat helper.
|
||||
/// </summary>
|
||||
protected WebCamTextureToMatHelper webCamTextureToMatHelper;
|
||||
protected MultiSource2MatHelper multiSource2MatHelper;
|
||||
|
||||
/// <summary>
|
||||
/// The bgr mat.
|
||||
|
@ -80,65 +84,33 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
protected string classes_filepath;
|
||||
protected string model_filepath;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
protected IEnumerator getFilePath_Coroutine;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// The CancellationTokenSource.
|
||||
/// </summary>
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
// Use this for initialization
|
||||
protected virtual void Start()
|
||||
async void Start()
|
||||
{
|
||||
fpsMonitor = GetComponent<FpsMonitor>();
|
||||
|
||||
webCamTextureToMatHelper = gameObject.GetComponent<WebCamTextureToMatHelper>();
|
||||
multiSource2MatHelper = gameObject.GetComponent<MultiSource2MatHelper>();
|
||||
multiSource2MatHelper.outputColorFormat = Source2MatHelperColorFormat.RGBA;
|
||||
|
||||
// Asynchronously retrieves the readable file path from the StreamingAssets directory.
|
||||
if (fpsMonitor != null)
|
||||
fpsMonitor.consoleText = "Preparing file access...";
|
||||
|
||||
#if UNITY_WEBGL
|
||||
getFilePath_Coroutine = GetFilePath();
|
||||
StartCoroutine(getFilePath_Coroutine);
|
||||
#else
|
||||
if (!string.IsNullOrEmpty(classes))
|
||||
{
|
||||
classes_filepath = Utils.getFilePath("YOLOv5WithOpenCVForUnityExample/" + classes);
|
||||
if (string.IsNullOrEmpty(classes_filepath)) Debug.Log("The file:" + classes + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
classes_filepath = await Utils.getFilePathAsyncTask("YOLOv5WithOpenCVForUnityExample/" + classes, cancellationToken: cts.Token);
|
||||
if (!string.IsNullOrEmpty(model))
|
||||
{
|
||||
model_filepath = Utils.getFilePath("YOLOv5WithOpenCVForUnityExample/" + model);
|
||||
if (string.IsNullOrEmpty(model_filepath)) Debug.Log("The file:" + model + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
Run();
|
||||
#endif
|
||||
}
|
||||
model_filepath = await Utils.getFilePathAsyncTask("YOLOv5WithOpenCVForUnityExample/" + model, cancellationToken: cts.Token);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
protected virtual IEnumerator GetFilePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(classes))
|
||||
{
|
||||
var getFilePathAsync_0_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + classes, (result) =>
|
||||
{
|
||||
classes_filepath = result;
|
||||
});
|
||||
yield return getFilePathAsync_0_Coroutine;
|
||||
|
||||
if (string.IsNullOrEmpty(classes_filepath)) Debug.Log("The file:" + classes + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model))
|
||||
{
|
||||
var getFilePathAsync_1_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + model, (result) =>
|
||||
{
|
||||
model_filepath = result;
|
||||
});
|
||||
yield return getFilePathAsync_1_Coroutine;
|
||||
|
||||
if (string.IsNullOrEmpty(model_filepath)) Debug.Log("The file:" + model + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
|
||||
getFilePath_Coroutine = null;
|
||||
if (fpsMonitor != null)
|
||||
fpsMonitor.consoleText = "";
|
||||
|
||||
Run();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this for initialization
|
||||
protected virtual void Run()
|
||||
|
@ -155,120 +127,40 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
objectDetector = new YOLOv5ObjectDetector(model_filepath, classes_filepath, new Size(inpWidth, inpHeight), confThreshold, nmsThreshold, topK);
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(testInputImage))
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
// Avoids the front camera low light issue that occurs in only some Android devices (e.g. Google Pixel, Pixel2).
|
||||
webCamTextureToMatHelper.avoidAndroidFrontCameraLowLightIssue = true;
|
||||
#endif
|
||||
webCamTextureToMatHelper.Initialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
/////////////////////
|
||||
// TEST
|
||||
|
||||
var getFilePathAsync_0_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + testInputImage, (result) =>
|
||||
{
|
||||
string test_input_image_filepath = result;
|
||||
if (string.IsNullOrEmpty(test_input_image_filepath)) Debug.Log("The file:" + testInputImage + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
|
||||
Mat img = Imgcodecs.imread(test_input_image_filepath);
|
||||
if (img.empty())
|
||||
{
|
||||
img = new Mat(424, 640, CvType.CV_8UC3, new Scalar(0, 0, 0));
|
||||
Imgproc.putText(img, testInputImage + " is not loaded.", new Point(5, img.rows() - 30), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
|
||||
Imgproc.putText(img, "Please read console message.", new Point(5, img.rows() - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
TickMeter tm = new TickMeter();
|
||||
tm.start();
|
||||
|
||||
Mat results = objectDetector.infer(img);
|
||||
|
||||
tm.stop();
|
||||
Debug.Log("YOLOv5ObjectDetector Inference time (preprocess + infer + postprocess), ms: " + tm.getTimeMilli());
|
||||
|
||||
objectDetector.visualize(img, results, true, false);
|
||||
}
|
||||
|
||||
gameObject.transform.localScale = new Vector3(img.width(), img.height(), 1);
|
||||
float imageWidth = img.width();
|
||||
float imageHeight = img.height();
|
||||
float widthScale = (float)Screen.width / imageWidth;
|
||||
float heightScale = (float)Screen.height / imageHeight;
|
||||
if (widthScale < heightScale)
|
||||
{
|
||||
Camera.main.orthographicSize = (imageWidth * (float)Screen.height / (float)Screen.width) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera.main.orthographicSize = imageHeight / 2;
|
||||
}
|
||||
|
||||
Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2RGB);
|
||||
Texture2D texture = new Texture2D(img.cols(), img.rows(), TextureFormat.RGB24, false);
|
||||
Utils.matToTexture2D(img, texture);
|
||||
gameObject.GetComponent<Renderer>().material.mainTexture = texture;
|
||||
|
||||
});
|
||||
StartCoroutine(getFilePathAsync_0_Coroutine);
|
||||
|
||||
/////////////////////
|
||||
}
|
||||
multiSource2MatHelper.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper initialized event.
|
||||
/// Raises the source to mat helper initialized event.
|
||||
/// </summary>
|
||||
public virtual void OnWebCamTextureToMatHelperInitialized()
|
||||
public virtual void OnSourceToMatHelperInitialized()
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperInitialized");
|
||||
Debug.Log("OnSourceToMatHelperInitialized");
|
||||
|
||||
Mat webCamTextureMat = webCamTextureToMatHelper.GetMat();
|
||||
Mat rgbaMat = multiSource2MatHelper.GetMat();
|
||||
|
||||
texture = new Texture2D(rgbaMat.cols(), rgbaMat.rows(), TextureFormat.RGBA32, false);
|
||||
|
||||
texture = new Texture2D(webCamTextureMat.cols(), webCamTextureMat.rows(), TextureFormat.RGBA32, false);
|
||||
resultPreview.texture = texture;
|
||||
resultPreview.GetComponent<AspectRatioFitter>().aspectRatio = (float)texture.width / texture.height;
|
||||
|
||||
gameObject.GetComponent<Renderer>().material.mainTexture = texture;
|
||||
|
||||
gameObject.transform.localScale = new Vector3(webCamTextureMat.cols(), webCamTextureMat.rows(), 1);
|
||||
Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
|
||||
|
||||
if (fpsMonitor != null)
|
||||
{
|
||||
fpsMonitor.Add("width", webCamTextureMat.width().ToString());
|
||||
fpsMonitor.Add("height", webCamTextureMat.height().ToString());
|
||||
fpsMonitor.Add("width", rgbaMat.width().ToString());
|
||||
fpsMonitor.Add("height", rgbaMat.height().ToString());
|
||||
fpsMonitor.Add("orientation", Screen.orientation.ToString());
|
||||
}
|
||||
|
||||
|
||||
float width = webCamTextureMat.width();
|
||||
float height = webCamTextureMat.height();
|
||||
|
||||
float widthScale = (float)Screen.width / width;
|
||||
float heightScale = (float)Screen.height / height;
|
||||
if (widthScale < heightScale)
|
||||
{
|
||||
Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera.main.orthographicSize = height / 2;
|
||||
}
|
||||
|
||||
|
||||
bgrMat = new Mat(webCamTextureMat.rows(), webCamTextureMat.cols(), CvType.CV_8UC3);
|
||||
bgrMat = new Mat(rgbaMat.rows(), rgbaMat.cols(), CvType.CV_8UC3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper disposed event.
|
||||
/// Raises the source to mat helper disposed event.
|
||||
/// </summary>
|
||||
public virtual void OnWebCamTextureToMatHelperDisposed()
|
||||
public virtual void OnSourceToMatHelperDisposed()
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperDisposed");
|
||||
Debug.Log("OnSourceToMatHelperDisposed");
|
||||
|
||||
if (bgrMat != null)
|
||||
bgrMat.Dispose();
|
||||
|
@ -281,21 +173,27 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper error occurred event.
|
||||
/// Raises the source to mat helper error occurred event.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">Error code.</param>
|
||||
public virtual void OnWebCamTextureToMatHelperErrorOccurred(WebCamTextureToMatHelper.ErrorCode errorCode)
|
||||
/// <param name="message">Message.</param>
|
||||
public void OnSourceToMatHelperErrorOccurred(Source2MatHelperErrorCode errorCode, string message)
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperErrorOccurred " + errorCode);
|
||||
Debug.Log("OnSourceToMatHelperErrorOccurred " + errorCode + ":" + message);
|
||||
|
||||
if (fpsMonitor != null)
|
||||
{
|
||||
fpsMonitor.consoleText = "ErrorCode: " + errorCode + ":" + message;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
|
||||
if (multiSource2MatHelper.IsPlaying() && multiSource2MatHelper.DidUpdateThisFrame())
|
||||
{
|
||||
|
||||
Mat rgbaMat = webCamTextureToMatHelper.GetMat();
|
||||
Mat rgbaMat = multiSource2MatHelper.GetMat();
|
||||
|
||||
if (objectDetector == null)
|
||||
{
|
||||
|
@ -330,20 +228,15 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
webCamTextureToMatHelper.Dispose();
|
||||
multiSource2MatHelper.Dispose();
|
||||
|
||||
if (objectDetector != null)
|
||||
objectDetector.dispose();
|
||||
|
||||
Utils.setDebugMode(false);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
if (getFilePath_Coroutine != null)
|
||||
{
|
||||
StopCoroutine(getFilePath_Coroutine);
|
||||
((IDisposable)getFilePath_Coroutine).Dispose();
|
||||
}
|
||||
#endif
|
||||
if (cts != null)
|
||||
cts.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -359,7 +252,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnPlayButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Play();
|
||||
multiSource2MatHelper.Play();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -367,7 +260,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnPauseButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Pause();
|
||||
multiSource2MatHelper.Pause();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -375,7 +268,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnStopButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Stop();
|
||||
multiSource2MatHelper.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -383,7 +276,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnChangeCameraButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
|
||||
multiSource2MatHelper.requestedIsFrontFacing = !multiSource2MatHelper.requestedIsFrontFacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1730312740}
|
||||
m_RootOrder: 0
|
||||
|
@ -233,7 +234,9 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0, y: 0, z: 0}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 467066251}
|
||||
- {fileID: 693261578}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
|
@ -303,10 +306,99 @@ Canvas:
|
|||
m_OverrideSorting: 0
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_VertexColorAlwaysGammaSpace: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
--- !u!1 &467066247
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 467066251}
|
||||
- component: {fileID: 467066250}
|
||||
- component: {fileID: 467066248}
|
||||
- component: {fileID: 467066249}
|
||||
m_Layer: 5
|
||||
m_Name: PreviewRawImage
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &467066248
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 467066247}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Texture: {fileID: 2800000, guid: 9a89f0244015e104fb922e309d53caf1, type: 3}
|
||||
m_UVRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
--- !u!114 &467066249
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 467066247}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 86710e43de46f6f4bac7c8e50813a599, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_AspectMode: 3
|
||||
m_AspectRatio: 1
|
||||
--- !u!222 &467066250
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 467066247}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!224 &467066251
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 467066247}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 433884705}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!1 &545649235
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -337,6 +429,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1757577928}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -489,6 +582,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2078184090}
|
||||
m_RootOrder: 0
|
||||
|
@ -569,6 +663,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1542903296}
|
||||
- {fileID: 2078184090}
|
||||
|
@ -576,7 +671,7 @@ RectTransform:
|
|||
- {fileID: 1987132238}
|
||||
- {fileID: 1730312740}
|
||||
m_Father: {fileID: 433884705}
|
||||
m_RootOrder: 0
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
|
@ -640,6 +735,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1542903296}
|
||||
m_RootOrder: 0
|
||||
|
@ -700,7 +796,7 @@ LightingSettings:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Settings.lighting
|
||||
serializedVersion: 3
|
||||
serializedVersion: 4
|
||||
m_GIWorkflowMode: 1
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
|
@ -713,7 +809,7 @@ LightingSettings:
|
|||
m_LightmapMaxSize: 1024
|
||||
m_BakeResolution: 50
|
||||
m_Padding: 2
|
||||
m_TextureCompression: 0
|
||||
m_LightmapCompression: 0
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 0
|
||||
|
@ -754,6 +850,7 @@ LightingSettings:
|
|||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_PVRTiledBaking: 0
|
||||
--- !u!1 &1478462775
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -763,14 +860,11 @@ GameObject:
|
|||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1478462780}
|
||||
- component: {fileID: 1478462779}
|
||||
- component: {fileID: 1478462778}
|
||||
- component: {fileID: 1478462777}
|
||||
- component: {fileID: 1478462781}
|
||||
- component: {fileID: 1478462776}
|
||||
- component: {fileID: 1478462783}
|
||||
- component: {fileID: 1478462782}
|
||||
m_Layer: 0
|
||||
m_Name: Quad
|
||||
m_Name: YOLOv5ObjectDetectionExample
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
@ -788,6 +882,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 96fe1591a90a516428f4047b7bcb137c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
resultPreview: {fileID: 467066248}
|
||||
model: yolov5n.onnx
|
||||
classes: coco.names
|
||||
confThreshold: 0.25
|
||||
|
@ -795,70 +890,6 @@ MonoBehaviour:
|
|||
topK: 300
|
||||
inpWidth: 640
|
||||
inpHeight: 640
|
||||
testInputImage:
|
||||
--- !u!23 &1478462777
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 2698d63d6eb926847b0236e1917fe982, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 1
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!64 &1478462778
|
||||
MeshCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
m_Convex: 0
|
||||
m_CookingOptions: 30
|
||||
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!33 &1478462779
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &1478462780
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -868,79 +899,12 @@ Transform:
|
|||
m_GameObject: {fileID: 1478462775}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 400, y: 400, z: 1}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1478462781
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: df35b0c19ca97734e87299a664cea35f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_requestedDeviceName:
|
||||
_requestedWidth: 640
|
||||
_requestedHeight: 480
|
||||
_requestedIsFrontFacing: 0
|
||||
_requestedFPS: 30
|
||||
_rotate90Degree: 0
|
||||
_flipVertical: 0
|
||||
_flipHorizontal: 0
|
||||
_outputColorFormat: 3
|
||||
_timeoutFrameCount: 1500
|
||||
onInitialized:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperInitialized
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
onDisposed:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperDisposed
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
onErrorOccurred:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperErrorOccurred
|
||||
m_Mode: 0
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
avoidAndroidFrontCameraLowLightIssue: 0
|
||||
--- !u!114 &1478462782
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -959,7 +923,82 @@ MonoBehaviour:
|
|||
boxWidth: 75
|
||||
boxHeight: 30
|
||||
padding: {x: 8, y: 5}
|
||||
consoleHeight: 50
|
||||
consoleHeight: 100
|
||||
--- !u!114 &1478462783
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: e564a549956aebc4d9acef3ff91b0981, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_requestedSource2MatHelperClassName: 0
|
||||
_currentSource2MatHelperClassCategory: 0
|
||||
_requestedDeviceName:
|
||||
_requestedWidth: 640
|
||||
_requestedHeight: 480
|
||||
_requestedIsFrontFacing: 0
|
||||
_requestedFPS: 30
|
||||
_requestedVideoFilePath: YOLOv5WithOpenCVForUnityExample/TestVideos/pexels-taryn-elliott-3770033-960x540-25fps.mp4
|
||||
_loop: 1
|
||||
_requestedImageFilePath:
|
||||
_repeat: 1
|
||||
_sourceTexture: {fileID: 0}
|
||||
_customClassComponent: {fileID: 0}
|
||||
_outputColorFormat: 3
|
||||
_timeoutFrameCount: 1500
|
||||
_onInitialized:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5ObjectDetectionExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperInitialized
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
_onDisposed:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5ObjectDetectionExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperDisposed
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
_onErrorOccurred:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5ObjectDetectionExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperErrorOccurred
|
||||
m_Mode: 0
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!1 &1525823489
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -988,6 +1027,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1987132238}
|
||||
m_RootOrder: 0
|
||||
|
@ -1100,7 +1140,7 @@ Camera:
|
|||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic: 0
|
||||
orthographic size: 200
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
|
@ -1127,6 +1167,7 @@ Transform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
|
@ -1281,6 +1322,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1105325471}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -1321,6 +1363,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 144354276}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -1473,6 +1516,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 545649236}
|
||||
m_RootOrder: 0
|
||||
|
@ -1556,6 +1600,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SendPointerHoverToParent: 1
|
||||
m_HorizontalAxis: Horizontal
|
||||
m_VerticalAxis: Vertical
|
||||
m_SubmitButton: Submit
|
||||
|
@ -1590,6 +1635,7 @@ Transform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 3
|
||||
|
@ -1624,6 +1670,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1525823490}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -1778,6 +1825,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 592285776}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
|
|
@ -13,6 +13,8 @@ using OpenCVForUnity.ImgcodecsModule;
|
|||
using OpenCVForUnity.UnityUtils;
|
||||
using OpenCVForUnity.UnityUtils.Helper;
|
||||
using YOLOv5WithOpenCVForUnity;
|
||||
using System.Threading;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace YOLOv5WithOpenCVForUnityExample
|
||||
{
|
||||
|
@ -22,9 +24,16 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// https://github.com/ultralytics/yolov5/blob/master/segment/predict.py
|
||||
/// https://github.com/ultralytics/yolov5/blob/master/utils/general.py
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(WebCamTextureToMatHelper))]
|
||||
[RequireComponent(typeof(MultiSource2MatHelper))]
|
||||
public class YOLOv5SegmentationExample : MonoBehaviour
|
||||
{
|
||||
[Header("Output")]
|
||||
/// <summary>
|
||||
/// The RawImage for previewing the result.
|
||||
/// </summary>
|
||||
public RawImage resultPreview;
|
||||
|
||||
[Space(10)]
|
||||
|
||||
[TooltipAttribute("Path to a binary file of model contains trained weights.")]
|
||||
public string model = "yolov5n.onnx";
|
||||
|
@ -50,20 +59,15 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
[TooltipAttribute("Preprocess input image by resizing to a specific height.")]
|
||||
public int inpHeight = 640;
|
||||
|
||||
[Header("TEST")]
|
||||
|
||||
[TooltipAttribute("Path to test input image.")]
|
||||
public string testInputImage;
|
||||
|
||||
/// <summary>
|
||||
/// The texture.
|
||||
/// </summary>
|
||||
protected Texture2D texture;
|
||||
|
||||
/// <summary>
|
||||
/// The webcam texture to mat helper.
|
||||
/// The multi source to mat helper.
|
||||
/// </summary>
|
||||
protected WebCamTextureToMatHelper webCamTextureToMatHelper;
|
||||
protected MultiSource2MatHelper multiSource2MatHelper;
|
||||
|
||||
/// <summary>
|
||||
/// The bgr mat.
|
||||
|
@ -83,65 +87,33 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
protected string classes_filepath;
|
||||
protected string model_filepath;
|
||||
|
||||
#if UNITY_WEBGL
|
||||
protected IEnumerator getFilePath_Coroutine;
|
||||
#endif
|
||||
/// <summary>
|
||||
/// The CancellationTokenSource.
|
||||
/// </summary>
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
// Use this for initialization
|
||||
protected virtual void Start()
|
||||
async void Start()
|
||||
{
|
||||
fpsMonitor = GetComponent<FpsMonitor>();
|
||||
|
||||
webCamTextureToMatHelper = gameObject.GetComponent<WebCamTextureToMatHelper>();
|
||||
multiSource2MatHelper = gameObject.GetComponent<MultiSource2MatHelper>();
|
||||
multiSource2MatHelper.outputColorFormat = Source2MatHelperColorFormat.RGBA;
|
||||
|
||||
// Asynchronously retrieves the readable file path from the StreamingAssets directory.
|
||||
if (fpsMonitor != null)
|
||||
fpsMonitor.consoleText = "Preparing file access...";
|
||||
|
||||
#if UNITY_WEBGL
|
||||
getFilePath_Coroutine = GetFilePath();
|
||||
StartCoroutine(getFilePath_Coroutine);
|
||||
#else
|
||||
if (!string.IsNullOrEmpty(classes))
|
||||
{
|
||||
classes_filepath = Utils.getFilePath("YOLOv5WithOpenCVForUnityExample/" + classes);
|
||||
if (string.IsNullOrEmpty(classes_filepath)) Debug.Log("The file:" + classes + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
classes_filepath = await Utils.getFilePathAsyncTask("YOLOv5WithOpenCVForUnityExample/" + classes, cancellationToken: cts.Token);
|
||||
if (!string.IsNullOrEmpty(model))
|
||||
{
|
||||
model_filepath = Utils.getFilePath("YOLOv5WithOpenCVForUnityExample/" + model);
|
||||
if (string.IsNullOrEmpty(model_filepath)) Debug.Log("The file:" + model + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
Run();
|
||||
#endif
|
||||
}
|
||||
model_filepath = await Utils.getFilePathAsyncTask("YOLOv5WithOpenCVForUnityExample/" + model, cancellationToken: cts.Token);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
protected virtual IEnumerator GetFilePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(classes))
|
||||
{
|
||||
var getFilePathAsync_0_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + classes, (result) =>
|
||||
{
|
||||
classes_filepath = result;
|
||||
});
|
||||
yield return getFilePathAsync_0_Coroutine;
|
||||
|
||||
if (string.IsNullOrEmpty(classes_filepath)) Debug.Log("The file:" + classes + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model))
|
||||
{
|
||||
var getFilePathAsync_1_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + model, (result) =>
|
||||
{
|
||||
model_filepath = result;
|
||||
});
|
||||
yield return getFilePathAsync_1_Coroutine;
|
||||
|
||||
if (string.IsNullOrEmpty(model_filepath)) Debug.Log("The file:" + model + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
}
|
||||
|
||||
getFilePath_Coroutine = null;
|
||||
if (fpsMonitor != null)
|
||||
fpsMonitor.consoleText = "";
|
||||
|
||||
Run();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this for initialization
|
||||
protected virtual void Run()
|
||||
|
@ -158,122 +130,40 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
segmentPredictor = new YOLOv5SegmentPredictor(model_filepath, classes_filepath, new Size(inpWidth, inpHeight), confThreshold, nmsThreshold, topK, upsample);
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(testInputImage))
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
// Avoids the front camera low light issue that occurs in only some Android devices (e.g. Google Pixel, Pixel2).
|
||||
webCamTextureToMatHelper.avoidAndroidFrontCameraLowLightIssue = true;
|
||||
#endif
|
||||
webCamTextureToMatHelper.Initialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
/////////////////////
|
||||
// TEST
|
||||
|
||||
var getFilePathAsync_0_Coroutine = Utils.getFilePathAsync("YOLOv5WithOpenCVForUnityExample/" + testInputImage, (result) =>
|
||||
{
|
||||
string test_input_image_filepath = result;
|
||||
if (string.IsNullOrEmpty(test_input_image_filepath)) Debug.Log("The file:" + testInputImage + " did not exist in the folder “Assets/StreamingAssets/YOLOv5WithOpenCVForUnityExample”.");
|
||||
|
||||
Mat img = Imgcodecs.imread(test_input_image_filepath);
|
||||
if (img.empty())
|
||||
{
|
||||
img = new Mat(424, 640, CvType.CV_8UC3, new Scalar(0, 0, 0));
|
||||
Imgproc.putText(img, testInputImage + " is not loaded.", new Point(5, img.rows() - 30), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
|
||||
Imgproc.putText(img, "Please read console message.", new Point(5, img.rows() - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
TickMeter tm = new TickMeter();
|
||||
tm.start();
|
||||
|
||||
List<Mat> results = segmentPredictor.infer(img);
|
||||
|
||||
tm.stop();
|
||||
Debug.Log("YOLOv5SegmentPredictor Inference time (preprocess + infer + postprocess), ms: " + tm.getTimeMilli());
|
||||
|
||||
|
||||
segmentPredictor.visualize_mask(img, results[0], results[1], 0.5f, false);
|
||||
segmentPredictor.visualize(img, results[0], true, false);
|
||||
}
|
||||
|
||||
gameObject.transform.localScale = new Vector3(img.width(), img.height(), 1);
|
||||
float imageWidth = img.width();
|
||||
float imageHeight = img.height();
|
||||
float widthScale = (float)Screen.width / imageWidth;
|
||||
float heightScale = (float)Screen.height / imageHeight;
|
||||
if (widthScale < heightScale)
|
||||
{
|
||||
Camera.main.orthographicSize = (imageWidth * (float)Screen.height / (float)Screen.width) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera.main.orthographicSize = imageHeight / 2;
|
||||
}
|
||||
|
||||
Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2RGB);
|
||||
Texture2D texture = new Texture2D(img.cols(), img.rows(), TextureFormat.RGB24, false);
|
||||
Utils.matToTexture2D(img, texture);
|
||||
gameObject.GetComponent<Renderer>().material.mainTexture = texture;
|
||||
|
||||
});
|
||||
StartCoroutine(getFilePathAsync_0_Coroutine);
|
||||
|
||||
/////////////////////
|
||||
}
|
||||
multiSource2MatHelper.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper initialized event.
|
||||
/// Raises the source to mat helper initialized event.
|
||||
/// </summary>
|
||||
public virtual void OnWebCamTextureToMatHelperInitialized()
|
||||
public virtual void OnSourceToMatHelperInitialized()
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperInitialized");
|
||||
Debug.Log("OnSourceToMatHelperInitialized");
|
||||
|
||||
Mat webCamTextureMat = webCamTextureToMatHelper.GetMat();
|
||||
Mat rgbaMat = multiSource2MatHelper.GetMat();
|
||||
|
||||
texture = new Texture2D(rgbaMat.cols(), rgbaMat.rows(), TextureFormat.RGBA32, false);
|
||||
|
||||
texture = new Texture2D(webCamTextureMat.cols(), webCamTextureMat.rows(), TextureFormat.RGBA32, false);
|
||||
resultPreview.texture = texture;
|
||||
resultPreview.GetComponent<AspectRatioFitter>().aspectRatio = (float)texture.width / texture.height;
|
||||
|
||||
gameObject.GetComponent<Renderer>().material.mainTexture = texture;
|
||||
|
||||
gameObject.transform.localScale = new Vector3(webCamTextureMat.cols(), webCamTextureMat.rows(), 1);
|
||||
Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
|
||||
|
||||
if (fpsMonitor != null)
|
||||
{
|
||||
fpsMonitor.Add("width", webCamTextureMat.width().ToString());
|
||||
fpsMonitor.Add("height", webCamTextureMat.height().ToString());
|
||||
fpsMonitor.Add("width", rgbaMat.width().ToString());
|
||||
fpsMonitor.Add("height", rgbaMat.height().ToString());
|
||||
fpsMonitor.Add("orientation", Screen.orientation.ToString());
|
||||
}
|
||||
|
||||
|
||||
float width = webCamTextureMat.width();
|
||||
float height = webCamTextureMat.height();
|
||||
|
||||
float widthScale = (float)Screen.width / width;
|
||||
float heightScale = (float)Screen.height / height;
|
||||
if (widthScale < heightScale)
|
||||
{
|
||||
Camera.main.orthographicSize = (width * (float)Screen.height / (float)Screen.width) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera.main.orthographicSize = height / 2;
|
||||
}
|
||||
|
||||
|
||||
bgrMat = new Mat(webCamTextureMat.rows(), webCamTextureMat.cols(), CvType.CV_8UC3);
|
||||
bgrMat = new Mat(rgbaMat.rows(), rgbaMat.cols(), CvType.CV_8UC3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper disposed event.
|
||||
/// Raises the source to mat helper disposed event.
|
||||
/// </summary>
|
||||
public virtual void OnWebCamTextureToMatHelperDisposed()
|
||||
public virtual void OnSourceToMatHelperDisposed()
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperDisposed");
|
||||
Debug.Log("OnSourceToMatHelperDisposed");
|
||||
|
||||
if (bgrMat != null)
|
||||
bgrMat.Dispose();
|
||||
|
@ -286,21 +176,27 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the webcam texture to mat helper error occurred event.
|
||||
/// Raises the source to mat helper error occurred event.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">Error code.</param>
|
||||
public virtual void OnWebCamTextureToMatHelperErrorOccurred(WebCamTextureToMatHelper.ErrorCode errorCode)
|
||||
/// <param name="message">Message.</param>
|
||||
public void OnSourceToMatHelperErrorOccurred(Source2MatHelperErrorCode errorCode, string message)
|
||||
{
|
||||
Debug.Log("OnWebCamTextureToMatHelperErrorOccurred " + errorCode);
|
||||
Debug.Log("OnSourceToMatHelperErrorOccurred " + errorCode + ":" + message);
|
||||
|
||||
if (fpsMonitor != null)
|
||||
{
|
||||
fpsMonitor.consoleText = "ErrorCode: " + errorCode + ":" + message;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
|
||||
if (multiSource2MatHelper.IsPlaying() && multiSource2MatHelper.DidUpdateThisFrame())
|
||||
{
|
||||
|
||||
Mat rgbaMat = webCamTextureToMatHelper.GetMat();
|
||||
Mat rgbaMat = multiSource2MatHelper.GetMat();
|
||||
|
||||
if (segmentPredictor == null)
|
||||
{
|
||||
|
@ -336,20 +232,15 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
webCamTextureToMatHelper.Dispose();
|
||||
multiSource2MatHelper.Dispose();
|
||||
|
||||
if (segmentPredictor != null)
|
||||
segmentPredictor.dispose();
|
||||
|
||||
Utils.setDebugMode(false);
|
||||
|
||||
#if UNITY_WEBGL
|
||||
if (getFilePath_Coroutine != null)
|
||||
{
|
||||
StopCoroutine(getFilePath_Coroutine);
|
||||
((IDisposable)getFilePath_Coroutine).Dispose();
|
||||
}
|
||||
#endif
|
||||
if (cts != null)
|
||||
cts.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -365,7 +256,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnPlayButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Play();
|
||||
multiSource2MatHelper.Play();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -373,7 +264,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnPauseButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Pause();
|
||||
multiSource2MatHelper.Pause();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -381,7 +272,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnStopButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.Stop();
|
||||
multiSource2MatHelper.Stop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -389,7 +280,7 @@ namespace YOLOv5WithOpenCVForUnityExample
|
|||
/// </summary>
|
||||
public virtual void OnChangeCameraButtonClick()
|
||||
{
|
||||
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
|
||||
multiSource2MatHelper.requestedIsFrontFacing = !multiSource2MatHelper.requestedIsFrontFacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,94 @@ NavMeshSettings:
|
|||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &47512345
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 47512349}
|
||||
- component: {fileID: 47512348}
|
||||
- component: {fileID: 47512346}
|
||||
- component: {fileID: 47512347}
|
||||
m_Layer: 5
|
||||
m_Name: PreviewRawImage
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &47512346
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 47512345}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Texture: {fileID: 2800000, guid: 9a89f0244015e104fb922e309d53caf1, type: 3}
|
||||
m_UVRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
--- !u!114 &47512347
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 47512345}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 86710e43de46f6f4bac7c8e50813a599, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_AspectMode: 3
|
||||
m_AspectRatio: 1
|
||||
--- !u!222 &47512348
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 47512345}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!224 &47512349
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 47512345}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 433884705}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!1 &218016805
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -153,6 +241,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 372546924}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -305,6 +394,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 218016806}
|
||||
m_RootOrder: 0
|
||||
|
@ -387,7 +477,9 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0, y: 0, z: 0}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 47512349}
|
||||
- {fileID: 693261578}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
|
@ -457,6 +549,7 @@ Canvas:
|
|||
m_OverrideSorting: 0
|
||||
m_OverridePixelPerfect: 0
|
||||
m_SortingBucketNormalizedSize: 0
|
||||
m_VertexColorAlwaysGammaSpace: 0
|
||||
m_AdditionalShaderChannelsFlag: 25
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
|
@ -490,14 +583,15 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1542903296}
|
||||
- {fileID: 1276279661}
|
||||
- {fileID: 1976697923}
|
||||
- {fileID: 1713250976}
|
||||
- {fileID: 1276279661}
|
||||
- {fileID: 218016806}
|
||||
m_Father: {fileID: 433884705}
|
||||
m_RootOrder: 0
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
|
@ -559,6 +653,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1276279661}
|
||||
m_RootOrder: 0
|
||||
|
@ -638,6 +733,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1976697923}
|
||||
m_RootOrder: 0
|
||||
|
@ -696,7 +792,7 @@ LightingSettings:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Settings.lighting
|
||||
serializedVersion: 3
|
||||
serializedVersion: 4
|
||||
m_GIWorkflowMode: 1
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
|
@ -709,7 +805,7 @@ LightingSettings:
|
|||
m_LightmapMaxSize: 1024
|
||||
m_BakeResolution: 50
|
||||
m_Padding: 2
|
||||
m_TextureCompression: 0
|
||||
m_LightmapCompression: 0
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 0
|
||||
|
@ -750,6 +846,7 @@ LightingSettings:
|
|||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_PVRTiledBaking: 0
|
||||
--- !u!1 &1105325470
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -780,6 +877,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1542903296}
|
||||
m_RootOrder: 0
|
||||
|
@ -863,10 +961,11 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 890681807}
|
||||
m_Father: {fileID: 693261578}
|
||||
m_RootOrder: 1
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
|
@ -996,14 +1095,11 @@ GameObject:
|
|||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1478462780}
|
||||
- component: {fileID: 1478462779}
|
||||
- component: {fileID: 1478462778}
|
||||
- component: {fileID: 1478462777}
|
||||
- component: {fileID: 1478462782}
|
||||
- component: {fileID: 1478462776}
|
||||
- component: {fileID: 1478462782}
|
||||
- component: {fileID: 1478462781}
|
||||
m_Layer: 0
|
||||
m_Name: Quad
|
||||
m_Name: YOLOv5SegmentationExample
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
|
@ -1021,6 +1117,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 7bd32c223d437c048bb0b1a5cef9a65c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
resultPreview: {fileID: 47512346}
|
||||
model: yolov5n-seg.onnx
|
||||
classes: coco.names
|
||||
confThreshold: 0.25
|
||||
|
@ -1029,70 +1126,6 @@ MonoBehaviour:
|
|||
upsample: 1
|
||||
inpWidth: 640
|
||||
inpHeight: 640
|
||||
testInputImage:
|
||||
--- !u!23 &1478462777
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 2698d63d6eb926847b0236e1917fe982, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 1
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!64 &1478462778
|
||||
MeshCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 4
|
||||
m_Convex: 0
|
||||
m_CookingOptions: 30
|
||||
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!33 &1478462779
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1478462775}
|
||||
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &1478462780
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1102,7 +1135,8 @@ Transform:
|
|||
m_GameObject: {fileID: 1478462775}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 400, y: 400, z: 1}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
|
@ -1125,7 +1159,7 @@ MonoBehaviour:
|
|||
boxWidth: 75
|
||||
boxHeight: 30
|
||||
padding: {x: 8, y: 5}
|
||||
consoleHeight: 50
|
||||
consoleHeight: 100
|
||||
--- !u!114 &1478462782
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1135,25 +1169,31 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 1478462775}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: df35b0c19ca97734e87299a664cea35f, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: e564a549956aebc4d9acef3ff91b0981, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_requestedSource2MatHelperClassName: 0
|
||||
_currentSource2MatHelperClassCategory: 0
|
||||
_requestedDeviceName:
|
||||
_requestedWidth: 640
|
||||
_requestedHeight: 480
|
||||
_requestedIsFrontFacing: 0
|
||||
_requestedFPS: 30
|
||||
_rotate90Degree: 0
|
||||
_flipVertical: 0
|
||||
_flipHorizontal: 0
|
||||
_requestedVideoFilePath: YOLOv5WithOpenCVForUnityExample\TestVideos\ObjectDetection_TestVideo_640_640_30fps.mp4
|
||||
_loop: 1
|
||||
_requestedImageFilePath:
|
||||
_repeat: 1
|
||||
_sourceTexture: {fileID: 0}
|
||||
_customClassComponent: {fileID: 0}
|
||||
_outputColorFormat: 3
|
||||
_timeoutFrameCount: 1500
|
||||
onInitialized:
|
||||
_onInitialized:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperInitialized
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5SegmentationExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperInitialized
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -1163,12 +1203,13 @@ MonoBehaviour:
|
|||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
onDisposed:
|
||||
_onDisposed:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperDisposed
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5SegmentationExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperDisposed
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -1178,12 +1219,13 @@ MonoBehaviour:
|
|||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
onErrorOccurred:
|
||||
_onErrorOccurred:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 1478462776}
|
||||
m_TargetAssemblyTypeName:
|
||||
m_MethodName: OnWebCamTextureToMatHelperErrorOccurred
|
||||
m_TargetAssemblyTypeName: YOLOv5WithOpenCVForUnityExample.YOLOv5SegmentationExample,
|
||||
Assembly-CSharp
|
||||
m_MethodName: OnSourceToMatHelperErrorOccurred
|
||||
m_Mode: 0
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
@ -1193,7 +1235,6 @@ MonoBehaviour:
|
|||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
avoidAndroidFrontCameraLowLightIssue: 0
|
||||
--- !u!1 &1542644386
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1255,7 +1296,7 @@ Camera:
|
|||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic: 0
|
||||
orthographic size: 200
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
|
@ -1282,6 +1323,7 @@ Transform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
|
@ -1436,6 +1478,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1105325471}
|
||||
m_Father: {fileID: 693261578}
|
||||
|
@ -1476,10 +1519,11 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1905103717}
|
||||
m_Father: {fileID: 693261578}
|
||||
m_RootOrder: 3
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
|
@ -1632,6 +1676,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SendPointerHoverToParent: 1
|
||||
m_HorizontalAxis: Horizontal
|
||||
m_VerticalAxis: Vertical
|
||||
m_SubmitButton: Submit
|
||||
|
@ -1666,6 +1711,7 @@ Transform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 3
|
||||
|
@ -1698,6 +1744,7 @@ RectTransform:
|
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1713250976}
|
||||
m_RootOrder: 0
|
||||
|
@ -1779,10 +1826,11 @@ RectTransform:
|
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 1010783035}
|
||||
m_Father: {fileID: 693261578}
|
||||
m_RootOrder: 2
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
## Environment
|
||||
- Windows / Mac / Linux / WebGL / Android / iOS
|
||||
- Unity >= 2020.3.48f1+
|
||||
- Unity >= 2021.3.35f1+
|
||||
- Scripting backend MONO / IL2CPP
|
||||
- [OpenCV for Unity](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088?aid=1011l4ehR) 2.5.9+
|
||||
- [OpenCV for Unity](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088?aid=1011l4ehR) 2.6.4+
|
||||
|
||||
|
||||
## Setup
|
||||
|
|
Загрузка…
Ссылка в новой задаче