async Task StartHoloLensMediaFrameSourceGroups() { #if ENABLE_WINMD_SUPPORT // Plugin doesn't work in the Unity editor myText.text = "Initializing MediaFrameSourceGroups..."; // PV Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Setting up sensor frame streamer"); _sensorType = (SensorType)sensorTypePv; _sensorFrameStreamerPv = new SensorFrameStreamer(); _sensorFrameStreamerPv.Enable(_sensorType); // Spatial perception Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Setting up spatial perception"); _spatialPerception = new SpatialPerception(); // Enable media frame source groups // PV Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Setting up the media frame source group"); _pvMediaFrameSourceGroup = new MediaFrameSourceGroup( MediaFrameSourceGroupType.PhotoVideoCamera, _spatialPerception, _sensorFrameStreamerPv); _pvMediaFrameSourceGroup.Enable(_sensorType); // Start media frame source groups myText.text = "Starting MediaFrameSourceGroups..."; // Photo video Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Starting the media frame source group"); await _pvMediaFrameSourceGroup.StartAsync(); _mediaFrameSourceGroupsStarted = true; myText.text = "MediaFrameSourceGroups started..."; // Initialize the Unity coordinate system // Get pointer to Unity's spatial coordinate system // https://github.com/qian256/HoloLensARToolKit/blob/master/ARToolKitUWP-Unity/Scripts/ARUWPVideo.cs try { _unityCoordinateSystem = Marshal.GetObjectForIUnknown(WorldManager.GetNativeISpatialCoordinateSystemPtr()) as SpatialCoordinateSystem; } catch (Exception) { Debug.Log("ArUcoDetectionHoloLensUnity.ArUcoMarkerDetection: Could not get pointer to Unity spatial coordinate system."); throw; } // Initialize the aruco marker detector with parameters _arUcoMarkerTracker = new ArUcoMarkerTracker( markerSize, (int)arUcoDictionaryName, _unityCoordinateSystem); #endif }
async Task StartHoloLensMediaFrameSourceGroups() { #if ENABLE_WINMD_SUPPORT // Plugin doesn't work in the Unity editor myText.text = "Initalizing MediaFrameSourceGroups..."; // PV _sensorFrameStreamerPv = new SensorFrameStreamer(); _sensorType = (SensorType)sensorTypePv; _sensorFrameStreamerPv.Enable(_sensorType); // Research streams _sensorFrameStreamerResearch = new SensorFrameStreamer(); _sensorTypeResearch = (SensorType)sensorTypeShortDepth; _sensorFrameStreamerResearch.Enable(_sensorTypeResearch); // Spatial perception _spatialPerception = new SpatialPerception(); // Enable media frame source groups // PV _pvMediaFrameSourceGroup = new MediaFrameSourceGroup( MediaFrameSourceGroupType.PhotoVideoCamera, _spatialPerception, _sensorFrameStreamerPv); _pvMediaFrameSourceGroup.Enable(_sensorType); // ToF Depth _shortDepthMediaFrameSourceGroup = new MediaFrameSourceGroup( MediaFrameSourceGroupType.HoloLensResearchModeSensors, _spatialPerception, _sensorFrameStreamerResearch); _shortDepthMediaFrameSourceGroup.Enable(_sensorTypeResearch); // Start media frame source groups myText.text = "Starting MediaFrameSourceGroups..."; // Photo video await _pvMediaFrameSourceGroup.StartAsync(); // ToF Depth await _shortDepthMediaFrameSourceGroup.StartAsync(); _mediaFrameSourceGroupsStarted = true; myText.text = "MediaFrameSourceGroups started..."; #endif }
async Task StartHoloLensMediaFrameSourceGroups() { #if ENABLE_WINMD_SUPPORT // Plugin doesn't work in the Unity editor myText.text = "Initializing MediaFrameSourceGroups..."; // PV Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Setting up sensor frame streamer"); _sensorType = (SensorType)sensorTypePv; _sensorFrameStreamerPv = new SensorFrameStreamer(); _sensorFrameStreamerPv.Enable(_sensorType); // Spatial perception Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Setting up spatial perception"); _spatialPerception = new SpatialPerception(); // Enable media frame source groups // PV Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Setting up the media frame source group"); // Check if using research mode sensors if (sensorTypePv == CvUtils.SensorTypeUnity.PhotoVideo) { _mediaFrameSourceGroup = MediaFrameSourceGroupType.PhotoVideoCamera; } else { _mediaFrameSourceGroup = MediaFrameSourceGroupType.HoloLensResearchModeSensors; } // Cast device type _deviceType = (HoloLensForCV.DeviceType)deviceType; _pvMediaFrameSourceGroup = new MediaFrameSourceGroup( _mediaFrameSourceGroup, _spatialPerception, _deviceType, _sensorFrameStreamerPv, // Calibration parameters from opencv, compute once for each hololens 2 device calibParams.focalLength.x, calibParams.focalLength.y, calibParams.principalPoint.x, calibParams.principalPoint.y, calibParams.radialDistortion.x, calibParams.radialDistortion.y, calibParams.radialDistortion.z, calibParams.tangentialDistortion.x, calibParams.tangentialDistortion.y, calibParams.imageHeight, calibParams.imageWidth); _pvMediaFrameSourceGroup.Enable(_sensorType); // Start media frame source groups myText.text = "Starting MediaFrameSourceGroups..."; // Photo video Debug.Log("HoloLensForCVUnity.ArUcoDetection.StartHoloLensMediaFrameSourceGroup: Starting the media frame source group"); await _pvMediaFrameSourceGroup.StartAsync(); _mediaFrameSourceGroupsStarted = true; myText.text = "MediaFrameSourceGroups started..."; // Initialize the Unity coordinate system // Get pointer to Unity's spatial coordinate system // https://github.com/qian256/HoloLensARToolKit/blob/master/ARToolKitUWP-Unity/Scripts/ARUWPVideo.cs try { _unityCoordinateSystem = Marshal.GetObjectForIUnknown(WorldManager.GetNativeISpatialCoordinateSystemPtr()) as SpatialCoordinateSystem; } catch (Exception) { Debug.Log("ArUcoDetectionHoloLensUnity.ArUcoMarkerDetection: Could not get pointer to Unity spatial coordinate system."); throw; } // Initialize the aruco marker detector with parameters await _pvMediaFrameSourceGroup.StartArUcoMarkerTrackerAsync( markerSize, (int)arUcoDictionaryName, _unityCoordinateSystem); #endif }