public void ReceiveFrame() { lBodies.Clear(); int nToRead = 16; byte[] buffer = new byte[nToRead]; while (oSocket.Available == 0) { if (!SocketConnected()) { bNoMoreStoredFrames = true; return; } } Receive(buffer, nToRead); //oSocket.Receive(buffer, 16, SocketFlags.None); nToRead = BitConverter.ToInt32(buffer, 0); if (nToRead <= 0) { bNoMoreStoredFrames = true; return; } int iCompressed = BitConverter.ToInt32(buffer, 4); int iDepthWidth = BitConverter.ToInt32(buffer, 8); int iDepthHeight = BitConverter.ToInt32(buffer, 12); iDepthFrameWidth = iDepthWidth; iDepthFrameHeight = iDepthHeight; buffer = new byte[nToRead]; Receive(buffer, nToRead); if (iCompressed == 1) { buffer = ZSTDDecompressor.Decompress(buffer); } if (iDepthWidth == 0) { iDepthWidth = 0; } frameDepth = new byte[iDepthWidth * iDepthHeight * 2]; frameRGB = new byte[iDepthWidth * iDepthHeight * 3]; Array.Copy(buffer, frameDepth, iDepthWidth * iDepthHeight * 2); Array.Copy(buffer, iDepthWidth * iDepthHeight * 2, frameRGB, 0, iDepthWidth * iDepthHeight * 3); //Receive body data int startIdx = iDepthWidth * iDepthHeight * 5; //Receive body data int nBodies = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; for (int i = 0; i < nBodies; i++) { Body tempBody = new Body(); tempBody.bTracked = BitConverter.ToBoolean(buffer, startIdx++); int nJoints = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; tempBody.lJoints = new List <Joint>(nJoints); tempBody.lJointsInColorSpace = new List <Point2f>(nJoints); for (int j = 0; j < nJoints; j++) { Joint tempJoint = new Joint(); Point2f tempPoint = new Point2f(); tempJoint.jointType = (JointType)BitConverter.ToInt32(buffer, startIdx); startIdx += 4; tempJoint.trackingState = (TrackingState)BitConverter.ToInt32(buffer, startIdx); startIdx += 4; tempJoint.position.X = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempJoint.position.Y = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempJoint.position.Z = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempPoint.X = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempPoint.Y = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempBody.lJoints.Add(tempJoint); tempBody.lJointsInColorSpace.Add(tempPoint); } lBodies.Add(tempBody); } }
public void ReceiveFrame() { lFrameRGB.Clear(); lFrameVerts.Clear(); lBodies.Clear(); lFaces.Clear(); lObject.Clear(); int nToRead; byte[] buffer = new byte[1024]; while (oSocket.Available == 0) { if (!SocketConnected()) { return; } } oSocket.Receive(buffer, 8, SocketFlags.None); nToRead = BitConverter.ToInt32(buffer, 0); int iCompressed = BitConverter.ToInt32(buffer, 4); if (nToRead == -1) { bNoMoreStoredFrames = true; return; } buffer = new byte[nToRead]; int nAlreadyRead = 0; while (nAlreadyRead != nToRead) { while (oSocket.Available == 0) { if (!SocketConnected()) { return; } } nAlreadyRead += oSocket.Receive(buffer, nAlreadyRead, nToRead - nAlreadyRead, SocketFlags.None); } if (iCompressed == 1) { buffer = ZSTDDecompressor.Decompress(buffer); } //Receive depth and color data int startIdx = 0; int n_vertices = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; for (int i = 0; i < n_vertices; i++) { for (int j = 0; j < 3; j++) { lFrameRGB.Add(buffer[startIdx++]); } for (int j = 0; j < 3; j++) { float val = BitConverter.ToInt16(buffer, startIdx); //converting from milimeters to meters val /= 1000.0f; lFrameVerts.Add(val); startIdx += 2; } } /* * //Receive body data * int nBodies = BitConverter.ToInt32(buffer, startIdx); * startIdx += 4; * for (int i = 0; i < nBodies; i++) * { * Body tempBody = new Body(); * tempBody.bTracked = BitConverter.ToBoolean(buffer, startIdx++); * int nJoints = BitConverter.ToInt32(buffer, startIdx); * startIdx += 4; * * tempBody.lJoints = new List<Joint>(nJoints); * tempBody.lJointsInColorSpace = new List<Point2f>(nJoints); * * for (int j = 0; j < nJoints; j++) * { * Joint tempJoint = new Joint(); * Point2f tempPoint = new Point2f(); * * tempJoint.jointType = (JointType)BitConverter.ToInt32(buffer, startIdx); * startIdx += 4; * tempJoint.trackingState = (TrackingState)BitConverter.ToInt32(buffer, startIdx); * startIdx += 4; * tempJoint.position.X = BitConverter.ToSingle(buffer, startIdx); * startIdx += 4; * tempJoint.position.Y = BitConverter.ToSingle(buffer, startIdx); * startIdx += 4; * tempJoint.position.Z = BitConverter.ToSingle(buffer, startIdx); * startIdx += 4; * * tempPoint.X = BitConverter.ToSingle(buffer, startIdx); * startIdx += 4; * tempPoint.Y = BitConverter.ToSingle(buffer, startIdx); * startIdx += 4; * * tempBody.lJoints.Add(tempJoint); * tempBody.lJointsInColorSpace.Add(tempPoint); * } * * lBodies.Add(tempBody); * } */ /////////////////////////// 통신////////////////////////////// // list.count 필요? face list 만들기! int nFaces = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; for (int i = 0; i < nFaces; i++) { float headx = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; float heady = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; float headz = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; float nosex = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; float nosey = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; float nosez = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; float pid = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; // headx /= 1000.0f; // heady /= 1000.0f; // headz /= 1000.0f; // nosex /= 1000.0f; // nosey /= 1000.0f; // nosez /= 1000.0f; lFaces.Add(headx); lFaces.Add(heady); lFaces.Add(headz); lFaces.Add(nosex); lFaces.Add(nosey); lFaces.Add(nosez); lFaces.Add(pid); } ///////////////////////////////////////////////////////////// // object 정보 int nob = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; for (int i = 0; i < nob; i++) { float obid = BitConverter.ToSingle(buffer, startIdx); //오브젝트 ID startIdx += 4; float obx = BitConverter.ToSingle(buffer, startIdx); //오브젝트 X좌표 startIdx += 4; float oby = BitConverter.ToSingle(buffer, startIdx); //오브젝트 Y좌표 startIdx += 4; float obz = BitConverter.ToSingle(buffer, startIdx); //오브젝트 Z좌표 startIdx += 4; float kiid = BitConverter.ToSingle(buffer, startIdx); //키넥트 ID 좌표 startIdx += 4; float hou = BitConverter.ToSingle(buffer, startIdx); //시 startIdx += 4; float mi = BitConverter.ToSingle(buffer, startIdx); //분 startIdx += 4; float se = BitConverter.ToSingle(buffer, startIdx); //초 startIdx += 4; lObject.Add(obid); lObject.Add(obx); lObject.Add(oby); lObject.Add(obz); lObject.Add(kiid); lObject.Add(hou); lObject.Add(mi); lObject.Add(se); } /////////////////////////////////////////////////////////////////////////////////////////////// }
public void ReceiveFrame() { lFrameRGB.Clear(); lFrameVerts.Clear(); lBodies.Clear(); int nToRead; byte[] buffer = new byte[1024]; while (oSocket.Available == 0) { if (!SocketConnected()) { return; } } oSocket.Receive(buffer, 8, SocketFlags.None); nToRead = BitConverter.ToInt32(buffer, 0); int iCompressed = BitConverter.ToInt32(buffer, 4); if (nToRead == -1) { bNoMoreStoredFrames = true; return; } buffer = new byte[nToRead]; int nAlreadyRead = 0; while (nAlreadyRead != nToRead) { while (oSocket.Available == 0) { if (!SocketConnected()) { return; } } nAlreadyRead += oSocket.Receive(buffer, nAlreadyRead, nToRead - nAlreadyRead, SocketFlags.None); } if (iCompressed == 1) { buffer = ZSTDDecompressor.Decompress(buffer); } //Receive depth and color data int startIdx = 0; int n_vertices = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; for (int i = 0; i < n_vertices; i++) { for (int j = 0; j < 3; j++) { lFrameRGB.Add(buffer[startIdx++]); } for (int j = 0; j < 3; j++) { float val = BitConverter.ToInt16(buffer, startIdx); //converting from milimeters to meters val /= 1000.0f; lFrameVerts.Add(val); startIdx += 2; } } //Receive body data int nBodies = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; for (int i = 0; i < nBodies; i++) { Body tempBody = new Body(); tempBody.bTracked = BitConverter.ToBoolean(buffer, startIdx++); int nJoints = BitConverter.ToInt32(buffer, startIdx); startIdx += 4; tempBody.lJoints = new List <Joint>(nJoints); tempBody.lJointsInColorSpace = new List <Point2f>(nJoints); for (int j = 0; j < nJoints; j++) { Joint tempJoint = new Joint(); Point2f tempPoint = new Point2f(); tempJoint.jointType = (JointType)BitConverter.ToInt32(buffer, startIdx); startIdx += 4; tempJoint.trackingState = (TrackingState)BitConverter.ToInt32(buffer, startIdx); startIdx += 4; tempJoint.position.X = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempJoint.position.Y = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempJoint.position.Z = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempPoint.X = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempPoint.Y = BitConverter.ToSingle(buffer, startIdx); startIdx += 4; tempBody.lJoints.Add(tempJoint); tempBody.lJointsInColorSpace.Add(tempPoint); } lBodies.Add(tempBody); } }