Skip to content

Commit 884b876

Browse files
committed
v1.0.6 Updated OpenCVForUnity version to 3.0.0.
1 parent a005fa7 commit 884b876

26 files changed

+476
-312
lines changed

Assets/NrealLightWithOpenCVForUnityExample/NRCamTexture2MatHelperExample/ComicFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using OpenCVForUnity.CoreModule;
22
using OpenCVForUnity.ImgprocModule;
3-
using OpenCVForUnity.UnityUtils;
3+
using OpenCVForUnity.UnityIntegration;
44
using OpenCVForUnity.UtilsModule;
55
using System;
66

@@ -38,7 +38,7 @@ public ComicFilter(int blackThresh = 60, int grayThresh = 120, int thickness = 5
3838
if (blackThresh <= i && i < grayThresh)
3939
lutArray[i] = 255;
4040
}
41-
MatUtils.copyToMat(lutArray, grayLUT);
41+
OpenCVMatUtils.CopyToMat(lutArray, grayLUT);
4242

4343
if (drawMainLine)
4444
{
@@ -58,7 +58,7 @@ public ComicFilter(int blackThresh = 60, int grayThresh = 120, int thickness = 5
5858
contrastAdjustmentsLUTArray[i] = (a > byte.MaxValue) ? (byte)255 : (byte)a;
5959

6060
}
61-
MatUtils.copyToMat(contrastAdjustmentsLUTArray, contrastAdjustmentsLUT);
61+
OpenCVMatUtils.CopyToMat(contrastAdjustmentsLUTArray, contrastAdjustmentsLUT);
6262
}
6363
}
6464

Assets/NrealLightWithOpenCVForUnityExample/NRCamTexture2MatHelperExample/NRCamTexture2MatHelperExample.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#if !(PLATFORM_LUMIN && !UNITY_EDITOR)
22

3-
using NrealLightWithOpenCVForUnity.UnityUtils.Helper;
3+
using NrealLightWithOpenCVForUnity.UnityIntegration.Helper.Source2Mat;
44
using NRKernal;
55
using OpenCVForUnity.CoreModule;
66
using OpenCVForUnity.ImgprocModule;
7-
using OpenCVForUnity.UnityUtils;
8-
using OpenCVForUnity.UnityUtils.Helper;
7+
using OpenCVForUnity.UnityIntegration;
8+
using OpenCVForUnity.UnityIntegration.Helper.Source2Mat;
99
using UnityEngine;
1010
using UnityEngine.SceneManagement;
1111
using UnityEngine.UI;
@@ -77,13 +77,13 @@ public class NRCamTexture2MatHelperExample : MonoBehaviour
7777
void Start()
7878
{
7979
webCamTextureToMatHelper = gameObject.GetComponent<NRCamTexture2MatHelper>();
80-
webCamTextureToMatHelper.outputColorFormat = Source2MatHelperColorFormat.RGB;
80+
webCamTextureToMatHelper.OutputColorFormat = Source2MatHelperColorFormat.RGB;
8181
webCamTextureToMatHelper.Initialize();
8282

8383
// Update GUI state
84-
rotate90DegreeToggle.isOn = webCamTextureToMatHelper.rotate90Degree;
85-
flipVerticalToggle.isOn = webCamTextureToMatHelper.flipVertical;
86-
flipHorizontalToggle.isOn = webCamTextureToMatHelper.flipHorizontal;
84+
rotate90DegreeToggle.isOn = webCamTextureToMatHelper.Rotate90Degree;
85+
flipVerticalToggle.isOn = webCamTextureToMatHelper.FlipVertical;
86+
flipHorizontalToggle.isOn = webCamTextureToMatHelper.FlipHorizontal;
8787
applyComicFilterToggle.isOn = applyComicFilter;
8888
}
8989

@@ -97,7 +97,7 @@ public void OnWebCamTextureToMatHelperInitialized()
9797
Mat rgbMat = webCamTextureToMatHelper.GetMat();
9898

9999
texture = new Texture2D(rgbMat.cols(), rgbMat.rows(), TextureFormat.RGB24, false);
100-
Utils.matToTexture2D(rgbMat, texture);
100+
OpenCVMatUtils.MatToTexture2D(rgbMat, texture);
101101

102102
gameObject.GetComponent<Renderer>().material.mainTexture = texture;
103103

@@ -158,7 +158,7 @@ void Update()
158158
Imgproc.putText(rgbMat, "W:" + rgbMat.width() + " H:" + rgbMat.height() + " SO:" + Screen.orientation, new Point(5, rgbMat.rows() - 10), Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
159159
}
160160

161-
Utils.matToTexture2D(rgbMat, texture);
161+
OpenCVMatUtils.MatToTexture2D(rgbMat, texture);
162162
}
163163

164164
if (webCamTextureToMatHelper.IsPlaying())
@@ -270,17 +270,17 @@ public void OnStopButtonClick()
270270
/// </summary>
271271
public void OnChangeCameraButtonClick()
272272
{
273-
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
273+
webCamTextureToMatHelper.RequestedIsFrontFacing = !webCamTextureToMatHelper.RequestedIsFrontFacing;
274274
}
275275

276276
/// <summary>
277277
/// Raises the rotate 90 degree toggle value changed event.
278278
/// </summary>
279279
public void OnRotate90DegreeToggleValueChanged()
280280
{
281-
if (rotate90DegreeToggle.isOn != webCamTextureToMatHelper.rotate90Degree)
281+
if (rotate90DegreeToggle.isOn != webCamTextureToMatHelper.Rotate90Degree)
282282
{
283-
webCamTextureToMatHelper.rotate90Degree = rotate90DegreeToggle.isOn;
283+
webCamTextureToMatHelper.Rotate90Degree = rotate90DegreeToggle.isOn;
284284
}
285285
}
286286

@@ -289,9 +289,9 @@ public void OnRotate90DegreeToggleValueChanged()
289289
/// </summary>
290290
public void OnFlipVerticalToggleValueChanged()
291291
{
292-
if (flipVerticalToggle.isOn != webCamTextureToMatHelper.flipVertical)
292+
if (flipVerticalToggle.isOn != webCamTextureToMatHelper.FlipVertical)
293293
{
294-
webCamTextureToMatHelper.flipVertical = flipVerticalToggle.isOn;
294+
webCamTextureToMatHelper.FlipVertical = flipVerticalToggle.isOn;
295295
}
296296
}
297297

@@ -300,9 +300,9 @@ public void OnFlipVerticalToggleValueChanged()
300300
/// </summary>
301301
public void OnFlipHorizontalToggleValueChanged()
302302
{
303-
if (flipHorizontalToggle.isOn != webCamTextureToMatHelper.flipHorizontal)
303+
if (flipHorizontalToggle.isOn != webCamTextureToMatHelper.FlipHorizontal)
304304
{
305-
webCamTextureToMatHelper.flipHorizontal = flipHorizontalToggle.isOn;
305+
webCamTextureToMatHelper.FlipHorizontal = flipHorizontalToggle.isOn;
306306
}
307307
}
308308

Assets/NrealLightWithOpenCVForUnityExample/NrealArUcoExample/NrealArUcoExample.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#if !(PLATFORM_LUMIN && !UNITY_EDITOR)
22

3-
using NrealLightWithOpenCVForUnity.UnityUtils.Helper;
3+
using NrealLightWithOpenCVForUnity.UnityIntegration.Helper.Source2Mat;
44
using NRKernal;
55
using OpenCVForUnity.Calib3dModule;
66
using OpenCVForUnity.CoreModule;
77
using OpenCVForUnity.ImgprocModule;
8-
using OpenCVForUnity.UnityUtils;
9-
using OpenCVForUnity.UnityUtils.Helper;
8+
using OpenCVForUnity.UnityIntegration;
9+
using OpenCVForUnity.UnityIntegration.Helper.Source2Mat;
1010
using OpenCVForUnity.ObjdetectModule;
1111
using System;
1212
using System.Collections.Generic;
1313
using UnityEngine;
1414
using UnityEngine.SceneManagement;
1515
using UnityEngine.UI;
16+
using OpenCVForUnity.UnityIntegration.Helper.Optimization;
17+
using static OpenCVForUnity.UnityIntegration.OpenCVARUtils;
1618

1719
namespace NrealLightWithOpenCVForUnityExample
1820
{
@@ -214,7 +216,7 @@ protected void Start()
214216

215217
imageOptimizationHelper = gameObject.GetComponent<ImageOptimizationHelper>();
216218
webCamTextureToMatHelper = gameObject.GetComponent<NRCamTexture2MatHelper>();
217-
webCamTextureToMatHelper.outputColorFormat = Source2MatHelperColorFormat.GRAY;
219+
webCamTextureToMatHelper.OutputColorFormat = Source2MatHelperColorFormat.GRAY;
218220
webCamTextureToMatHelper.Initialize();
219221
}
220222

@@ -276,14 +278,14 @@ public void OnWebCamTextureToMatHelperInitialized()
276278
// if WebCamera is frontFaceing, flip Mat.
277279
if (webCamTextureToMatHelper.GetWebCamDevice().isFrontFacing)
278280
{
279-
webCamTextureToMatHelper.flipHorizontal = true;
281+
webCamTextureToMatHelper.FlipHorizontal = true;
280282
}
281283

282284
#endif
283285

284286
if (enableDownScale)
285287
{
286-
float DOWNSCALE_RATIO = imageOptimizationHelper.downscaleRatio;
288+
float DOWNSCALE_RATIO = imageOptimizationHelper.DownscaleRatio;
287289
double[] data = new double[(int)camMatrix.total()];
288290
camMatrix.get(0, 0, data);
289291
data[0] /= DOWNSCALE_RATIO;
@@ -516,10 +518,10 @@ private void DetectARUcoMarker()
516518
rvec.get(0, 0, rvecArr);
517519
double[] tvecArr = new double[3];
518520
tvec.get(0, 0, tvecArr);
519-
PoseData poseData = ARUtils.ConvertRvecTvecToPoseData(rvecArr, tvecArr);
521+
PoseData poseData = OpenCVARUtils.ConvertRvecTvecToPoseData(rvecArr, tvecArr);
520522

521523
// Create transform matrix.
522-
transformationM = Matrix4x4.TRS(poseData.pos, poseData.rot, Vector3.one);
524+
transformationM = Matrix4x4.TRS(poseData.Pos, poseData.Rot, Vector3.one);
523525

524526
// Right-handed coordinates system (OpenCV) to left-handed one (Unity)
525527
// https://stackoverflow.com/questions/30234945/change-handedness-of-a-row-major-4x4-transformation-matrix
@@ -560,7 +562,7 @@ private void OnDetectionDone()
560562
}
561563
}
562564

563-
Utils.matToTexture2D(rgbMat4preview, texture);
565+
OpenCVMatUtils.MatToTexture2D(rgbMat4preview, texture);
564566
}
565567

566568
if (applyEstimationPose)
@@ -585,7 +587,7 @@ private void OnDetectionDone()
585587
}
586588
else
587589
{
588-
ARUtils.SetTransformFromMatrix(arGameObject.transform, ref ARM);
590+
OpenCVARUtils.SetTransformFromMatrix(arGameObject.transform, ref ARM);
589591
}
590592
}
591593
}
@@ -655,7 +657,7 @@ public void OnStopButtonClick()
655657
/// </summary>
656658
public void OnChangeCameraButtonClick()
657659
{
658-
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
660+
webCamTextureToMatHelper.RequestedIsFrontFacing = !webCamTextureToMatHelper.RequestedIsFrontFacing;
659661
}
660662

661663
/// <summary>

Assets/NrealLightWithOpenCVForUnityExample/NrealArUcoExample/NrealArUcoExample.unity

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,9 +3212,9 @@ GameObject:
32123212
serializedVersion: 6
32133213
m_Component:
32143214
- component: {fileID: 1709852085}
3215+
- component: {fileID: 1709852087}
32153216
- component: {fileID: 1709852086}
32163217
- component: {fileID: 1709852083}
3217-
- component: {fileID: 1709852084}
32183218
m_Layer: 0
32193219
m_Name: NrealArUcoExample
32203220
m_TagString: Untagged
@@ -3246,20 +3246,6 @@ MonoBehaviour:
32463246
arGameObject: {fileID: 1982842543}
32473247
enableLerpFilter: 1
32483248
enableLerpFilterToggle: {fileID: 1309379128}
3249-
--- !u!114 &1709852084
3250-
MonoBehaviour:
3251-
m_ObjectHideFlags: 0
3252-
m_CorrespondingSourceObject: {fileID: 0}
3253-
m_PrefabInstance: {fileID: 0}
3254-
m_PrefabAsset: {fileID: 0}
3255-
m_GameObject: {fileID: 1709852081}
3256-
m_Enabled: 1
3257-
m_EditorHideFlags: 0
3258-
m_Script: {fileID: 11500000, guid: d8d27c020f1865746b5abf91a35964df, type: 3}
3259-
m_Name:
3260-
m_EditorClassIdentifier:
3261-
_downscaleRatio: 2
3262-
_frameSkippingRatio: 1
32633249
--- !u!4 &1709852085
32643250
Transform:
32653251
m_ObjectHideFlags: 0
@@ -3345,6 +3331,20 @@ MonoBehaviour:
33453331
m_StringArgument:
33463332
m_BoolArgument: 0
33473333
m_CallState: 2
3334+
--- !u!114 &1709852087
3335+
MonoBehaviour:
3336+
m_ObjectHideFlags: 0
3337+
m_CorrespondingSourceObject: {fileID: 0}
3338+
m_PrefabInstance: {fileID: 0}
3339+
m_PrefabAsset: {fileID: 0}
3340+
m_GameObject: {fileID: 1709852081}
3341+
m_Enabled: 1
3342+
m_EditorHideFlags: 0
3343+
m_Script: {fileID: 11500000, guid: f065446083c6ae5449076b65cf4452ca, type: 3}
3344+
m_Name:
3345+
m_EditorClassIdentifier:
3346+
_downscaleRatio: 2
3347+
_frameSkippingRatio: 1
33483348
--- !u!1 &1867008042
33493349
GameObject:
33503350
m_ObjectHideFlags: 0

Assets/NrealLightWithOpenCVForUnityExample/NrealFaceDetectionExample/NrealFaceDetectionExample.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#if !(PLATFORM_LUMIN && !UNITY_EDITOR)
22

3-
using NrealLightWithOpenCVForUnity.UnityUtils.Helper;
3+
using NrealLightWithOpenCVForUnity.UnityIntegration.Helper.Source2Mat;
44
using NrealLightWithOpenCVForUnityExample.RectangleTrack;
55
using NRKernal;
66
using OpenCVForUnity.CoreModule;
77
using OpenCVForUnity.ImgprocModule;
88
using OpenCVForUnity.ObjdetectModule;
9-
using OpenCVForUnity.UnityUtils;
10-
using OpenCVForUnity.UnityUtils.Helper;
9+
using OpenCVForUnity.UnityIntegration;
10+
using OpenCVForUnity.UnityIntegration.Helper.Optimization;
11+
using OpenCVForUnity.UnityIntegration.Helper.Source2Mat;
1112
using System;
1213
using System.Collections.Generic;
1314
using System.Threading;
@@ -173,7 +174,7 @@ protected void Start()
173174
174175
imageOptimizationHelper = gameObject.GetComponent<ImageOptimizationHelper>();
175176
webCamTextureToMatHelper = gameObject.GetComponent<NRCamTexture2MatHelper>();
176-
webCamTextureToMatHelper.outputColorFormat = Source2MatHelperColorFormat.GRAY;
177+
webCamTextureToMatHelper.OutputColorFormat = Source2MatHelperColorFormat.GRAY;
177178
webCamTextureToMatHelper.Initialize();
178179
179180
rectangleTracker = new RectangleTracker();
@@ -204,8 +205,8 @@ async void Start()
204205
// Asynchronously retrieves the readable file path from the StreamingAssets directory.
205206
Debug.Log("Preparing file access...");
206207

207-
cascade_filepath = await Utils.getFilePathAsyncTask("OpenCVForUnity/objdetect/lbpcascade_frontalface.xml", cancellationToken: cts.Token);
208-
cascade4Thread_filepath = await Utils.getFilePathAsyncTask("OpenCVForUnity/objdetect/haarcascade_frontalface_alt.xml", cancellationToken: cts.Token);
208+
cascade_filepath = await OpenCVEnv.GetFilePathTaskAsync("OpenCVForUnityExample/objdetect/lbpcascade_frontalface.xml", cancellationToken: cts.Token);
209+
cascade4Thread_filepath = await OpenCVEnv.GetFilePathTaskAsync("OpenCVForUnityExample/objdetect/haarcascade_frontalface_alt.xml", cancellationToken: cts.Token);
209210

210211
Debug.Log("Preparing file access complete!");
211212

@@ -219,18 +220,18 @@ void Run()
219220
cascade.load(cascade_filepath);
220221
if (cascade.empty())
221222
{
222-
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnity/objdetect/” to “Assets/StreamingAssets/OpenCVForUnity/objdetect/” folder. ");
223+
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnityExample/objdetect/” to “Assets/StreamingAssets/OpenCVForUnityExample/objdetect/” folder. ");
223224
}
224225

225226

226227
cascade4Thread = new CascadeClassifier();
227228
cascade4Thread.load(cascade4Thread_filepath);
228229
if (cascade4Thread.empty())
229230
{
230-
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnity/objdetect/” to “Assets/StreamingAssets/OpenCVForUnity/objdetect/” folder. ");
231+
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnityExample/objdetect/” to “Assets/StreamingAssets/OpenCVForUnityExample/objdetect/” folder. ");
231232
}
232233

233-
webCamTextureToMatHelper.outputColorFormat = Source2MatHelperColorFormat.GRAY;
234+
webCamTextureToMatHelper.OutputColorFormat = Source2MatHelperColorFormat.GRAY;
234235
webCamTextureToMatHelper.Initialize();
235236
}
236237
////
@@ -263,23 +264,23 @@ public void OnWebCamTextureToMatHelperInitialized()
263264

264265
/*
265266
cascade = new CascadeClassifier();
266-
cascade.load(Utils.getFilePath("OpenCVForUnity/objdetect/lbpcascade_frontalface.xml"));
267+
cascade.load(OpenCVEnv.GetFilePath("OpenCVForUnityExample/objdetect/lbpcascade_frontalface.xml"));
267268
#if !UNITY_WSA_10_0 || UNITY_EDITOR
268269
// "empty" method is not working on the UWP platform.
269270
if (cascade.empty())
270271
{
271-
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnity/objdetect/” to “Assets/StreamingAssets/OpenCVForUnity/objdetect/” folder. ");
272+
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnityExample/objdetect/” to “Assets/StreamingAssets/OpenCVForUnityExample/objdetect/” folder. ");
272273
}
273274
#endif
274275
275276
grayMat4Thread = new Mat();
276277
cascade4Thread = new CascadeClassifier();
277-
cascade4Thread.load(Utils.getFilePath("OpenCVForUnity/objdetect/haarcascade_frontalface_alt.xml"));
278+
cascade4Thread.load(OpenCVEnv.GetFilePath("OpenCVForUnity/objdetect/haarcascade_frontalface_alt.xml"));
278279
#if !UNITY_WSA_10_0 || UNITY_EDITOR
279280
// "empty" method is not working on the UWP platform.
280281
if (cascade4Thread.empty())
281282
{
282-
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnity/objdetect/” to “Assets/StreamingAssets/OpenCVForUnity/objdetect/” folder. ");
283+
Debug.LogError("cascade file is not loaded. Please copy from “OpenCVForUnity/StreamingAssets/OpenCVForUnityExample/objdetect/” to “Assets/StreamingAssets/OpenCVForUnityExample/objdetect/” folder. ");
283284
}
284285
#endif
285286
*/
@@ -353,7 +354,7 @@ void Update()
353354
if (enableDownScale)
354355
{
355356
downScaleMat = imageOptimizationHelper.GetDownScaleMat(grayMat);
356-
DOWNSCALE_RATIO = imageOptimizationHelper.downscaleRatio;
357+
DOWNSCALE_RATIO = imageOptimizationHelper.DownscaleRatio;
357358
}
358359
else
359360
{
@@ -433,7 +434,7 @@ void Update()
433434
DrawDownScaleFaceRects(grayMat, resultObjects.ToArray(), DOWNSCALE_RATIO, COLOR_WHITE, 6);
434435
}
435436

436-
Utils.matToTexture2D(grayMat, texture);
437+
OpenCVMatUtils.MatToTexture2D(grayMat, texture);
437438
}
438439

439440
if (webCamTextureToMatHelper.IsPlaying())
@@ -667,7 +668,7 @@ public void OnStopButtonClick()
667668
/// </summary>
668669
public void OnChangeCameraButtonClick()
669670
{
670-
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
671+
webCamTextureToMatHelper.RequestedIsFrontFacing = !webCamTextureToMatHelper.RequestedIsFrontFacing;
671672
}
672673

673674
/// <summary>

Assets/NrealLightWithOpenCVForUnityExample/NrealFaceDetectionExample/NrealFaceDetectionExample.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ MonoBehaviour:
19691969
m_GameObject: {fileID: 1076083694}
19701970
m_Enabled: 1
19711971
m_EditorHideFlags: 0
1972-
m_Script: {fileID: 11500000, guid: d8d27c020f1865746b5abf91a35964df, type: 3}
1972+
m_Script: {fileID: 11500000, guid: f065446083c6ae5449076b65cf4452ca, type: 3}
19731973
m_Name:
19741974
m_EditorClassIdentifier:
19751975
_downscaleRatio: 2

0 commit comments

Comments
 (0)