public KinectInterop.SensorData OpenDefaultSensor(KinectInterop.FrameSource dwFlags, float sensorAngle, bool bUseMultiSource) { KinectInterop.SensorData sensorData = new KinectInterop.SensorData(); sensorFlags = dwFlags; kinectSensor = KinectSensor.GetDefault(); if(kinectSensor == null) return null; coordMapper = kinectSensor.CoordinateMapper; this.bodyCount = kinectSensor.BodyFrameSource.BodyCount; sensorData.bodyCount = this.bodyCount; sensorData.jointCount = 25; sensorData.depthCameraFOV = 60f; sensorData.colorCameraFOV = 53.8f; sensorData.depthCameraOffset = -0.05f; sensorData.faceOverlayOffset = -0.04f; if((dwFlags & KinectInterop.FrameSource.TypeBody) != 0) { if(!bUseMultiSource) bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader(); bodyData = new Body[sensorData.bodyCount]; } var frameDesc = kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba); sensorData.colorImageWidth = frameDesc.Width; sensorData.colorImageHeight = frameDesc.Height; if((dwFlags & KinectInterop.FrameSource.TypeColor) != 0) { if(!bUseMultiSource) colorFrameReader = kinectSensor.ColorFrameSource.OpenReader(); sensorData.colorImage = new byte[frameDesc.BytesPerPixel * frameDesc.LengthInPixels]; } sensorData.depthImageWidth = kinectSensor.DepthFrameSource.FrameDescription.Width; sensorData.depthImageHeight = kinectSensor.DepthFrameSource.FrameDescription.Height; if((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0) { if(!bUseMultiSource) depthFrameReader = kinectSensor.DepthFrameSource.OpenReader(); sensorData.depthImage = new ushort[kinectSensor.DepthFrameSource.FrameDescription.LengthInPixels]; } if((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0) { if(!bUseMultiSource) bodyIndexFrameReader = kinectSensor.BodyIndexFrameSource.OpenReader(); sensorData.bodyIndexImage = new byte[kinectSensor.BodyIndexFrameSource.FrameDescription.LengthInPixels]; } if((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0) { if(!bUseMultiSource) infraredFrameReader = kinectSensor.InfraredFrameSource.OpenReader(); sensorData.infraredImage = new ushort[kinectSensor.InfraredFrameSource.FrameDescription.LengthInPixels]; } //if(!kinectSensor.IsOpen) { //Debug.Log("Opening sensor, available: " + kinectSensor.IsAvailable); kinectSensor.Open(); } float fWaitTime = Time.realtimeSinceStartup + 3f; while(!kinectSensor.IsAvailable && Time.realtimeSinceStartup < fWaitTime) { // wait for sensor to open } Debug.Log("K2-sensor " + (kinectSensor.IsOpen ? "opened" : "closed") + ", available: " + kinectSensor.IsAvailable); if(bUseMultiSource && dwFlags != KinectInterop.FrameSource.TypeNone && kinectSensor.IsOpen) { multiSourceFrameReader = kinectSensor.OpenMultiSourceFrameReader((FrameSourceTypes)((int)dwFlags & 0x3F)); } return sensorData; }
void Start() { hint.SetActive(false); spriteRenderer = GetComponent <SpriteRenderer>(); if (!DEBUG) { // If there hasn't assigned BodySourceManager, byebye if (bodySourceManager == null) { return; } bodyManager = bodySourceManager.GetComponent <BodySourceManager>(); // If there is no BodySourceManager if (bodyManager == null) { return; } coordinate = bodyManager.GetCoordinate(); } // for animation m_animator = gameObject.GetComponent <Animator>(); m_animator.SetBool("handclosebool", false); }
public KinectManager() { _Sensor = Kinect.KinectSensor.GetDefault(); if (_Sensor == null) { ExitWithLog("Kinect Sensor not avalibalbe"); } _Reader = _Sensor.OpenMultiSourceFrameReader( Kinect.FrameSourceTypes.Depth | Kinect.FrameSourceTypes.Body ); if (_Reader == null) { ExitWithLog("Fail to load multiframe source reader."); } DepthFrameDesc = _Sensor.DepthFrameSource.FrameDescription; Mapper = _Sensor.CoordinateMapper; DepthData = new ushort[DepthFrameDesc.LengthInPixels]; _BodyData = new Kinect.Body[_Sensor.BodyFrameSource.BodyCount]; if (!_Sensor.IsOpen) { _Sensor.Open(); } }
void Start() { winey = Resources.Load <Sprite>("KingChina"); money = Resources.Load <Sprite>("money"); normalBackground = Resources.Load <Sprite>("normalbackground"); if (!DEBUG) { // If there hasn't assigned BodySourceManager, byebye if (bodySourceManager == null) { return; } bodyManager = bodySourceManager.GetComponent <BodySourceManager>(); // If there is no BodySourceManager if (bodyManager == null) { return; } coordinate = bodyManager.GetCoordinate(); } // for animation m_animator = gameObject.GetComponent <Animator>(); m_animator.SetBool("handclosebool", false); }
public ZigInputKinectOne() { _sensor = KinectSensor.GetDefault(); _mapper = _sensor.CoordinateMapper; _depth = new KinectOneDepth(_sensor); _image = new KinectOneImage(_sensor); _labelMap = new KinectOneLabelMap(_sensor); }
void Start() { _Sensor = Kinect.KinectSensor.GetDefault(); _CoordinateMapper = _Sensor.CoordinateMapper; SensorWidth = _Sensor.ColorFrameSource.FrameDescription.Width; SensorHeight = _Sensor.ColorFrameSource.FrameDescription.Height; }
private Vector3 GetVector3FromJoint(Kinect.CoordinateMapper mapper, Kinect.Joint joint) { Kinect.ColorSpacePoint colorPoint = mapper.MapCameraPointToColorSpace(joint.Position); //Debug.Log("Position of " + joint.JointType.ToString() + ": " + joint.Position.X + "," + joint.Position.Y + "," + joint.Position.Z); float newX = (joint.Position.X * 10); float newY = joint.Position.Y * 10; return(new Vector3(newX, newY, gameObject.transform.position.z - (joint.Position.Z * 10))); }
void Start() { leftHandCube = GameObject.CreatePrimitive(PrimitiveType.Cube); rightHandCube = GameObject.CreatePrimitive(PrimitiveType.Cube); sensor = Kinect.KinectSensor.GetDefault(); mapper = sensor.CoordinateMapper; depthFrameInfo = sensor.DepthFrameSource.FrameDescription; depthImg = new Texture2D(depthFrameInfo.Width, depthFrameInfo.Height, TextureFormat.RGB24, false); }
public void CloseSensor(KinectInterop.SensorData sensorData) { if(coordMapper != null) { coordMapper = null; } if(bodyFrameReader != null) { bodyFrameReader.Dispose(); bodyFrameReader = null; } if(bodyIndexFrameReader != null) { bodyIndexFrameReader.Dispose(); bodyIndexFrameReader = null; } if(colorFrameReader != null) { colorFrameReader.Dispose(); colorFrameReader = null; } if(depthFrameReader != null) { depthFrameReader.Dispose(); depthFrameReader = null; } if(infraredFrameReader != null) { infraredFrameReader.Dispose(); infraredFrameReader = null; } if(multiSourceFrameReader != null) { multiSourceFrameReader.Dispose(); multiSourceFrameReader = null; } if(kinectSensor != null) { if (kinectSensor.IsOpen) { kinectSensor.Close(); } kinectSensor = null; } }
public StickRecognizer(KinectManager manager) { _Width = manager.DepthFrameDesc.Width; _Height = manager.DepthFrameDesc.Height; _LeftTipCache = new Kinect.CameraSpacePoint(); _RightTipCache = new Kinect.CameraSpacePoint(); _LeftCacheElapsedFrame = 10; _RightCacheElapsedFrame = 10; _Mapper = manager.Mapper; //debugPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); //debugPlane.transform.Translate(-10, 2, 0); //debugPlane.transform.Rotate(-90, 180, 0); //debugTexture = new Texture2D(manager.DepthFrameDesc.Width, manager.DepthFrameDesc.Height, TextureFormat.RGB24, false); }
void Start() { _Sensor = KinectSensor.GetDefault(); if (_Sensor != null) { _Reader = _Sensor.BodyFrameSource.OpenReader(); if (!_Sensor.IsOpen) { _Sensor.Open(); coordinateMapper=_Sensor.CoordinateMapper; } } }
void Start() { depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription; depthWidth = depthFrameDesc.Width; depthHeight = depthFrameDesc.Height; // buffer for points mapped to camera space coordinate. mapper = KinectSensor.GetDefault().CoordinateMapper; cameraSpacePoints = new CameraSpacePoint[depthWidth * depthHeight]; depthSourceManagerScript = depthSourceManager.GetComponent<DepthSourceManager>(); colorSourceManagerScript = colorSourceManager.GetComponent<ColorSourceManager>(); particles = new ParticleSystem.Particle[depthWidth * depthHeight]; color_reader = KinectSensor.GetDefault().ColorFrameSource.OpenReader(); colorFrameDesc = KinectSensor.GetDefault().ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba); colorSpacePoints = new ColorSpacePoint[depthWidth * depthHeight]; color_array = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels]; }
void Start() { // Get the description of the depth frames. depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription; depthWidth = depthFrameDesc.Width; depthHeight = depthFrameDesc.Height; // buffer for points mapped to camera space coordinate. cameraSpacePoints = new CameraSpacePoint[depthWidth * depthHeight]; mapper = KinectSensor.GetDefault ().CoordinateMapper; // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip') depthSourceManagerScript = depthSourceManager.GetComponent<DepthSourceManager> (); // particles to be drawn particles = new ParticleSystem.Particle[depthWidth * depthHeight]; }
void Start() { _Sensor = KinectSensor.GetDefault(); if (_Sensor != null) { _Mapper = _Sensor.CoordinateMapper; var frameDesc = _Sensor.DepthFrameSource.FrameDescription; // Downsample to lower resolution CreateMesh(frameDesc.Width / _DownsampleSize, frameDesc.Height / _DownsampleSize); if (!_Sensor.IsOpen) { _Sensor.Open(); } } }
// Use this for initialization void Start() { // Get the description of the depth frames. infraredFrameDesc = KinectSensor.GetDefault().InfraredFrameSource.FrameDescription; depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription; depthWidth = depthFrameDesc.Width; depthHeight = depthFrameDesc.Height; // buffer for points mapped to camera space coordinate. cameraSpacePoints = new CameraSpacePoint[depthWidth * depthHeight]; mapper = KinectSensor.GetDefault().CoordinateMapper; // get reference to infraredSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip') multiSourceManagerScript = multiSourceManager.GetComponent<MultiSourceManager>(); infraredSourceManagerScript = infraredSourceManager.GetComponent<InfraredSourceManager>(); //最初はてきとーな場所に配置 transform.position = new Vector3(0.0f, 10.0f, 10.0f); }
// Use this for initialization void Start() { mySensor = KinectSensor.GetDefault(); if (mySensor != null) { depthFrameData = new ushort[depthWidth * depthHeight]; bodyIndexFrameData = new byte[depthWidth * depthHeight]; colorFrameData = new byte[colorWidth * colorHeight * bytes_per_pixel]; displayPixels = new byte[depthWidth * depthHeight * bytes_per_pixel]; colorPoints = new ColorSpacePoint[depthWidth * depthHeight]; ninjaTex = new Texture2D(depthWidth, depthHeight, TextureFormat.BGRA32, false); if (!mySensor.IsOpen) { mySensor.Open(); } myCoordinateMapper = mySensor.CoordinateMapper; msFrameReader = mySensor.OpenMultiSourceFrameReader(FrameSourceTypes.BodyIndex | FrameSourceTypes.Color | FrameSourceTypes.Depth); //Rendering user as part of the Unity Scene background via Main Camera Rect cameraRect = Camera.main.pixelRect; float rectHeight = cameraRect.height; float rectWidth = cameraRect.width; if (rectWidth > rectHeight) rectWidth = rectHeight * depthWidth / depthHeight; else rectHeight = rectWidth * depthHeight / depthWidth; float foregroundOfsX = (cameraRect.width - rectWidth) / 2; float foregroundOfsY = (cameraRect.height - rectHeight) / 2; foregroundImgRect = new Rect(foregroundOfsX, foregroundOfsY, rectWidth, rectHeight); foregroundGuiRect = new Rect(foregroundOfsX, cameraRect.height - foregroundOfsY, rectWidth, -rectHeight); } }
void Start() { KinectOneInput input = ((KinectOneInput)KinectOneInput.Instance); _mapper = input.GetMapper(); depthInfo = input.GetDepthSensor(); textureSize = new ResolutionData(depthInfo.Sensor.DepthFrameSource.FrameDescription.Width, depthInfo.Sensor.DepthFrameSource.FrameDescription.Height); texture = new Texture2D(depthInfo.Sensor.DepthFrameSource.FrameDescription.Width, depthInfo.Sensor.DepthFrameSource.FrameDescription.Height, TextureFormat.RGBA32, false); texture.wrapMode = TextureWrapMode.Clamp; depthHistogramMap = new float[depthInfo.Sensor.DepthFrameSource.DepthMaxReliableDistance]; depthToColor = new Color32[depthInfo.Sensor.DepthFrameSource.DepthMaxReliableDistance]; outputPixels = new Color32[textureSize.Width * textureSize.Height]; if (null != target) { target.material.mainTexture = texture; } m_engageuser = this.GetComponent <KinectOneEngageSingleUser>(); CalImage2Screen(DepthImagePos.LeftMain); }
private void UpdateClothHandlers(Kinect.Body body) { foreach (AbstractClothHandler handler in clothHandlers) { for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++) { if (jt != handler.jointType) // If it's not the joint the handler wants, { continue; // Skip! } Kinect.Joint joint = body.Joints[jt]; Kinect.CoordinateMapper mapper = _BodyManager.Sensor().CoordinateMapper; Kinect.ColorSpacePoint screenPos = mapper.MapCameraPointToColorSpace(joint.Position); Vector3 jointPos = new Vector3(screenPos.X, screenPos.Y, joint.Position.Z); // Z should be distance to kinect plane //Vector3 legacy = GetVector3FromJoint(_BodyManager.Sensor().CoordinateMapper, joint); handler.UpdatePosition(body.TrackingId, joint, jointPos); } } }
void InitializeDefaultSensor() { m_pKinectSensor = KinectSensor.GetDefault(); if (m_pKinectSensor != null) { // Initialize the Kinect and get coordinate mapper and the frame reader m_pCoordinateMapper = m_pKinectSensor.CoordinateMapper; m_pKinectSensor.Open(); if (m_pKinectSensor.IsOpen) { m_pMultiSourceFrameReader = m_pKinectSensor.OpenMultiSourceFrameReader( FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex); } } if (m_pKinectSensor == null) { UnityEngine.Debug.LogError("No ready Kinect found!"); } }
// Use this for initialization void Start() { terrCollider = GetComponent <TerrainCollider>(); terrData = terrCollider.terrainData; _Sensor = KinectSensor.GetDefault(); if (_Sensor != null) { _Reader = _Sensor.DepthFrameSource.OpenReader(); _Reader.FrameArrived += _Reader_FrameArrived; _Data = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels]; Debug.LogFormat("Depth:H:{0} x W:{1}", _Sensor.DepthFrameSource.FrameDescription.Height, _Sensor.DepthFrameSource.FrameDescription.Width); Debug.LogFormat("TerrData:H:{0} x W:{1}", terrData.heightmapHeight, terrData.heightmapWidth); minDist = _Sensor.DepthFrameSource.DepthMinReliableDistance; maxDist = 1500f;// _Sensor.DepthFrameSource.DepthMaxReliableDistance; scale = 0.1f / (maxDist - minDist); Debug.LogFormat("Depth:Min:{0} x Max:{1} (Scale:{2})", minDist, maxDist, scale); mapper = _Sensor.CoordinateMapper; _Sensor.Open(); } logFile = new System.IO.StreamWriter(new System.IO.FileStream("e:\\log.txt", System.IO.FileMode.OpenOrCreate)); Debug.LogFormat("Scale:{0}", terrData.heightmapScale); data = new float[terrData.heightmapHeight, terrData.heightmapWidth]; }
void Update() { if (BodySourceManager == null) { return; } _BodyManager = BodySourceManager.GetComponent <BodySourceManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); if (data == null) { return; } List <ulong> trackedIds = new List <ulong>(); foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); } } List <ulong> knownIds = new List <ulong>(_Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { if (!_Bodies.ContainsKey(body.TrackingId)) { _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId); } RefreshBodyObject(body, _Bodies[body.TrackingId]); } } if (_CoordinateMapper == null) { _CoordinateMapper = _BodyManager.Sensor.CoordinateMapper; } }
// Use this for initialization void Start() { myProjector = GetComponent<Camera>(); tex = new Texture2D(proWidth, proHeight, TextureFormat.ARGB32, false); // buffer for points mapped to camera space coordinate. mapper = KinectSensor.GetDefault().CoordinateMapper; // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip') multiSourceManagerScript = multiSourceManager.GetComponent<MultiSourceManager>(); }
// private void Start() { m_Sensor = KinectSensor.GetDefault(); if (m_Sensor != null) { // m_CoordinateMapper = m_Sensor.CoordinateMapper; // m_Reader = m_Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Body | FrameSourceTypes.BodyIndex); var colorFrameDesc = m_Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba); ColorWidth = colorFrameDesc.Width; ColorHeight = colorFrameDesc.Height; m_ColorTexture = new Texture2D(colorFrameDesc.Width, colorFrameDesc.Height, TextureFormat.RGBA32, false); m_ColorData = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels]; m_ColorMappedToDepthPoints = new DepthSpacePoint[ColorWidth * ColorHeight]; // var depthFrameDesc = m_Sensor.DepthFrameSource.FrameDescription; DepthWidth = depthFrameDesc.Width; DepthHeight = depthFrameDesc.Height; m_DepthData = new ushort[depthFrameDesc.Width * depthFrameDesc.Height]; m_DepthCoordinates = new DepthSpacePoint[colorFrameDesc.Width * colorFrameDesc.Height]; // m_BodyData = new Body[m_Sensor.BodyFrameSource.BodyCount]; // var bodyIndexFrameDesc = m_Sensor.BodyIndexFrameSource.FrameDescription; BodyIndexWidth = bodyIndexFrameDesc.Width; BodyIndexHeight = bodyIndexFrameDesc.Height; m_BodyIndexData = new byte[ bodyIndexFrameDesc.Width * bodyIndexFrameDesc.Height ]; // if (!m_Sensor.IsOpen) { m_Sensor.Open(); } } }
void Update() { if (BodySourceManager == null) { return; } _BodyManager = BodySourceManager.GetComponent<BodySourceManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); if (data == null) { return; } if ( _CoordinateMapper ==null ) { _CoordinateMapper = _BodyManager.Sensor.CoordinateMapper; } List<ulong> trackedIds = new List<ulong>(); foreach(var body in data) { if (body == null) { continue; } if(body.IsTracked) { trackedIds.Add (body.TrackingId); } } List<ulong> knownIds = new List<ulong>(_Bodies.Keys); // First delete untracked bodies foreach(ulong trackingId in knownIds) { if(!trackedIds.Contains(trackingId)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } foreach(var body in data) { if (body == null) { continue; } if(body.IsTracked) { if(!_Bodies.ContainsKey(body.TrackingId)) { // depth distance winnow Kinect.Joint head = body.Joints[Kinect.JointType.Head]; float z = head.Position.Z; if(z >= distanceThreshold){ //Destroy(bodyObject); continue; } // 認識してるボディの数表示 認識制限1人にする Debug.Log(_Bodies.Count); if(_Bodies.Count > 0){ Debug.Log("1人プレイだよ"); continue; } _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId); } RefreshBodyObject(body, _Bodies[body.TrackingId]); } } }
void Start() { sensor = KinectSensor.GetDefault(); if ( sensor != null ) { reader = sensor.OpenMultiSourceFrameReader( FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex); coordinateMapper = sensor.CoordinateMapper; FrameDescription depthFrameDesc = sensor.DepthFrameSource.FrameDescription; depthData = new ushort[depthFrameDesc.LengthInPixels]; depthWidth = depthFrameDesc.Width; depthHeight = depthFrameDesc.Height; FrameDescription colorFrameDesc = sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba); colorLengthInBytes = colorFrameDesc.LengthInPixels * colorFrameDesc.BytesPerPixel; colorData = new byte[colorLengthInBytes]; colorWidth = colorFrameDesc.Width; colorBytesPerPixel = colorFrameDesc.BytesPerPixel; FrameDescription bodyIndexDesc = sensor.BodyIndexFrameSource.FrameDescription; bodyIndexData = new byte[bodyIndexDesc.LengthInPixels * bodyIndexDesc.BytesPerPixel]; // PREPARE THE COLOR TO DEPTH MAPPED BYTE ARRAY FOR CREATING OUR DYNAMIC TEXTURE // --------------------------------------------------------------------------------------- // STEP 1. ALLOCATE SPACE FOR THE RESULT OF MAPPING COLORSPACEPOINTS FOR EACH DEPTH FRAME POINT colorSpacePoints = new ColorSpacePoint[depthFrameDesc.LengthInPixels]; cameraSpacePoints = new CameraSpacePoint[depthFrameDesc.LengthInPixels]; // STEP 2. PREPARE THE BYTE ARRAY THAT WILL HOLD A CALCULATED COLOR PIXEL FOR EACH DEPTH PIXEL // THIS BYTE ARRAY WILL BE FED TO THE MATERIAL AND USED AS THE MESH TEXTURE mappedColorData = new byte[depthFrameDesc.LengthInPixels * colorFrameDesc.BytesPerPixel]; // STEP 3. CREATE A TEXTURE THAT HAS THE SIZE OF THE DEPTH FRAME BUT CAN HOLD RGBA VALUES FROM THE COLOR FRAME texture = new Texture2D(depthFrameDesc.Width, depthFrameDesc.Height, TextureFormat.RGBA32, false); // STEP 4. BIND THE MAIN TEXTURE TO THE LOCAL VARIABLE FOR FUTURE PROCESSING gameObject.GetComponent<Renderer>().material.mainTexture = texture; if (!sensor.IsOpen) sensor.Open(); BuildSimpleMesh(); //BuildVariableMesh(); } else { Debug.LogError("Couldn't find Kinect Sensor!"); } }
// Token: 0x060029B0 RID: 10672 RVA: 0x000D49E4 File Offset: 0x000D2DE4 internal CoordinateMapper(IntPtr pNative) { this._pNative = pNative; CoordinateMapper.Windows_Kinect_CoordinateMapper_AddRefObject(ref this._pNative); }
public void CloseSensor(KinectInterop.SensorData sensorData) { if(coordMapper != null) { coordMapper = null; } if(bodyFrameReader != null) { bodyFrameReader.Dispose(); bodyFrameReader = null; } if(bodyIndexFrameReader != null) { bodyIndexFrameReader.Dispose(); bodyIndexFrameReader = null; } if(colorFrameReader != null) { colorFrameReader.Dispose(); colorFrameReader = null; } if(depthFrameReader != null) { depthFrameReader.Dispose(); depthFrameReader = null; } if(infraredFrameReader != null) { infraredFrameReader.Dispose(); infraredFrameReader = null; } if(multiSourceFrameReader != null) { multiSourceFrameReader.Dispose(); multiSourceFrameReader = null; } if(kinectSensor != null) { //if (kinectSensor.IsOpen) { //Debug.Log("Closing sensor, available: " + kinectSensor.IsAvailable); kinectSensor.Close(); } float fWaitTime = Time.realtimeSinceStartup + 3f; while(kinectSensor.IsOpen && Time.realtimeSinceStartup < fWaitTime) { // wait for sensor to close } Debug.Log("K2-sensor " + (kinectSensor.IsOpen ? "opened" : "closed") + ", available: " + kinectSensor.IsAvailable); kinectSensor = null; } }
void Update() { if (BodySourceManager == null) { return; } _BodyManager = BodySourceManager.GetComponent<BodySourceManager>(); if (_BodyManager == null) { return; } Kinect.Body[] data = _BodyManager.GetData(); if (data == null) { return; } if ( _CoordinateMapper ==null ) { _CoordinateMapper = _BodyManager.Sensor.CoordinateMapper; } List<ulong> trackedIds = new List<ulong>(); foreach(var body in data) { if (body == null) { continue; } if(body.IsTracked) { trackedIds.Add (body.TrackingId); } } List<ulong> knownIds = new List<ulong>(_Bodies.Keys); // First delete untracked bodies foreach(ulong trackingId in knownIds) { if(!trackedIds.Contains(trackingId)) { Destroy(_Bodies[trackingId]); _Bodies.Remove(trackingId); } } foreach(var body in data) { if (body == null) { continue; } if(body.IsTracked) { if(!_Bodies.ContainsKey(body.TrackingId)) { _Bodies[body.TrackingId] = CreateBodyObject(body.TrackingId); } RefreshBodyObject(body, _Bodies[body.TrackingId]); } } }
public KinectInterop.SensorData OpenDefaultSensor(KinectInterop.FrameSource dwFlags, float sensorAngle, bool bUseMultiSource) { KinectInterop.SensorData sensorData = new KinectInterop.SensorData(); //sensorFlags = dwFlags; kinectSensor = KinectSensor.GetDefault(); if(kinectSensor == null) return null; coordMapper = kinectSensor.CoordinateMapper; this.bodyCount = kinectSensor.BodyFrameSource.BodyCount; sensorData.bodyCount = this.bodyCount; sensorData.jointCount = 25; sensorData.depthCameraFOV = 60f; sensorData.colorCameraFOV = 53.8f; sensorData.depthCameraOffset = -0.03f; if((dwFlags & KinectInterop.FrameSource.TypeBody) != 0) { if(!bUseMultiSource) bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader(); bodyData = new Body[sensorData.bodyCount]; } var frameDesc = kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba); sensorData.colorImageWidth = frameDesc.Width; sensorData.colorImageHeight = frameDesc.Height; if((dwFlags & KinectInterop.FrameSource.TypeColor) != 0) { if(!bUseMultiSource) colorFrameReader = kinectSensor.ColorFrameSource.OpenReader(); sensorData.colorImage = new byte[frameDesc.BytesPerPixel * frameDesc.LengthInPixels]; } sensorData.depthImageWidth = kinectSensor.DepthFrameSource.FrameDescription.Width; sensorData.depthImageHeight = kinectSensor.DepthFrameSource.FrameDescription.Height; if((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0) { if(!bUseMultiSource) depthFrameReader = kinectSensor.DepthFrameSource.OpenReader(); sensorData.depthImage = new ushort[kinectSensor.DepthFrameSource.FrameDescription.LengthInPixels]; } if((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0) { if(!bUseMultiSource) bodyIndexFrameReader = kinectSensor.BodyIndexFrameSource.OpenReader(); sensorData.bodyIndexImage = new byte[kinectSensor.BodyIndexFrameSource.FrameDescription.LengthInPixels]; } if((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0) { if(!bUseMultiSource) infraredFrameReader = kinectSensor.InfraredFrameSource.OpenReader(); sensorData.infraredImage = new ushort[kinectSensor.InfraredFrameSource.FrameDescription.LengthInPixels]; } if(!kinectSensor.IsOpen) { kinectSensor.Open(); } if(bUseMultiSource && dwFlags != KinectInterop.FrameSource.TypeNone && kinectSensor.IsOpen) { multiSourceFrameReader = kinectSensor.OpenMultiSourceFrameReader((FrameSourceTypes)dwFlags); } return sensorData; }
void Update() { if (bodyManager == null) { return; } bManager = bodyManager.GetComponent <BodySourceManager>(); if (bManager == null) { return; } if (mapper == null) { mapper = bManager.Sensor.CoordinateMapper; } Kinect.Body[] data = bManager.GetData(); if (data == null) { return; } List <ulong> trackedIds = new List <ulong>(); foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); } } List <ulong> knownIds = new List <ulong>(bBuff.Keys); foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { Destroy(bBuff[trackingId]); bBuff.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked && type != null) { Vector3 pos = GetVector3FromJoint(body.Joints[type]); Renderer r = GetComponentInChildren <Renderer>(); transform.position = new Vector3(pos.x, (pos.y + r.bounds.extents.y / 2), -2f); } } }
void Start () { sensor = KinectSensor.GetDefault (); if (sensor != null) { coordinateMapper = sensor.CoordinateMapper; reader = sensor.OpenMultiSourceFrameReader (FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex); FrameDescription colorFrameDesc = sensor.ColorFrameSource.CreateFrameDescription (ColorImageFormat.Rgba); texture = new Texture2D (colorFrameDesc.Width, colorFrameDesc.Height, TextureFormat.RGBA32, false); colorData = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels]; FrameDescription depthFrameDesc = sensor.DepthFrameSource.FrameDescription; depthData = new ushort[depthFrameDesc.LengthInPixels]; depthSpacePoints = new DepthSpacePoint[colorFrameDesc.LengthInPixels]; FrameDescription bodyIndexFrameDesc = sensor.BodyIndexFrameSource.FrameDescription; bodyIndexData = new byte[bodyIndexFrameDesc.BytesPerPixel * bodyIndexFrameDesc.LengthInPixels]; if (!sensor.IsOpen) { sensor.Open (); } rgbaMat = new Mat (colorFrameDesc.Height, colorFrameDesc.Width, CvType.CV_8UC4); Debug.Log ("rgbaMat " + rgbaMat.ToString ()); maskMat = new Mat (rgbaMat.rows (), rgbaMat.cols (), CvType.CV_8UC1); outputMat = new Mat (rgbaMat.rows (), rgbaMat.cols (), CvType.CV_8UC4); maskData = new byte[rgbaMat.rows () * rgbaMat.cols ()]; gameObject.transform.localScale = new Vector3 (texture.width, texture.height, 1); gameObject.GetComponent<Renderer> ().material.mainTexture = texture; Camera.main.orthographicSize = texture.height / 2; // sepia sepiaKernel = new Mat (4, 4, CvType.CV_32F); sepiaKernel.put (0, 0, /* R */0.189f, 0.769f, 0.393f, 0f); sepiaKernel.put (1, 0, /* G */0.168f, 0.686f, 0.349f, 0f); sepiaKernel.put (2, 0, /* B */0.131f, 0.534f, 0.272f, 0f); sepiaKernel.put (3, 0, /* A */0.000f, 0.000f, 0.000f, 1f); // pixelize pixelizeIntermediateMat = new Mat (); pixelizeSize0 = new Size (); //comic comicGrayMat = new Mat (texture.height, texture.width, CvType.CV_8UC1); comicLineMat = new Mat (texture.height, texture.width, CvType.CV_8UC1); comicMaskMat = new Mat (texture.height, texture.width, CvType.CV_8UC1); //create a striped background. comicBgMat = new Mat (texture.height, texture.width, CvType.CV_8UC1, new Scalar (255)); for (int i = 0; i < comicBgMat.rows ()*2.5f; i=i+4) { Core.line (comicBgMat, new Point (0, 0 + i), new Point (comicBgMat.cols (), -comicBgMat.cols () + i), new Scalar (0), 1); } comicDstMat = new Mat (texture.height, texture.width, CvType.CV_8UC1); comicGrayPixels = new byte[comicGrayMat.cols () * comicGrayMat.rows () * comicGrayMat.channels ()]; comicMaskPixels = new byte[comicMaskMat.cols () * comicMaskMat.rows () * comicMaskMat.channels ()]; } else { UnityEngine.Debug.LogError ("No ready Kinect found!"); } }
void Start() { // Get the description of the depth frames. depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription; depthWidth = depthFrameDesc.Width; depthHeight = depthFrameDesc.Height; // buffer for points mapped to camera space coordinate. cameraSpacePoints = new CameraSpacePoint[depthWidth * depthHeight]; mapper = KinectSensor.GetDefault ().CoordinateMapper; // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip') multiSourceManagerScript = multiSourceManager.GetComponent<MultiSourceManager> (); // point cloud pointCloud = new Vector3[depthWidth * depthHeight]; // crate mesh CreateMesh(depthWidth / downsampleSize, depthHeight / downsampleSize); transform.position = new Vector3(0.0f, 0.0f, 10.0f); }
//關閉Sensor等等動作。 void OnApplicationQuit() { if (_Mapper != null) { _Mapper = null; } if (_Sensor != null) { if (_Sensor.IsOpen) { _Sensor.Close(); } _Sensor = null; } }
// Use this for initialization void Start() { terrCollider = GetComponent<TerrainCollider>(); terrData = terrCollider.terrainData; _Sensor = KinectSensor.GetDefault(); if (_Sensor != null) { _Reader = _Sensor.DepthFrameSource.OpenReader(); _Reader.FrameArrived += _Reader_FrameArrived; _Data = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels]; Debug.LogFormat("Depth:H:{0} x W:{1}", _Sensor.DepthFrameSource.FrameDescription.Height, _Sensor.DepthFrameSource.FrameDescription.Width); Debug.LogFormat("TerrData:H:{0} x W:{1}", terrData.heightmapHeight, terrData.heightmapWidth); minDist = _Sensor.DepthFrameSource.DepthMinReliableDistance; maxDist = 1500f;// _Sensor.DepthFrameSource.DepthMaxReliableDistance; scale = 0.1f / (maxDist - minDist); Debug.LogFormat("Depth:Min:{0} x Max:{1} (Scale:{2})", minDist, maxDist, scale); mapper = _Sensor.CoordinateMapper; _Sensor.Open(); } logFile = new System.IO.StreamWriter(new System.IO.FileStream("e:\\log.txt", System.IO.FileMode.OpenOrCreate)); Debug.LogFormat("Scale:{0}", terrData.heightmapScale); data = new float[terrData.heightmapHeight, terrData.heightmapWidth]; }