void OnApplicationQuit() { KinectInterface.GAKClose(); // Free the pinned array handle. m_ColorHandle.Free(); m_DepthHandle.Free(); }
void Awake() { if (KinectSensor.instance != null) { Debug.Log("There should be only one active instance of the KinectSensor component at at time."); throw new Exception("There should be only one active instance of the KinectSensor component at a time."); } try { // The MSR Kinect DLL (native code) is going to load into the Unity process and stay resident even between debug runs of the game. // So our component must be resilient to starting up on a second run when the Kinect DLL is already loaded and // perhaps even left in a running state. Kinect does not appear to like having NuiInitialize called when it is already initialized as // it messes up the internal state and stops functioning. It is resilient to having Shutdown called right before initializing even if it // hasn't been initialized yet. So calling this first puts us in a good state on a first or second run. // However, calling NuiShutdown before starting prevents the image streams from being read, so if you want to use image data // (either depth or RGB), comment this line out. //NuiShutdown(); int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor); if (hr != 0) { throw new Exception("NuiInitialize Failed."); } hr = NativeMethods.NuiSkeletonTrackingEnable(IntPtr.Zero, 0); if (hr != 0) { throw new Exception("Cannot initialize Skeleton Data."); } depthStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.DepthAndPlayerIndex, NuiImageResolution.resolution320x240, 0, 2, IntPtr.Zero, ref depthStreamHandle); if (hr != 0) { throw new Exception("Cannot open depth stream."); } colorStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.Color, NuiImageResolution.resolution640x480, 0, 2, IntPtr.Zero, ref colorStreamHandle); if (hr != 0) { throw new Exception("Cannot open color stream."); } colorImage = new Color32[640 * 480]; double theta = Math.Atan((lookAt.y + kinectCenter.y - sensorHeight) / (lookAt.z + kinectCenter.z)); long kinectAngle = (long)(theta * (180 / Math.PI)); NativeMethods.NuiCameraSetAngle(kinectAngle); DontDestroyOnLoad(gameObject); KinectSensor.Instance = this; NativeMethods.NuiSetDeviceStatusCallback(new NuiStatusProc()); } catch (Exception e) { Debug.Log(e.Message); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { foreach (GraphicsAdapter ga in GraphicsAdapter.Adapters) { Debug.WriteLine("test"); Debug.WriteLine(ga.DeviceName); Debug.WriteLine(ga.Description); Debug.WriteLine(ga.IsDefaultAdapter); } IsFixedTimeStep = false; IsMouseVisible = true; graphics.PreferredBackBufferHeight = 720; graphics.PreferredBackBufferWidth = 1280; //graphics.PreferredBackBufferWidth = 640; //graphics.PreferredBackBufferHeight = 480; graphics.ApplyChanges(); kinect = new KinectInterface(GraphicsDevice); kinect.Start(); trackerMan = new TrackerManager(kinect); base.Initialize(); }
//end lxjk // Use this for initialization void Start() { outputDir = Application.dataPath + "/../YuYuYouEr_Kinect_Data/Recordings/"; outputFile = outputDir + "playback"; kinect = devOrEmu.getKinect(); }
// Update is called once per frame void Update() { //Update Kinect KinectInterface.GAKUpdate(.1f); //GetRawImage(); //GetDepthImage(); }
public Texture GetDepthImage() { KinectInterface.GAKCopyImageDataToTexturePtr(m_DepthHandle.AddrOfPinnedObject(), KinectInterface.NuiImageStream.NSM_IMAGE_STREAM_DEPTH_AND_PLAYERINDEX_320x240); m_DepthTexture.SetPixels32(m_DepthArray); m_DepthTexture.Apply(); return(m_DepthTexture); }
public int SetFilterData <T>(uint FilterFlag, T Data) { GCHandle Temp = GCHandle.Alloc(Data, GCHandleType.Pinned); int RetVal = KinectInterface.GAKSetFilterData(FilterFlag, Temp.AddrOfPinnedObject()); Temp.Free(); return(RetVal); }
public Texture GetRawImage() { KinectInterface.GAKCopyImageDataToTexturePtr(m_ColorHandle.AddrOfPinnedObject(), KinectInterface.NuiImageStream.NSM_IMAGE_STREAM_COLOR_640x480); m_ColorTexture.SetPixels32(m_ColorArray); m_ColorTexture.Apply(); return(m_ColorTexture); }
void OnDestroy() { KinectSensor.instance = null; m_pollThread_run = false; if (m_doNotShutdownKinect) { NativeMethods.qfKinectUnInit(); } }
//testing /*Color32[] colors = new Color32[0]; * Texture2D best_pose; */ // Use this for initialization void Start() { KinectPrefab = GameObject.Find("Kinect_Prefab"); kinect = KinectPrefab.GetComponent <DeviceOrEmulator>().getKinect(); //init our torso torso[0] = left_arm[0]; torso[1] = right_arm[0]; torso[2] = left_leg[0]; torso[3] = right_leg[0]; ReadFile(); }
public bool GetFirstTrackedSkeleton(int frameIndex, out KinectInterface.NUI_SKELETON_DATA skeletonData) { KinectInterface.NUI_SKELETON_FRAME frameData; KinectInterface.GAKGetSkeletonData(out frameData); skeletonData = new KinectInterface.NUI_SKELETON_DATA(); for (int skeletonIndex = 0; skeletonIndex < KinectInterface.NUI_SKELETON_COUNT; skeletonIndex++) { if (frameData.SkeletonData[skeletonIndex].eTrackingState == KinectInterface.NUI_SKELETON_TRACKING_STATE.NUI_SKELETON_TRACKED) { skeletonData = frameData.SkeletonData[skeletonIndex]; return(true); } } return(false); }
public int GetFilterData <T>(uint FilterFlag, ref T Data) where T : struct { var ArrayBox = new T[1] { Data }; GCHandle Temp = GCHandle.Alloc(ArrayBox, GCHandleType.Pinned); int RetVal = KinectInterface.GAKGetFilterData(FilterFlag, Temp.AddrOfPinnedObject()); Data = ArrayBox[0]; Temp.Free(); return(RetVal); }
void Awake() { if (KinectWrapper.instance != null) { Debug.Log("There should only be one active instance of KinectWrapper component"); throw new Exception("There should only be one active instance of KinectWrapper component"); } try{ int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor); if (hr != 0) { throw new Exception("Cannot initialize Skeleton Data."); } depthStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.DepthAndPlayerIndex, NuiImageResolution.resolution320x240, 0, 2, IntPtr.Zero, ref depthStreamHandle); Debug.Log(depthStreamHandle); if (hr != 0) { throw new Exception("Cannot open depth stream."); } colorStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.Color, NuiImageResolution.resolution640x480, 0, 2, IntPtr.Zero, ref colorStreamHandle); Debug.Log(colorStreamHandle); if (hr != 0) { throw new Exception("Cannot open color stream."); } colorImage = new Color32[640 * 480]; double theta = Math.Atan((lookAt.y + kinectCenter.y - sensorHeight) / (lookAt.z + kinectCenter.z)); long kinectAngle = (long)(theta * (180 / Math.PI)); NativeMethods.NuiCameraSetAngle(kinectAngle); DontDestroyOnLoad(gameObject); KinectWrapper.Instance = this; } catch (Exception e) { Debug.Log(e.Message); } }
// Use this for initialization void Start() { //Start Kinect KinectInterface.GAKInit(); //KinectInterface.GAKInitStreamFilter((uint)FilterFlags.NSFILTER_SKELETON_MIRRORING, 1.0f); KinectInterface.GAKInitStreamFilter((uint)FilterFlags.NSFILTER_SKELETON_SMOOTHING, 2.0f); PlayerManager Manager = (PlayerManager)FindObjectOfType(typeof(PlayerManager)); SetPlayerAddedCallback(Manager.PlayerAdded); SetPlayerRemovedCallback(Manager.PlayerRemoved); //SetPlayerRemappedCallback(PlayerManager.PlayerReplaced); m_ColorTexture = new Texture2D(640, 480, TextureFormat.RGBA32, false); m_ColorArray = m_ColorTexture.GetPixels32(0); m_ColorHandle = GCHandle.Alloc(m_ColorArray, GCHandleType.Pinned); m_DepthTexture = new Texture2D(320, 240, TextureFormat.RGBA32, false); m_DepthArray = m_DepthTexture.GetPixels32(); m_DepthHandle = GCHandle.Alloc(m_DepthArray, GCHandleType.Pinned); Manager.MaxPlayers = 2; }
public KinectView3D(GraphicsDevice gd, KinectInterface kinect, TrackerManager trackMan, Model sphere, Rectangle targetRect) { GraphicsDevice = gd; this.trackMan = trackMan; this.sphere = sphere; Viewport viewp = new Viewport(targetRect); camera = new Camera3D(viewp); camera.SetPosition(Vector3.UnitZ * 1); camera.LookAt(-Vector3.UnitZ); this.kinect = kinect; qb = new QuadBuilder(); int numQuads = KinectInterface.w * KinectInterface.h / (res * res); vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalColor), numQuads * 4, BufferUsage.None); indexBuffer = new IndexBuffer(GraphicsDevice, typeof(int), numQuads * 6, BufferUsage.None); effect = new BasicEffect(GraphicsDevice); lineEffect = new BasicEffect(GraphicsDevice); }
void Awake() { if (KinectSensor.instance != null) { Debug.Log("There should be only one active instance of the KinectSensor component at at time."); throw new Exception("There should be only one active instance of the KinectSensor component at a time."); } try { // The MSR Kinect DLL (native code) is going to load into the Unity process and stay resident even between debug runs of the game. // So our component must be resilient to starting up on a second run when the Kinect DLL is already loaded and // perhaps even left in a running state. Kinect does not appear to like having NuiInitialize called when it is already initialized as // it messes up the internal state and stops functioning. It is resilient to having Shutdown called right before initializing even if it // hasn't been initialized yet. So calling this first puts us in a good state on a first or second run. // However, calling NuiShutdown before starting prevents the image streams from being read, so if you want to use image data // (either depth or RGB), comment this line out. //NuiShutdown(); int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor); if (hr != 0) { throw new Exception("NuiInitialize Failed. HRESULT Fail Code: " + hr); } hr = NativeMethods.NuiSkeletonTrackingEnable(IntPtr.Zero, skeltonTrackingMode); if (hr != 0) { throw new Exception("Cannot initialize Skeleton Data."); } depthStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.DepthAndPlayerIndex, NuiImageResolution.resolution320x240, 0, 2, IntPtr.Zero, ref depthStreamHandle); //Debug.Log(depthStreamHandle); if (hr != 0) { throw new Exception("Cannot open depth stream."); } colorStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.Color, NuiImageResolution.resolution640x480, 0, 2, IntPtr.Zero, ref colorStreamHandle); //Debug.Log(colorStreamHandle); if (hr != 0) { throw new Exception("Cannot open color stream."); } colorImage = new Color32[640*480]; if(AdjustSensorAngle) { double theta = Mathf.Atan((lookAt.y+kinectCenter.y-sensorHeight) / (lookAt.z + kinectCenter.z)); long kinectAngle = (long)(theta * (180 / Mathf.PI)); NativeMethods.NuiCameraSetAngle(kinectAngle); } DontDestroyOnLoad(gameObject); KinectSensor.Instance = this; NativeMethods.NuiSetDeviceStatusCallback(new NuiStatusProc(), IntPtr.Zero); } catch (Exception e) { Debug.Log(e.Message); } }
//end lxjk // Use this for initialization void Start() { kinect = devOrEmu.getKinect(); }
//end lxjk // Use this for initialization void Start () { kinect = devOrEmu.getKinect(); }
void Awake() { if (KinectSensor.instance != null) { Debug.Log("There should be only one active instance of the KinectSensor component at at time."); throw new Exception("There should be only one active instance of the KinectSensor component at a time."); } try { int hr = NativeMethods.qfKinectInit(); if (hr != 0) { throw new Exception("NuiInitialize Failed."); } NativeMethods.qfKinectSetEnableMultiUser(m_enableMultiUser); NativeMethods.qfKinectSetEnableBackgroundRemoval(m_enableBackgroundRemoval); NativeMethods.qfKinectSetEnableKinectInteractive(m_enableInteractive); NativeMethods.qfKinectSetEnableFaceTracking(m_enableFaceTracking); NativeMethods.qfKinectSetEnableSpeechRecognition(m_enableSpeechReg); //////////////////////////////////////////////////////// depth_width = NativeMethods.qfKinectGetDepthWidth(); depth_height = NativeMethods.qfKinectGetDepthHeight(); video_width = NativeMethods.qfKinectGetVideoWidth(); video_height = NativeMethods.qfKinectGetVideoHeight(); //////////////////////////////////////////////////////// //init BackgroundRemovalImage = new Color32[video_width * video_height]; BackgroundRemovalImageTexture = new Color32[video_width * video_height]; m_BackgroundRemoval_data = new byte[video_width * video_height * 4]; colorImageTexture = new Color32[video_width * video_height]; m_color_data = new byte[video_width * video_height * 4]; //depthImage = new Color32[depth_width * depth_height]; m_depth_data = new byte[depth_width * depth_height * 4]; depthPlayerData = new short[depth_width * depth_height]; m_skldata = new float[20 * 4]; m_skldata_mul = new float[6, 20 * 4]; m_userID = new int[6]; handEvent = new byte[2]; handEvent_Multi = new byte[6, 2]; m_isLeftHandGrip_Multi = new bool[6]; m_isRightHandGrip_Multi = new bool[6]; for (int i = 0; i < skeletonFrame.SkeletonData.Length; ++i) { m_userID[i] = 0; skeletonFrame.SkeletonData[i].eTrackingState = Kinect.NuiSkeletonTrackingState.NotTracked; skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState = new NuiSkeletonPositionTrackingState[20]; skeletonFrame.SkeletonData[i].SkeletonPositions = new Vector4[20]; for (int i_skl = 0; i_skl < skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState.Length; ++i_skl) { skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState[i_skl] = Kinect.NuiSkeletonPositionTrackingState.NotTracked; } } //////////////////////////////////////////////////////// KinectSensor.Instance = this; if (null == m_th) { m_th = new System.Threading.Thread(new System.Threading.ThreadStart(pollThread)); m_th.Start(); } } catch (Exception e) { Debug.Log(e.Message); } }
public void SetPlayerRemappedCallback(PlayerRemappedCallback Delegate) { IntPtr ptr = Marshal.GetFunctionPointerForDelegate(Delegate); KinectInterface.GAKSetPlayerRemappedCallback(ptr); }
void Awake() { if (KinectSensor.instance != null) { Debug.Log("There should be only one active instance of the KinectSensor component at at time."); throw new Exception("There should be only one active instance of the KinectSensor component at a time."); } try { // The MSR Kinect DLL (native code) is going to load into the Unity process and stay resident even between debug runs of the game. // So our component must be resilient to starting up on a second run when the Kinect DLL is already loaded and // perhaps even left in a running state. Kinect does not appear to like having NuiInitialize called when it is already initialized as // it messes up the internal state and stops functioning. It is resilient to having Shutdown called right before initializing even if it // hasn't been initialized yet. So calling this first puts us in a good state on a first or second run. // However, calling NuiShutdown before starting prevents the image streams from being read, so if you want to use image data // (either depth or RGB), comment this line out. //NuiShutdown(); int hr = NativeMethods.qfKinectInit(); if (hr != 0) { throw new Exception("NuiInitialize Failed."); } NativeMethods.qfKinectSetEnableMultiUser(true); NativeMethods.qfKinectSetEnableBackgroundRemoval(true); //////////////////////////////////////////////////////// depth_width = NativeMethods.qfKinectGetDepthWidth(); depth_height = NativeMethods.qfKinectGetDepthHeight(); video_width = NativeMethods.qfKinectGetVideoWidth(); video_height = NativeMethods.qfKinectGetVideoHeight(); //////////////////////////////////////////////////////// //init BackgroundRemovalImage = new Color32[video_width * video_height]; BackgroundRemovalImageTexture = new Color32[video_width * video_height]; m_BackgroundRemoval_data = new byte[video_width * video_height * 4]; colorImage = new Color32[video_width * video_height]; colorImageTexture = new Color32[video_width * video_height]; m_color_data = new byte[video_width * video_height * 4]; //depthImage = new Color32[depth_width * depth_height]; m_depth_data = new byte[depth_width * depth_height * 4]; depthPlayerData = new short[depth_width * depth_height]; m_skldata = new float[20 * 4]; m_skldata_mul = new float[6, 20 * 4]; m_userID = new int[6]; handEvent = new byte[2]; handEvent_Multi = new byte[6, 2]; m_isLeftHandGrip_Multi = new bool[6]; m_isRightHandGrip_Multi = new bool[6]; for (int i = 0; i < skeletonFrame.SkeletonData.Length; ++i) { skeletonFrame.SkeletonData[i].eTrackingState = Kinect.NuiSkeletonTrackingState.NotTracked; skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState = new NuiSkeletonPositionTrackingState[20]; skeletonFrame.SkeletonData[i].SkeletonPositions = new Vector4[20]; for (int i_skl = 0; i_skl < skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState.Length; ++i_skl) { skeletonFrame.SkeletonData[i].eSkeletonPositionTrackingState[i_skl] = Kinect.NuiSkeletonPositionTrackingState.NotTracked; } } //////////////////////////////////////////////////////// DontDestroyOnLoad(gameObject); KinectSensor.Instance = this; if (null == m_th) { m_th = new System.Threading.Thread(new System.Threading.ThreadStart(pollThread)); m_th.Start(); } } catch (Exception e) { Debug.Log(e.Message); } }
//testing /*Color32[] colors = new Color32[0]; Texture2D best_pose; */ // Use this for initialization void Start () { KinectPrefab = GameObject.Find("Kinect_Prefab"); kinect = KinectPrefab.GetComponent<DeviceOrEmulator>().getKinect(); //init our torso torso[0] = left_arm[0]; torso[1] = right_arm[0]; torso[2] = left_leg[0]; torso[3] = right_leg[0]; ReadFile(); }
void Awake(){ if(KinectWrapper.instance != null){ Debug.Log("There should only be one active instance of KinectWrapper component"); throw new Exception("There should only be one active instance of KinectWrapper component"); } try{ int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor); if(hr != 0) throw new Exception("Cannot initialize Skeleton Data."); depthStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.DepthAndPlayerIndex, NuiImageResolution.resolution320x240, 0, 2, IntPtr.Zero, ref depthStreamHandle); Debug.Log(depthStreamHandle); if(hr != 0) throw new Exception("Cannot open depth stream."); colorStreamHandle = IntPtr.Zero; hr = NativeMethods.NuiImageStreamOpen(NuiImageType.Color, NuiImageResolution.resolution640x480, 0, 2, IntPtr.Zero, ref colorStreamHandle); Debug.Log(colorStreamHandle); if(hr != 0) throw new Exception("Cannot open color stream."); colorImage = new Color32[640*480]; double theta = Math.Atan((lookAt.y + kinectCenter.y - sensorHeight) / (lookAt.z + kinectCenter.z)); long kinectAngle = (long)(theta * (180 / Math.PI)); NativeMethods.NuiCameraSetAngle(kinectAngle); DontDestroyOnLoad(gameObject); KinectWrapper.Instance = this; } catch(Exception e){ Debug.Log(e.Message); } }