@@ -20,7 +20,7 @@ namespace HoloLensWithOpenCVForUnityExample
20
20
21
21
/// <summary>
22
22
/// Hololens camera stream to mat helper.
23
- /// v 1.0.0
23
+ /// v 1.0.1
24
24
///
25
25
/// Combination of camera frame size and frame rate that can be acquired on Hololens. (width x height : framerate)
26
26
/// 1280 x 720 : 30
@@ -63,7 +63,7 @@ public class HololensCameraStreamToMatHelper : WebCamTextureToMatHelper
63
63
protected System . Object latestImageBytesLockObject = new System . Object ( ) ;
64
64
65
65
protected HoloLensCameraStream . VideoCapture videoCapture ;
66
- protected CameraParameters cameraParams ;
66
+ protected HoloLensCameraStream . CameraParameters cameraParams ;
67
67
68
68
protected Matrix4x4 _cameraToWorldMatrix = Matrix4x4 . identity ;
69
69
protected Matrix4x4 cameraToWorldMatrix {
@@ -116,6 +116,14 @@ protected byte[] latestImageBytes {
116
116
set { lock ( lockObject )
117
117
_hasInitDone = value ; }
118
118
}
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
+ }
119
127
120
128
protected virtual void LateUpdate ( )
121
129
{
@@ -159,7 +167,7 @@ protected virtual void OnFrameSampleAcquired(VideoCaptureSample sample)
159
167
didUpdateThisFrame = true ;
160
168
didUpdateImageBufferInCurrentFrame = true ;
161
169
162
- if ( hasInitDone && frameMatAcquired != null )
170
+ if ( hasInitEventCompleted && frameMatAcquired != null )
163
171
{
164
172
Mat mat = new Mat ( cameraParams . cameraResolutionHeight , cameraParams . cameraResolutionWidth , CvType . CV_8UC4 ) ;
165
173
OpenCVForUnity . Utils . copyToMat < byte > ( latestImageBytes , mat ) ;
@@ -181,15 +189,15 @@ protected virtual void OnFrameSampleAcquired(VideoCaptureSample sample)
181
189
}
182
190
}
183
191
184
- protected virtual CameraParameters CreateCameraParams ( HoloLensCameraStream . VideoCapture videoCapture )
192
+ protected virtual HoloLensCameraStream . CameraParameters CreateCameraParams ( HoloLensCameraStream . VideoCapture videoCapture )
185
193
{
186
194
int min1 = videoCapture . GetSupportedResolutions ( ) . Min ( r => Mathf . Abs ( ( r . width * r . height ) - ( _requestedWidth * _requestedHeight ) ) ) ;
187
195
HoloLensCameraStream . Resolution resolution = videoCapture . GetSupportedResolutions ( ) . First ( r => Mathf . Abs ( ( r . width * r . height ) - ( _requestedWidth * _requestedHeight ) ) == min1 ) ;
188
196
189
197
float min2 = videoCapture . GetSupportedFrameRatesForResolution ( resolution ) . Min ( f => Mathf . Abs ( f - _requestedFPS ) ) ;
190
198
float frameRate = videoCapture . GetSupportedFrameRatesForResolution ( resolution ) . First ( f => Mathf . Abs ( f - _requestedFPS ) == min2 ) ;
191
199
192
- CameraParameters cameraParams = new CameraParameters ( ) ;
200
+ HoloLensCameraStream . CameraParameters cameraParams = new HoloLensCameraStream . CameraParameters ( ) ;
193
201
cameraParams . cameraResolutionHeight = resolution . height ;
194
202
cameraParams . cameraResolutionWidth = resolution . width ;
195
203
cameraParams . frameRate = Mathf . RoundToInt ( frameRate ) ;
@@ -279,7 +287,11 @@ protected override IEnumerator _Initialize ()
279
287
} else {
280
288
281
289
//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
282
293
spatialCoordinateSystemPtr = UnityEngine . VR . WSA . WorldManager . GetNativeISpatialCoordinateSystemPtr ( ) ;
294
+ #endif
283
295
284
296
HoloLensCameraStream . VideoCapture . CreateAync ( videoCapture => {
285
297
@@ -348,12 +360,13 @@ protected override IEnumerator _Initialize ()
348
360
}
349
361
350
362
isInitWaiting = false ;
363
+ hasInitDone = true ;
351
364
initCoroutine = null ;
352
365
353
366
if ( onInitialized != null )
354
367
onInitialized . Invoke ( ) ;
355
368
356
- hasInitDone = true ;
369
+ hasInitEventCompleted = true ;
357
370
358
371
break ;
359
372
} else {
@@ -390,6 +403,15 @@ protected override IEnumerator _Initialize ()
390
403
}
391
404
}
392
405
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
+
393
415
/// <summary>
394
416
/// Starts the webcam texture.
395
417
/// </summary>
@@ -572,6 +594,7 @@ protected override void ReleaseResources ()
572
594
{
573
595
isInitWaiting = false ;
574
596
hasInitDone = false ;
597
+ hasInitEventCompleted = false ;
575
598
576
599
latestImageBytes = null ;
577
600
didUpdateThisFrame = false ;
0 commit comments