public KinectInterop.SensorData OpenDefaultSensor(KinectInterop.FrameSource dwFlags, float sensorAngle, bool bUseMultiSource) { sourceFlags = dwFlags; NuiInitializeFlags nuiFlags = // NuiInitializeFlags.UsesNone; NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesDepthAndPlayerIndex; if ((dwFlags & KinectInterop.FrameSource.TypeBody) != 0) { nuiFlags |= NuiInitializeFlags.UsesSkeleton; } if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0) { nuiFlags |= NuiInitializeFlags.UsesColor; } if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0) { nuiFlags |= NuiInitializeFlags.UsesDepthAndPlayerIndex; } if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0) { nuiFlags |= NuiInitializeFlags.UsesDepthAndPlayerIndex; } if ((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0) { nuiFlags |= (NuiInitializeFlags.UsesColor | (NuiInitializeFlags)0x8000); } if ((dwFlags & KinectInterop.FrameSource.TypeAudio) != 0) { nuiFlags |= NuiInitializeFlags.UsesAudio; } FacetrackingManager[] faceManagers = GameObject.FindObjectsOfType(typeof(FacetrackingManager)) as FacetrackingManager[]; if (faceManagers != null && faceManagers.Length > 0) { for (int i = 0; i < faceManagers.Length; i++) { if (faceManagers[i].enabled) { //Debug.Log("Found FacetrackingManager => UsesColor"); nuiFlags |= NuiInitializeFlags.UsesColor; break; } } } SpeechManager[] speechManagers = GameObject.FindObjectsOfType(typeof(SpeechManager)) as SpeechManager[]; if (speechManagers != null && speechManagers.Length > 0) { for (int i = 0; i < speechManagers.Length; i++) { if (speechManagers[i].enabled) { //Debug.Log("Found SpeechManager => UsesAudio"); nuiFlags |= NuiInitializeFlags.UsesAudio; break; } } } int hr = InitKinectSensor(nuiFlags, true, (int)Constants.ColorImageResolution, (int)Constants.DepthImageResolution, Constants.IsNearMode); if (hr == 0) { // set sensor angle SetKinectElevationAngle((int)sensorAngle); // initialize Kinect interaction hr = InitKinectInteraction(); if (hr != 0) { Debug.LogError(string.Format("Error initializing KinectInteraction: hr=0x{0:X}", hr)); } KinectInterop.SensorData sensorData = new KinectInterop.SensorData(); sensorData.bodyCount = Constants.NuiSkeletonCount; sensorData.jointCount = Constants.JointCount; sensorData.depthCameraFOV = 46.6f; sensorData.colorCameraFOV = 48.6f; sensorData.depthCameraOffset = 0.01f; sensorData.faceOverlayOffset = 0.01f; NuiImageResolutionToSize(Constants.ColorImageResolution, out sensorData.colorImageWidth, out sensorData.colorImageHeight); // sensorData.colorImageWidth = Constants.ColorImageWidth; // sensorData.colorImageHeight = Constants.ColorImageHeight; if ((dwFlags & KinectInterop.FrameSource.TypeColor) != 0) { //colorStreamHandle = GetColorStreamHandle(); sensorData.colorImage = new byte[sensorData.colorImageWidth * sensorData.colorImageHeight * 4]; } NuiImageResolutionToSize(Constants.DepthImageResolution, out sensorData.depthImageWidth, out sensorData.depthImageHeight); // sensorData.depthImageWidth = Constants.DepthImageWidth; // sensorData.depthImageHeight = Constants.DepthImageHeight; if ((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0) { //depthStreamHandle = GetDepthStreamHandle(); sensorData.depthImage = new ushort[sensorData.depthImageWidth * sensorData.depthImageHeight]; } if ((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0) { sensorData.bodyIndexImage = new byte[sensorData.depthImageWidth * sensorData.depthImageHeight]; } if ((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0) { sensorData.infraredImage = new ushort[sensorData.colorImageWidth * sensorData.colorImageHeight]; } if ((dwFlags & KinectInterop.FrameSource.TypeBody) != 0) { skeletonFrame = new NuiSkeletonFrame() { SkeletonData = new NuiSkeletonData[Constants.NuiSkeletonCount] }; // default values used to pass to smoothing function smoothParameters = new NuiTransformSmoothParameters(); smoothParameters.fSmoothing = 0.5f; smoothParameters.fCorrection = 0.5f; smoothParameters.fPrediction = 0.5f; smoothParameters.fJitterRadius = 0.05f; smoothParameters.fMaxDeviationRadius = 0.04f; } return sensorData; } else { Debug.LogError("InitKinectSensor failed: " + GetNuiErrorString(hr)); } return null; }
public static extern int NuiTransformSmooth(ref NuiSkeletonFrame pSkeletonFrame, ref NuiTransformSmoothParameters pSmoothingParams);
private static extern int NuiTransformSmooth(ref NuiSkeletonFrame pSkeletonFrame, ref NuiTransformSmoothParameters pSmoothingParams);