Skip to content

Commit 6942129

Browse files
committed
v1.1.0 Updated OpenCVForUnity version to 3.0.0.
1 parent 2ce6c15 commit 6942129

35 files changed

+929
-596
lines changed

HLWithOpenCVExampleMRTK2/Assets/HoloLensWithOpenCVForUnityExample/HLArUcoExample/HLArUcoExample.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using HoloLensCameraStream;
2-
using HoloLensWithOpenCVForUnity.UnityUtils.Helper;
2+
using HoloLensWithOpenCVForUnity.UnityIntegration.Helper.Source2Mat;
33
using OpenCVForUnity.Calib3dModule;
44
using OpenCVForUnity.CoreModule;
55
using OpenCVForUnity.ImgprocModule;
66
using OpenCVForUnity.ObjdetectModule;
7-
using OpenCVForUnity.UnityUtils;
8-
using OpenCVForUnity.UnityUtils.Helper;
7+
using OpenCVForUnity.UnityIntegration;
8+
using OpenCVForUnity.UnityIntegration.Helper.Optimization;
9+
using OpenCVForUnity.UnityIntegration.Helper.Source2Mat;
910
using System;
1011
using System.Collections.Generic;
1112
using System.IO;
@@ -14,6 +15,7 @@
1415
using UnityEngine;
1516
using UnityEngine.SceneManagement;
1617
using UnityEngine.UI;
18+
using static OpenCVForUnity.UnityIntegration.OpenCVARUtils;
1719

1820
namespace HoloLensWithOpenCVForUnityExample
1921
{
@@ -255,9 +257,9 @@ protected void Start()
255257
imageOptimizationHelper = gameObject.GetComponent<ImageOptimizationHelper>();
256258
webCamTextureToMatHelper = gameObject.GetComponent<HLCameraStream2MatHelper>();
257259
#if WINDOWS_UWP && !DISABLE_HOLOLENSCAMSTREAM_API
258-
webCamTextureToMatHelper.frameMatAcquired += OnFrameMatAcquired;
260+
webCamTextureToMatHelper.FrameMatAcquired += OnFrameMatAcquired;
259261
#endif
260-
webCamTextureToMatHelper.outputColorFormat = Source2MatHelperColorFormat.GRAY;
262+
webCamTextureToMatHelper.OutputColorFormat = Source2MatHelperColorFormat.GRAY;
261263
webCamTextureToMatHelper.Initialize();
262264
}
263265

@@ -276,7 +278,7 @@ public void OnWebCamTextureToMatHelperInitialized()
276278
if (enableDownScale)
277279
{
278280
downScaleMat = imageOptimizationHelper.GetDownScaleMat(grayMat);
279-
DOWNSCALE_RATIO = imageOptimizationHelper.downscaleRatio;
281+
DOWNSCALE_RATIO = imageOptimizationHelper.DownscaleRatio;
280282
}
281283
else
282284
{
@@ -296,7 +298,7 @@ public void OnWebCamTextureToMatHelperInitialized()
296298
//Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
297299

298300

299-
DebugUtils.AddDebugStr(webCamTextureToMatHelper.outputColorFormat.ToString() + " " + webCamTextureToMatHelper.GetWidth() + " x " + webCamTextureToMatHelper.GetHeight() + " : " + webCamTextureToMatHelper.GetFPS());
301+
DebugUtils.AddDebugStr(webCamTextureToMatHelper.OutputColorFormat.ToString() + " " + webCamTextureToMatHelper.GetWidth() + " x " + webCamTextureToMatHelper.GetHeight() + " : " + webCamTextureToMatHelper.GetFPS());
300302
if (enableDownScale)
301303
DebugUtils.AddDebugStr("enableDownScale = true: " + DOWNSCALE_RATIO + " / " + width + " x " + height);
302304

@@ -431,13 +433,13 @@ public void OnWebCamTextureToMatHelperInitialized()
431433

432434

433435
// If the WebCam is front facing, flip the Mat horizontally. Required for successful detection of AR markers.
434-
if (webCamTextureToMatHelper.IsFrontFacing() && !webCamTextureToMatHelper.flipHorizontal)
436+
if (webCamTextureToMatHelper.IsFrontFacing() && !webCamTextureToMatHelper.FlipHorizontal)
435437
{
436-
webCamTextureToMatHelper.flipHorizontal = true;
438+
webCamTextureToMatHelper.FlipHorizontal = true;
437439
}
438-
else if (!webCamTextureToMatHelper.IsFrontFacing() && webCamTextureToMatHelper.flipHorizontal)
440+
else if (!webCamTextureToMatHelper.IsFrontFacing() && webCamTextureToMatHelper.FlipHorizontal)
439441
{
440-
webCamTextureToMatHelper.flipHorizontal = false;
442+
webCamTextureToMatHelper.FlipHorizontal = false;
441443
}
442444

443445
rgbMat4preview = new Mat();
@@ -528,7 +530,7 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
528530
if (enableDownScale)
529531
{
530532
downScaleMat = imageOptimizationHelper.GetDownScaleMat(grayMat);
531-
DOWNSCALE_RATIO = imageOptimizationHelper.downscaleRatio;
533+
DOWNSCALE_RATIO = imageOptimizationHelper.DownscaleRatio;
532534
}
533535
else
534536
{
@@ -591,10 +593,10 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
591593
double[] tvecArr = new double[3];
592594
tvec.get(0, 0, tvecArr);
593595
tvecArr[2] /= DOWNSCALE_RATIO;
594-
PoseData poseData = ARUtils.ConvertRvecTvecToPoseData(rvecArr, tvecArr);
596+
PoseData poseData = OpenCVARUtils.ConvertRvecTvecToPoseData(rvecArr, tvecArr);
595597

596598
// Create transform matrix.
597-
transformationM = Matrix4x4.TRS(poseData.pos, poseData.rot, Vector3.one);
599+
transformationM = Matrix4x4.TRS(poseData.Pos, poseData.Rot, Vector3.one);
598600

599601
lock (sync)
600602
{
@@ -653,7 +655,7 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
653655

654656
if (displayCameraPreview && rgbMat4preview != null)
655657
{
656-
Utils.matToTexture2D(rgbMat4preview, texture);
658+
OpenCVMatUtils.MatToTexture2D(rgbMat4preview, texture);
657659
rgbMat4preview.Dispose();
658660
}
659661

@@ -674,7 +676,7 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
674676
}
675677
else
676678
{
677-
ARUtils.SetTransformFromMatrix(arGameObject.transform, ref ARM);
679+
OpenCVARUtils.SetTransformFromMatrix(arGameObject.transform, ref ARM);
678680
}
679681
}
680682
}
@@ -731,7 +733,7 @@ void Update()
731733
if (enableDownScale)
732734
{
733735
downScaleMat = imageOptimizationHelper.GetDownScaleMat(grayMat);
734-
DOWNSCALE_RATIO = imageOptimizationHelper.downscaleRatio;
736+
DOWNSCALE_RATIO = imageOptimizationHelper.DownscaleRatio;
735737
}
736738
else
737739
{
@@ -826,10 +828,10 @@ private void DetectARUcoMarker()
826828
double[] tvecArr = new double[3];
827829
tvec.get(0, 0, tvecArr);
828830
tvecArr[2] /= DOWNSCALE_RATIO;
829-
PoseData poseData = ARUtils.ConvertRvecTvecToPoseData(rvecArr, tvecArr);
831+
PoseData poseData = OpenCVARUtils.ConvertRvecTvecToPoseData(rvecArr, tvecArr);
830832

831833
// Create transform matrix.
832-
transformationM = Matrix4x4.TRS(poseData.pos, poseData.rot, Vector3.one);
834+
transformationM = Matrix4x4.TRS(poseData.Pos, poseData.Rot, Vector3.one);
833835

834836
// Right-handed coordinates system (OpenCV) to left-handed one (Unity)
835837
// https://stackoverflow.com/questions/30234945/change-handedness-of-a-row-major-4x4-transformation-matrix
@@ -874,7 +876,7 @@ private void OnDetectionDone()
874876
}
875877
}
876878

877-
Utils.matToTexture2D(rgbMat4preview, texture);
879+
OpenCVMatUtils.MatToTexture2D(rgbMat4preview, texture);
878880
}
879881

880882
if (arCamera != null && applyEstimationPose)
@@ -892,7 +894,7 @@ private void OnDetectionDone()
892894
}
893895
else
894896
{
895-
ARUtils.SetTransformFromMatrix(arGameObject.transform, ref ARM);
897+
OpenCVARUtils.SetTransformFromMatrix(arGameObject.transform, ref ARM);
896898
}
897899
}
898900
}
@@ -955,7 +957,7 @@ void LateUpdate()
955957
void OnDestroy()
956958
{
957959
#if WINDOWS_UWP && !DISABLE_HOLOLENSCAMSTREAM_API
958-
webCamTextureToMatHelper.frameMatAcquired -= OnFrameMatAcquired;
960+
webCamTextureToMatHelper.FrameMatAcquired -= OnFrameMatAcquired;
959961
#endif
960962
webCamTextureToMatHelper.Dispose();
961963
imageOptimizationHelper.Dispose();
@@ -998,7 +1000,7 @@ public void OnStopButtonClick()
9981000
/// </summary>
9991001
public void OnChangeCameraButtonClick()
10001002
{
1001-
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
1003+
webCamTextureToMatHelper.RequestedIsFrontFacing = !webCamTextureToMatHelper.RequestedIsFrontFacing;
10021004
}
10031005

10041006
/// <summary>

HLWithOpenCVExampleMRTK2/Assets/HoloLensWithOpenCVForUnityExample/HLArUcoExample/HLArUcoExample.unity

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,7 +3488,7 @@ GameObject:
34883488
serializedVersion: 6
34893489
m_Component:
34903490
- component: {fileID: 1709852085}
3491-
- component: {fileID: 1709852084}
3491+
- component: {fileID: 1709852087}
34923492
- component: {fileID: 1709852083}
34933493
- component: {fileID: 1709852086}
34943494
m_Layer: 0
@@ -3520,11 +3520,12 @@ MonoBehaviour:
35203520
_flipHorizontal: 0
35213521
_outputColorFormat: 0
35223522
_timeoutFrameCount: 300
3523-
onInitialized:
3523+
_onInitialized:
35243524
m_PersistentCalls:
35253525
m_Calls:
35263526
- m_Target: {fileID: 1709852086}
3527-
m_TargetAssemblyTypeName:
3527+
m_TargetAssemblyTypeName: HoloLensWithOpenCVForUnityExample.HLArUcoExample,
3528+
Assembly-CSharp
35283529
m_MethodName: OnWebCamTextureToMatHelperInitialized
35293530
m_Mode: 1
35303531
m_Arguments:
@@ -3535,11 +3536,12 @@ MonoBehaviour:
35353536
m_StringArgument:
35363537
m_BoolArgument: 0
35373538
m_CallState: 2
3538-
onDisposed:
3539+
_onDisposed:
35393540
m_PersistentCalls:
35403541
m_Calls:
35413542
- m_Target: {fileID: 1709852086}
3542-
m_TargetAssemblyTypeName:
3543+
m_TargetAssemblyTypeName: HoloLensWithOpenCVForUnityExample.HLArUcoExample,
3544+
Assembly-CSharp
35433545
m_MethodName: OnWebCamTextureToMatHelperDisposed
35443546
m_Mode: 1
35453547
m_Arguments:
@@ -3550,11 +3552,12 @@ MonoBehaviour:
35503552
m_StringArgument:
35513553
m_BoolArgument: 0
35523554
m_CallState: 2
3553-
onErrorOccurred:
3555+
_onErrorOccurred:
35543556
m_PersistentCalls:
35553557
m_Calls:
35563558
- m_Target: {fileID: 1709852086}
3557-
m_TargetAssemblyTypeName:
3559+
m_TargetAssemblyTypeName: HoloLensWithOpenCVForUnityExample.HLArUcoExample,
3560+
Assembly-CSharp
35583561
m_MethodName: OnWebCamTextureToMatHelperErrorOccurred
35593562
m_Mode: 0
35603563
m_Arguments:
@@ -3565,21 +3568,6 @@ MonoBehaviour:
35653568
m_StringArgument:
35663569
m_BoolArgument: 0
35673570
m_CallState: 2
3568-
avoidAndroidFrontCameraLowLightIssue: 0
3569-
--- !u!114 &1709852084
3570-
MonoBehaviour:
3571-
m_ObjectHideFlags: 0
3572-
m_CorrespondingSourceObject: {fileID: 0}
3573-
m_PrefabInstance: {fileID: 0}
3574-
m_PrefabAsset: {fileID: 0}
3575-
m_GameObject: {fileID: 1709852081}
3576-
m_Enabled: 1
3577-
m_EditorHideFlags: 0
3578-
m_Script: {fileID: 11500000, guid: d8d27c020f1865746b5abf91a35964df, type: 3}
3579-
m_Name:
3580-
m_EditorClassIdentifier:
3581-
_downscaleRatio: 2
3582-
_frameSkippingRatio: 1
35833571
--- !u!4 &1709852085
35843572
Transform:
35853573
m_ObjectHideFlags: 0
@@ -3627,6 +3615,20 @@ MonoBehaviour:
36273615
videoFPS: {fileID: 483362305815949845}
36283616
trackFPS: {fileID: 1543301699}
36293617
debugStr: {fileID: 483484711471432421}
3618+
--- !u!114 &1709852087
3619+
MonoBehaviour:
3620+
m_ObjectHideFlags: 0
3621+
m_CorrespondingSourceObject: {fileID: 0}
3622+
m_PrefabInstance: {fileID: 0}
3623+
m_PrefabAsset: {fileID: 0}
3624+
m_GameObject: {fileID: 1709852081}
3625+
m_Enabled: 1
3626+
m_EditorHideFlags: 0
3627+
m_Script: {fileID: 11500000, guid: f065446083c6ae5449076b65cf4452ca, type: 3}
3628+
m_Name:
3629+
m_EditorClassIdentifier:
3630+
_downscaleRatio: 2
3631+
_frameSkippingRatio: 1
36303632
--- !u!1 &1802466379
36313633
GameObject:
36323634
m_ObjectHideFlags: 0

HLWithOpenCVExampleMRTK2/Assets/HoloLensWithOpenCVForUnityExample/HLCameraStream2MatHelperExample/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 System;
55

66
namespace HoloLensWithOpenCVForUnityExample
@@ -37,7 +37,7 @@ public ComicFilter(int blackThresh = 60, int grayThresh = 120, int thickness = 5
3737
if (blackThresh <= i && i < grayThresh)
3838
lutArray[i] = 255;
3939
}
40-
MatUtils.copyToMat(lutArray, grayLUT);
40+
OpenCVMatUtils.CopyToMat(lutArray, grayLUT);
4141

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

5959
}
60-
MatUtils.copyToMat(contrastAdjustmentsLUTArray, contrastAdjustmentsLUT);
60+
OpenCVMatUtils.CopyToMat(contrastAdjustmentsLUTArray, contrastAdjustmentsLUT);
6161
}
6262
}
6363

0 commit comments

Comments
 (0)