@@ -20,7 +20,7 @@ namespace HoloLensWithOpenCVForUnityExample
2020
2121 /// <summary>
2222 /// Hololens camera stream to mat helper.
23- /// v 1.0.0
23+ /// v 1.0.1
2424 ///
2525 /// Combination of camera frame size and frame rate that can be acquired on Hololens. (width x height : framerate)
2626 /// 1280 x 720 : 30
@@ -63,7 +63,7 @@ public class HololensCameraStreamToMatHelper : WebCamTextureToMatHelper
6363 protected System . Object latestImageBytesLockObject = new System . Object ( ) ;
6464
6565 protected HoloLensCameraStream . VideoCapture videoCapture ;
66- protected CameraParameters cameraParams ;
66+ protected HoloLensCameraStream . CameraParameters cameraParams ;
6767
6868 protected Matrix4x4 _cameraToWorldMatrix = Matrix4x4 . identity ;
6969 protected Matrix4x4 cameraToWorldMatrix {
@@ -116,6 +116,14 @@ protected byte[] latestImageBytes {
116116 set { lock ( lockObject )
117117 _hasInitDone = value ; }
118118 }
119+
120+ protected bool _hasInitEventCompleted = false ;
121+ protected bool hasInitEventCompleted {
122+ get { lock ( lockObject )
123+ return _hasInitEventCompleted ; }
124+ set { lock ( lockObject )
125+ _hasInitEventCompleted = value ; }
126+ }
119127
120128 protected virtual void LateUpdate ( )
121129 {
@@ -159,7 +167,7 @@ protected virtual void OnFrameSampleAcquired(VideoCaptureSample sample)
159167 didUpdateThisFrame = true ;
160168 didUpdateImageBufferInCurrentFrame = true ;
161169
162- if ( hasInitDone && frameMatAcquired != null )
170+ if ( hasInitEventCompleted && frameMatAcquired != null )
163171 {
164172 Mat mat = new Mat ( cameraParams . cameraResolutionHeight , cameraParams . cameraResolutionWidth , CvType . CV_8UC4 ) ;
165173 OpenCVForUnity . Utils . copyToMat < byte > ( latestImageBytes , mat ) ;
@@ -181,15 +189,15 @@ protected virtual void OnFrameSampleAcquired(VideoCaptureSample sample)
181189 }
182190 }
183191
184- protected virtual CameraParameters CreateCameraParams ( HoloLensCameraStream . VideoCapture videoCapture )
192+ protected virtual HoloLensCameraStream . CameraParameters CreateCameraParams ( HoloLensCameraStream . VideoCapture videoCapture )
185193 {
186194 int min1 = videoCapture . GetSupportedResolutions ( ) . Min ( r => Mathf . Abs ( ( r . width * r . height ) - ( _requestedWidth * _requestedHeight ) ) ) ;
187195 HoloLensCameraStream . Resolution resolution = videoCapture . GetSupportedResolutions ( ) . First ( r => Mathf . Abs ( ( r . width * r . height ) - ( _requestedWidth * _requestedHeight ) ) == min1 ) ;
188196
189197 float min2 = videoCapture . GetSupportedFrameRatesForResolution ( resolution ) . Min ( f => Mathf . Abs ( f - _requestedFPS ) ) ;
190198 float frameRate = videoCapture . GetSupportedFrameRatesForResolution ( resolution ) . First ( f => Mathf . Abs ( f - _requestedFPS ) == min2 ) ;
191199
192- CameraParameters cameraParams = new CameraParameters ( ) ;
200+ HoloLensCameraStream . CameraParameters cameraParams = new HoloLensCameraStream . CameraParameters ( ) ;
193201 cameraParams . cameraResolutionHeight = resolution . height ;
194202 cameraParams . cameraResolutionWidth = resolution . width ;
195203 cameraParams . frameRate = Mathf . RoundToInt ( frameRate ) ;
@@ -279,7 +287,11 @@ protected override IEnumerator _Initialize ()
279287 } else {
280288
281289 //Fetch a pointer to Unity's spatial coordinate system if you need pixel mapping
290+ #if UNITY_2017_2_OR_NEWER
291+ spatialCoordinateSystemPtr = UnityEngine . XR . WSA . WorldManager . GetNativeISpatialCoordinateSystemPtr ( ) ;
292+ #else
282293 spatialCoordinateSystemPtr = UnityEngine . VR . WSA . WorldManager . GetNativeISpatialCoordinateSystemPtr ( ) ;
294+ #endif
283295
284296 HoloLensCameraStream . VideoCapture . CreateAync ( videoCapture => {
285297
@@ -348,12 +360,13 @@ protected override IEnumerator _Initialize ()
348360 }
349361
350362 isInitWaiting = false ;
363+ hasInitDone = true ;
351364 initCoroutine = null ;
352365
353366 if ( onInitialized != null )
354367 onInitialized . Invoke ( ) ;
355368
356- hasInitDone = true ;
369+ hasInitEventCompleted = true ;
357370
358371 break ;
359372 } else {
@@ -390,6 +403,15 @@ protected override IEnumerator _Initialize ()
390403 }
391404 }
392405
406+ /// <summary>
407+ /// Indicates whether this instance has been initialized.
408+ /// </summary>
409+ /// <returns><c>true</c>, if this instance has been initialized, <c>false</c> otherwise.</returns>
410+ public override bool IsInitialized ( )
411+ {
412+ return hasInitDone ;
413+ }
414+
393415 /// <summary>
394416 /// Starts the webcam texture.
395417 /// </summary>
@@ -572,6 +594,7 @@ protected override void ReleaseResources ()
572594 {
573595 isInitWaiting = false ;
574596 hasInitDone = false ;
597+ hasInitEventCompleted = false ;
575598
576599 latestImageBytes = null ;
577600 didUpdateThisFrame = false ;
0 commit comments