1
1
using HoloLensCameraStream ;
2
- using HoloLensWithOpenCVForUnity . UnityUtils . Helper ;
2
+ using HoloLensWithOpenCVForUnity . UnityIntegration . Helper . Source2Mat ;
3
3
using OpenCVForUnity . Calib3dModule ;
4
4
using OpenCVForUnity . CoreModule ;
5
5
using OpenCVForUnity . ImgprocModule ;
6
6
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 ;
9
10
using System ;
10
11
using System . Collections . Generic ;
11
12
using System . IO ;
14
15
using UnityEngine ;
15
16
using UnityEngine . SceneManagement ;
16
17
using UnityEngine . UI ;
18
+ using static OpenCVForUnity . UnityIntegration . OpenCVARUtils ;
17
19
18
20
namespace HoloLensWithOpenCVForUnityExample
19
21
{
@@ -255,9 +257,9 @@ protected void Start()
255
257
imageOptimizationHelper = gameObject . GetComponent < ImageOptimizationHelper > ( ) ;
256
258
webCamTextureToMatHelper = gameObject . GetComponent < HLCameraStream2MatHelper > ( ) ;
257
259
#if WINDOWS_UWP && ! DISABLE_HOLOLENSCAMSTREAM_API
258
- webCamTextureToMatHelper . frameMatAcquired += OnFrameMatAcquired ;
260
+ webCamTextureToMatHelper . FrameMatAcquired += OnFrameMatAcquired ;
259
261
#endif
260
- webCamTextureToMatHelper . outputColorFormat = Source2MatHelperColorFormat . GRAY ;
262
+ webCamTextureToMatHelper . OutputColorFormat = Source2MatHelperColorFormat . GRAY ;
261
263
webCamTextureToMatHelper . Initialize ( ) ;
262
264
}
263
265
@@ -276,7 +278,7 @@ public void OnWebCamTextureToMatHelperInitialized()
276
278
if ( enableDownScale )
277
279
{
278
280
downScaleMat = imageOptimizationHelper . GetDownScaleMat ( grayMat ) ;
279
- DOWNSCALE_RATIO = imageOptimizationHelper . downscaleRatio ;
281
+ DOWNSCALE_RATIO = imageOptimizationHelper . DownscaleRatio ;
280
282
}
281
283
else
282
284
{
@@ -296,7 +298,7 @@ public void OnWebCamTextureToMatHelperInitialized()
296
298
//Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
297
299
298
300
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 ( ) ) ;
300
302
if ( enableDownScale )
301
303
DebugUtils . AddDebugStr ( "enableDownScale = true: " + DOWNSCALE_RATIO + " / " + width + " x " + height ) ;
302
304
@@ -431,13 +433,13 @@ public void OnWebCamTextureToMatHelperInitialized()
431
433
432
434
433
435
// 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 )
435
437
{
436
- webCamTextureToMatHelper . flipHorizontal = true ;
438
+ webCamTextureToMatHelper . FlipHorizontal = true ;
437
439
}
438
- else if ( ! webCamTextureToMatHelper . IsFrontFacing ( ) && webCamTextureToMatHelper . flipHorizontal )
440
+ else if ( ! webCamTextureToMatHelper . IsFrontFacing ( ) && webCamTextureToMatHelper . FlipHorizontal )
439
441
{
440
- webCamTextureToMatHelper . flipHorizontal = false ;
442
+ webCamTextureToMatHelper . FlipHorizontal = false ;
441
443
}
442
444
443
445
rgbMat4preview = new Mat ( ) ;
@@ -528,7 +530,7 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
528
530
if ( enableDownScale )
529
531
{
530
532
downScaleMat = imageOptimizationHelper . GetDownScaleMat ( grayMat ) ;
531
- DOWNSCALE_RATIO = imageOptimizationHelper . downscaleRatio ;
533
+ DOWNSCALE_RATIO = imageOptimizationHelper . DownscaleRatio ;
532
534
}
533
535
else
534
536
{
@@ -591,10 +593,10 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
591
593
double [ ] tvecArr = new double [ 3 ] ;
592
594
tvec . get ( 0 , 0 , tvecArr ) ;
593
595
tvecArr [ 2 ] /= DOWNSCALE_RATIO ;
594
- PoseData poseData = ARUtils . ConvertRvecTvecToPoseData ( rvecArr , tvecArr ) ;
596
+ PoseData poseData = OpenCVARUtils . ConvertRvecTvecToPoseData ( rvecArr , tvecArr ) ;
595
597
596
598
// Create transform matrix.
597
- transformationM = Matrix4x4 . TRS ( poseData . pos , poseData . rot , Vector3 . one ) ;
599
+ transformationM = Matrix4x4 . TRS ( poseData . Pos , poseData . Rot , Vector3 . one ) ;
598
600
599
601
lock ( sync )
600
602
{
@@ -653,7 +655,7 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
653
655
654
656
if ( displayCameraPreview && rgbMat4preview != null )
655
657
{
656
- Utils . matToTexture2D ( rgbMat4preview , texture ) ;
658
+ OpenCVMatUtils . MatToTexture2D ( rgbMat4preview , texture ) ;
657
659
rgbMat4preview . Dispose ( ) ;
658
660
}
659
661
@@ -674,7 +676,7 @@ public void OnFrameMatAcquired(Mat grayMat, Matrix4x4 projectionMatrix, Matrix4x
674
676
}
675
677
else
676
678
{
677
- ARUtils . SetTransformFromMatrix ( arGameObject . transform , ref ARM ) ;
679
+ OpenCVARUtils . SetTransformFromMatrix ( arGameObject . transform , ref ARM ) ;
678
680
}
679
681
}
680
682
}
@@ -731,7 +733,7 @@ void Update()
731
733
if ( enableDownScale )
732
734
{
733
735
downScaleMat = imageOptimizationHelper . GetDownScaleMat ( grayMat ) ;
734
- DOWNSCALE_RATIO = imageOptimizationHelper . downscaleRatio ;
736
+ DOWNSCALE_RATIO = imageOptimizationHelper . DownscaleRatio ;
735
737
}
736
738
else
737
739
{
@@ -826,10 +828,10 @@ private void DetectARUcoMarker()
826
828
double [ ] tvecArr = new double [ 3 ] ;
827
829
tvec . get ( 0 , 0 , tvecArr ) ;
828
830
tvecArr [ 2 ] /= DOWNSCALE_RATIO ;
829
- PoseData poseData = ARUtils . ConvertRvecTvecToPoseData ( rvecArr , tvecArr ) ;
831
+ PoseData poseData = OpenCVARUtils . ConvertRvecTvecToPoseData ( rvecArr , tvecArr ) ;
830
832
831
833
// Create transform matrix.
832
- transformationM = Matrix4x4 . TRS ( poseData . pos , poseData . rot , Vector3 . one ) ;
834
+ transformationM = Matrix4x4 . TRS ( poseData . Pos , poseData . Rot , Vector3 . one ) ;
833
835
834
836
// Right-handed coordinates system (OpenCV) to left-handed one (Unity)
835
837
// https://stackoverflow.com/questions/30234945/change-handedness-of-a-row-major-4x4-transformation-matrix
@@ -874,7 +876,7 @@ private void OnDetectionDone()
874
876
}
875
877
}
876
878
877
- Utils . matToTexture2D ( rgbMat4preview , texture ) ;
879
+ OpenCVMatUtils . MatToTexture2D ( rgbMat4preview , texture ) ;
878
880
}
879
881
880
882
if ( arCamera != null && applyEstimationPose )
@@ -892,7 +894,7 @@ private void OnDetectionDone()
892
894
}
893
895
else
894
896
{
895
- ARUtils . SetTransformFromMatrix ( arGameObject . transform , ref ARM ) ;
897
+ OpenCVARUtils . SetTransformFromMatrix ( arGameObject . transform , ref ARM ) ;
896
898
}
897
899
}
898
900
}
@@ -955,7 +957,7 @@ void LateUpdate()
955
957
void OnDestroy ( )
956
958
{
957
959
#if WINDOWS_UWP && ! DISABLE_HOLOLENSCAMSTREAM_API
958
- webCamTextureToMatHelper . frameMatAcquired -= OnFrameMatAcquired ;
960
+ webCamTextureToMatHelper . FrameMatAcquired -= OnFrameMatAcquired ;
959
961
#endif
960
962
webCamTextureToMatHelper . Dispose ( ) ;
961
963
imageOptimizationHelper . Dispose ( ) ;
@@ -998,7 +1000,7 @@ public void OnStopButtonClick()
998
1000
/// </summary>
999
1001
public void OnChangeCameraButtonClick ( )
1000
1002
{
1001
- webCamTextureToMatHelper . requestedIsFrontFacing = ! webCamTextureToMatHelper . requestedIsFrontFacing ;
1003
+ webCamTextureToMatHelper . RequestedIsFrontFacing = ! webCamTextureToMatHelper . RequestedIsFrontFacing ;
1002
1004
}
1003
1005
1004
1006
/// <summary>
0 commit comments