示例#1
0
        private void UpdateTrackingTime(Skeleton skeleton)
        {
            frame++;
            ColorImagePoint position =
                              kinectSensor.CoordinateMapper.MapSkeletonPointToColorPoint(skeleton.Position,
                                                                                         ColorImageFormat.RgbResolution640x480Fps30);
            BodyIDAndPostion  bodyIdAndPostion = new BodyIDAndPostion();;
            for (int i = trackingTimeList.Count - 1; i >= 0; i--)
            {
                if (skeleton.TrackingId == trackingTimeList[i].TrackingID)
                {
                    TrackingTime trackingTime = new TrackingTime();
                    trackingTime.StartTime = trackingTimeList[i].StartTime;
                    trackingTime.Time = trackingTimeList[i].Time + 1;
                    trackingTime.TrackingID = trackingTimeList[i].TrackingID;
                    trackingTime.Index = trackingTimeList[i].Index;
                    trackingTime.StayTime = trackingTimeList[i].StayTime;
                    trackingTime.CurrentSkeletonPoint = trackingTimeList[i].CurrentSkeletonPoint;
                    trackingTime.ShotCount = trackingTimeList[i].ShotCount;
                    trackingTime.TotalStayTime = trackingTimeList[i].TotalStayTime + 1;
                    float x = skeleton.Position.X - trackingTimeList[i].CurrentSkeletonPoint.X;
                    float y = skeleton.Position.Y - trackingTimeList[i].CurrentSkeletonPoint.Y;
                    float z = skeleton.Position.Z - trackingTimeList[i].CurrentSkeletonPoint.Z;
                    float distance = Math.Abs(x) + Math.Abs(y) + Math.Abs(z);
                    bodyIdAndPostion.bodyIdTextblock.Text = skeleton.TrackingId.ToString();
                    if (frame>=10)
                    {
                        trackingTime.CurrentSkeletonPoint = skeleton.Position;
                        frame = 0;
                        if (distance<0.3)
                        {
                             trackingTime.StayTime = trackingTimeList[i].StayTime + 10;
                             isStay = true;
                        }
                        else
                        {
                            isStay = false;
                            trackingTime.StayTime = 0;
                        }
                    }
                    if (isStay)
                    {
                        bodyIdAndPostion.bodyIdTextblock.Background = new SolidColorBrush(new Color());
                    }
                    if (trackingTimeList[i].StayTime>=50)
                    {
                        trackingTime.StayTime = 0;
                        if (trackingTimeList[i].ShotCount<=0)
                        {
                            SaveImage(position, trackingTimeList[i], videoElement);
                            SaveImage(position, trackingTimeList[i], colorImage);
                            trackingTime.ShotCount = trackingTimeList[i].ShotCount+1;
                        }
                    }
                    Canvas.SetLeft(bodyIdAndPostion, position.X);
                    Canvas.SetTop(bodyIdAndPostion, position.Y);
                    bodyContainer.Children.Add(bodyIdAndPostion);

                    trackingTimeList.RemoveAt(i);
                    trackingTimeList.Add(trackingTime);
                }
                break;
            }
        }
示例#2
0
        private void UpdateDataToDB(TrackingTime trackingTime)
        {
            using (var session = documentStore.OpenSession())
            {
                string id = GetDetectFaceInfoID(trackingTime.StartTime);
                DetectFaceInfo detectFaceInfo = session.Load<DetectFaceInfo>(id);

                detectFaceInfo.StartTime = trackingTime.StartTime;
                detectFaceInfo.EndTime = trackingTime.EndTime;
                detectFaceInfo.DwellTime =new TimeSpan(0,0,0,(int)trackingTime.DewellTime);
                detectFaceInfo.TotalStayTime=
                        new TimeSpan(0, 0, 0, trackingTime.TotalStayTime/30);
                Point point=new Point();
                point.X = (int)(trackingTime.CurrentSkeletonPoint.X*(-1000));
                point.Y=(int)(trackingTime.CurrentSkeletonPoint.Z*1000);
                detectFaceInfo.BodyPostion = point;

                session.SaveChanges();
            }
        }
示例#3
0
        void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            List<Int32> currentTrackingIDList=new List<int>();
            Skeleton[] skeletons = new Skeleton[0];
            bodyContainer.Children.Clear();
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);

                    foreach (var skeleton in skeletons)
                    {
                        currentTrackingIDList.Add(skeleton.TrackingId);

                        if (skeleton.TrackingState==SkeletonTrackingState.PositionOnly||
                            skeleton.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            //new body
                            if (!oldTrackingIdList.Contains(skeleton.TrackingId))
                            {
                                BodyCount++;
                                TrackingTime trackingTimeTemp=new TrackingTime();
                                trackingTimeTemp.StartTime = DateTime.Now;
                                trackingTimeTemp.TrackingID = skeleton.TrackingId;
                                trackingTimeTemp.Time = 0;
                                trackingTimeTemp.Index = trackingTimeIndex++;
                                trackingTimeList.Add(trackingTimeTemp);
                                listBox.SelectedItem = listBox.Items[listBox.Items.Count - 1];
                                CreateBodyDateToDB(trackingTimeTemp.StartTime);
                            }
                            //update body data
                            UpdateTrackingTime(skeleton);
                        }
                    }
                    // body disappear
                    foreach (var bodytrackingID in oldTrackingIdList )
                    {
                        if (!currentTrackingIDList.Contains(bodytrackingID))
                        {
                            for (int i = trackingTimeList.Count - 1; i >= 0; i--)
                            {
                                if (bodytrackingID==trackingTimeList[i].TrackingID)
                                {
                                    TrackingTime trackingTime = trackingTimeList[i];
                                    trackingTime.EndTime = DateTime.Now;
                                    trackingTime.DewellTime = (trackingTime.EndTime - trackingTime.StartTime).TotalSeconds;
                                    trackingTimeList.RemoveAt(i);
                                    trackingTimeList.Add(trackingTime);
                                    UpdateDataToDB(trackingTime);
                                }
                            }
                        }
                    }
                    //update oldTrackingIDList
                    oldTrackingIdList.Clear();
                    foreach (var trackID in currentTrackingIDList)
                    {
                       oldTrackingIdList.Add(trackID);
                    }
                    this.textBox1.Text = BodyCount.ToString();

                }

            }
        }
示例#4
0
        private void SaveImage(ColorImagePoint position,TrackingTime trackingTime,FrameworkElement control)
        {
            _fn = GetFilename(trackingTime);
            try
            {
               RenderTargetBitmap renderTargetBitmap=new RenderTargetBitmap(640,480,96,96,PixelFormats.Pbgra32);
                renderTargetBitmap.Render(control);
                renderTargetBitmap.Freeze();
                int x = position.X - croppedImageWidth/2;
                if (x<0)
                {
                    x = 0;
                }
                int width = croppedImageWidth;
                if (x+width>renderTargetBitmap.Width)
                {
                    width = (int)renderTargetBitmap.Width - x;
                }
                CroppedBitmap croppedBitmap = new CroppedBitmap(renderTargetBitmap, new Int32Rect(x,0,width,(int)renderTargetBitmap.Height));
                string ext = System.IO.Path.GetExtension(_fn).ToLower();
                BitmapEncoder encoder = new PngBitmapEncoder();
                if (encoder == null) return;
                encoder.Frames.Add(BitmapFrame.Create(croppedBitmap));

                using (Stream stm = File.Create(_fn))
                {
                    encoder.Save(stm);
                }

               //backgroundWorker.RunWorkerAsync(_fn);
            }
            catch (Exception x)
            {
                MessageBox.Show("Sorry, I had trouble saving that photo.\n\nError: " + x.Message);
                //IsAutoEnabled = false;
                // timer.Stop();
            }
        }
示例#5
0
        private string GetFilename(TrackingTime trackingTime)
        {
            int num = 0;
            Settings s = Settings.Default;
            string detectfaceid = GetDetectFaceInfoID(trackingTime.StartTime);

            string fn = System.IO.Path.Combine(s.SaveLocation,
                                             detectfaceid+"_"+num.ToString()+
                                               ".png");
            while (File.Exists(fn))
            {
                num++;
                fn = System.IO.Path.Combine(s.SaveLocation,
                                             detectfaceid+ "_" + num.ToString() +
                                               ".png");
            }
            return fn;
        }