Пример #1
0
        SerializerClass getSkelData(Skeleton skel, KinectSensor ks, string epoch)
        {
            SerializerClass dataSerializer = new SerializerClass();
            dataSerializer.data = new Data("kinect", "entity", "Skeletal", "Kinect", "SK01", epoch, Guid.NewGuid().ToString());

            for (int i = 1; i < 4; i++)
            {
                if (ks.DeviceConnectionId == appConfig["kinect" + i + "_usb"])
                {
                    dataSerializer.data.serial = appConfig["kinect" + i];
                }

            }
            if (skel.TrackingState != SkeletonTrackingState.PositionOnly)
            {
                List<Joint> jointData = new List<Joint>();
                jointData.Add(skel.Joints[JointType.AnkleLeft]);
                jointData.Add(skel.Joints[JointType.AnkleRight]);
                jointData.Add(skel.Joints[JointType.ElbowLeft]);
                jointData.Add(skel.Joints[JointType.ElbowRight]);
                jointData.Add(skel.Joints[JointType.FootLeft]);
                jointData.Add(skel.Joints[JointType.FootRight]);
                jointData.Add(skel.Joints[JointType.HandLeft]);
                jointData.Add(skel.Joints[JointType.HandRight]);
                jointData.Add(skel.Joints[JointType.Head]);
                jointData.Add(skel.Joints[JointType.HipCenter]);
                jointData.Add(skel.Joints[JointType.HipLeft]);
                jointData.Add(skel.Joints[JointType.HipRight]);
                jointData.Add(skel.Joints[JointType.KneeLeft]);
                jointData.Add(skel.Joints[JointType.KneeRight]);
                jointData.Add(skel.Joints[JointType.ShoulderCenter]);
                jointData.Add(skel.Joints[JointType.ShoulderLeft]);
                jointData.Add(skel.Joints[JointType.ShoulderRight]);
                jointData.Add(skel.Joints[JointType.Spine]);
                jointData.Add(skel.Joints[JointType.WristLeft]);
                jointData.Add(skel.Joints[JointType.WristRight]);

                dataSerializer.data.message = "[";
                foreach (Joint joint in jointData)
                {
                    SkeletonPoint sp = joint.Position;
                    DepthImagePoint depthPoint = ks.CoordinateMapper.MapSkeletonPointToDepthPoint(sp, ks.DepthStream.Format);
                    Vector4 mt4 = skel.BoneOrientations[joint.JointType].AbsoluteRotation.Quaternion;
                    string bo = mt4.W.ToString() + "##" + mt4.X.ToString() + "##" + mt4.Y.ToString() + "##" + mt4.Z.ToString();
                    JointSerializer js = new JointSerializer(joint.JointType.ToString(), skel.TrackingId, joint.Position.X, joint.Position.Y, joint.Position.Z, joint.TrackingState.ToString(), bo, depthPoint.X, depthPoint.Y, depthPoint.Depth);
                    dataSerializer.data.message += jsserializer.Serialize(js) + ",";

                }
                dataSerializer.data.message = dataSerializer.data.message.Substring(0, dataSerializer.data.message.Length - 1);
                dataSerializer.data.message += "]";
            }
            else
            {
                dataSerializer.data.message = "[";
                dataSerializer.data.message += skel.TrackingId.ToString()+"##"+ "X:" + skel.Position.X.ToString() + "##Y:" + skel.Position.Y.ToString() + "##Z:" + skel.Position.Z.ToString()+"]";
            }

            return dataSerializer;
        }
Пример #2
0
        void ks_allFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
            string epoch = t.TotalSeconds.ToString();
            var tempKS = (KinectSensor)sender;
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame != null)
                {

                    byte[] colorData;
                    //Using standard SDK
                    colorData = new byte[colorFrame.PixelDataLength];
                    colorFrame.CopyPixelDataTo(colorData);
                    Bitmap bmap = new Bitmap(colorFrame.Width, colorFrame.Height, PixelFormat.Format32bppRgb);
                    BitmapData bmapdata = bmap.LockBits(
                    new Rectangle(0, 0, colorFrame.Width, colorFrame.Height),
                     ImageLockMode.WriteOnly,
                     bmap.PixelFormat);
                    IntPtr ptr = bmapdata.Scan0;
                    Marshal.Copy(colorData, 0, ptr, colorFrame.PixelDataLength);
                    bmap.UnlockBits(bmapdata);

                    lock (_locker4)
                    {
                        if (halfQ[tempKS])
                        {
                            //            RGBObject obj = new RGBObject(bmap, epoch);
                            //          ThreadPool.QueueUserWorkItem(new WaitCallback(RabbitMQ), (object)obj);

                        //    System.IO.MemoryStream stream = new System.IO.MemoryStream();
                        //    bmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                       //     byte[] imageBytes = stream.ToArray();
                            string base64String = GetString(colorData) ;
                            SerializerClass cData = new SerializerClass();
                            cData = getColorData(base64String, tempKS, epoch);
                            string message = jsserializer.Serialize(cData); //move to separate thread?
                            rabbitMessage rMsg = new rabbitMessage("color", message);
                            ThreadPool.QueueUserWorkItem(new WaitCallback(sendtoRabbitMQ), (object)rMsg);
                            halfQ[tempKS] = false;
                        }
                    }

                }
            }

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                //Create buffer to store skeletons
                Skeleton[] skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];

                //Write skeleton data into buffer
                skeletonFrame.CopySkeletonDataTo(skeletons);

                //Loop into each skeleton
                foreach (Skeleton skel in skeletons)
                {
                    switch (skel.TrackingState)
                    {
                        case SkeletonTrackingState.NotTracked:
                            //No skeleton data, no need to do a thing
                            continue;
                        default:
                            //Serialize position data to a JSON string for sending
                            SerializerClass dataClass = new SerializerClass();
                            dataClass = getSkelData(skel, tempKS, epoch);
                            dataClass.action = "rawevents";
                            dataClass.site = "kyoto";
                            string message = jsserializer.Serialize(dataClass); //move to separate thread?
                            rabbitMessage rMsg = new rabbitMessage("skeletal", message);
                            //SendTCPMessage(message);
                            ThreadPool.QueueUserWorkItem(new WaitCallback(saveLocal), (object)message);
                            try
                            {
                                lock (_locker4)
                                {
                                    if (halfC[tempKS])
                                    {
                                        ThreadPool.QueueUserWorkItem(new WaitCallback(sendtoRabbitMQ), (object)rMsg);
                                        halfC[tempKS] = false;
                                    }
                                }
                            }
                            catch (Exception ex) {

                                saveLocal(ex.Message);

                            }
                            //sendtoRabbitMQ(message);

                            continue;

                    }
                }
            }
        }
Пример #3
0
        SerializerClass getColorData(string b64, KinectSensor ks, string epoch)
        {
            SerializerClass dataSerializer = new SerializerClass();
            dataSerializer.data = new Data("kinect", "entity", "Color", "Kinect", "RGB02", epoch, Guid.NewGuid().ToString());

            for (int i = 1; i < 4; i++)
            {
                if (ks.UniqueKinectId == appConfig["kinect" + i + "_usb"])
                {
                    dataSerializer.data.serial = appConfig["kinect" + i];
                }

            }

            dataSerializer.data.message = b64;

            return dataSerializer;
        }