コード例 #1
0
        private void SaveFragButton_Click(object sender, RoutedEventArgs e)
        {
            if (HendlerHolder.IsKinectPlayerWindow(this))
            {
                return;
            }
            if (SKLRecording == null)
            {
                MessageBox.Show(this, "No recording was loaded.", "Error saving recording", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (SKLRecording.Count == 0)
            {
                MessageBox.Show(this, "No recording was loaded.", "Error saving recording", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            int start = 0;
            int stop  = 0;

            try
            {
                start = int.Parse(StartTextBox.Text);
                stop  = int.Parse(StopTextBox.Text);
            }
            catch
            {
                MessageBox.Show(this, "Error in parsing range.", "Error saving recording", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (start < 0 || start >= SKLRecording.Count ||
                stop < 0 || stop >= SKLRecording.Count ||
                start > stop)
            {
                MessageBox.Show(this, "Recording ranges out of range.", "Error saving recording", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            String dirName          = System.AppDomain.CurrentDomain.BaseDirectory;
            String fileNameSkeleton = "SkeletonRecord";
            int    imageIndex       = 0;

            while (File.Exists(dirName + "/" + fileNameSkeleton + imageIndex + ".skl"))
            {
                imageIndex++;
            }
            StreamWriter sw           = new StreamWriter(dirName + "/" + fileNameSkeleton + imageIndex + ".skl");
            long         currentFrame = 0;

            for (int a = start; a <= stop; a++)
            {
                TSkeleton[] ts = (TSkeleton[])SKLRecording[a];
                for (int b = 0; b < ts.Length; b++)
                {
                    TSkeletonHelper.SaveTSkeletonToFile(ts[b], sw, currentFrame);
                }
                currentFrame++;
            }
            sw.Close();
            MessageBox.Show(this, "File saved successfully under path:\r\n" + dirName + "/" + fileNameSkeleton + imageIndex + ".skl", "Saving", MessageBoxButton.OK, MessageBoxImage.Information);
        }
コード例 #2
0
 private void RecordButtn_Click(object sender, RoutedEventArgs e)
 {
     if (HendlerHolder.IsKinectPlayerWindow(this))
     {
         BeginCapture();
     }
 }
コード例 #3
0
        private void DrawImage(TSkeleton[] tSkeletons)
        {
            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, HendlerHolder.DisplayWidth, HendlerHolder.DisplayHeight));
                if (tSkeletons == null)
                {
                    return;
                }
                int penIndex = 0;
                //foreach (Body body in this.bodies)
                for (int a = 0; a < tSkeletons.Length; a++)
                {
                    TSkeleton tSkeleton = tSkeletons[a];
                    Pen       drawPen   = HendlerHolder.BodyColors[penIndex++];

                    if (tSkeleton.IsTracked)
                    {
                        this.DrawClippedEdges(tSkeleton, dc);

                        //IReadOnlyDictionary<JointType, Joint> joints = body.Joints;

                        // convert the joint points to depth (display) space
                        //Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>();

                        //foreach (JointType jointType in joints.Keys)
                        Point[] updatedPositions = new Point[tSkeleton.Position.Length];
                        for (int b = 0; b < tSkeleton.Position.Length; b++)
                        {
                            // sometimes the depth(Z) of an inferred joint may show as negative
                            // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
                            updatedPositions[b] = new Point();
                            CameraSpacePoint updatedCSP = new CameraSpacePoint();
                            updatedCSP.X = tSkeleton.Position[b].X;
                            updatedCSP.Y = tSkeleton.Position[b].Y;
                            updatedCSP.Z = tSkeleton.Position[b].Z;
                            if (updatedCSP.Z < 0)
                            {
                                updatedCSP.Z = HendlerHolder.InferredZPositionClamp;
                            }

                            DepthSpacePoint depthSpacePoint = HendlerHolder.MapSkeletonPointToDepthPointOffline(updatedCSP);
                            //DepthSpacePoint depthSpacePoint = HendlerHolder.coordinateMapper.MapCameraPointToDepthSpace(updatedCSP);
                            updatedPositions[b] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                            //jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                        }

                        this.DrawBody(tSkeleton, updatedPositions, dc, drawPen);

                        this.DrawHand(tSkeleton.HandLeftState, updatedPositions[(int)JointType.HandLeft], dc);
                        this.DrawHand(tSkeleton.HandRightState, updatedPositions[(int)JointType.HandRight], dc);
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, HendlerHolder.DisplayWidth, HendlerHolder.DisplayHeight));
            }
        }
コード例 #4
0
        private void Show3D_Click(object sender, RoutedEventArgs e)
        {
            if (SKLRecording == null)
            {
                return;
            }
            if (SKLRecording.Count < 1)
            {
                return;
            }
            //PlayerWindow3D pw3D = new PlayerWindow3D(TSkeletonHelper.CloneRecording(SKLRecording));
            PlayerWindow3D pw3D = HendlerHolder.OpenNewPlayerWindow3D(TSkeletonHelper.CloneRecording(SKLRecording));

            pw3D.Title = this.Title;
            //pw3D.Show();
        }
コード例 #5
0
        public void PlayRecording()
        {
            if (SKLRecording == null)
            {
                return;
            }
            if (SKLRecording.Count == 0)
            {
                return;
            }
            RecognitionCounter recognitionCounter = HendlerHolder.OpenRecognitionCounter();

            IsPlaying = true;
            ChangeContentWhileRecordingOrPlaying(true);
            Thread ReaderThread = new Thread(PlayerThread);

            ReaderThread.IsBackground = true;
            //ReadFile(fileToPlay);
            //line = 0;
            ReaderThread.Start();
        }
コード例 #6
0
 public void StopCapture()
 {
     recording = false;
     if (sKLFileStream == null)
     {
         return;
     }
     CaptureStopwatch.Stop();
     if (sKLFileStream != null)
     {
         sKLFileStream.Close();
     }
     sKLFileStream = null;
     if (SKLRecording != null)
     {
         SKLRecording.Clear();
     }
     HendlerHolder.OpenNewPlayerWindow(true, SKLFileName);
     SKLFileName = null;
     ChangeContentWhileRecordingOrPlaying(false);
     SKLRecording = TSkeletonHelper.ReadRecordingFromFile(SKLFileName);
     LoadSKLRecording(SKLFileName);
     ChangeContentWhileRecordingOrPlaying(false);
     if (SKLRecording != null)
     {
         ProgressSlider.Maximum = SKLRecording.Count - 1;
         ProgressSlider.Value   = ProgressSlider.Maximum;
         ProgressSlider.Value   = 0;
         if (SKLRecording.Count > 0)
         {
             DrawImage((TSkeleton[])SKLRecording[0]);
         }
     }
     else
     {
         ProgressSlider.Maximum = 0;
         ProgressSlider.Value   = 0;
         DrawImage(null);
     }
 }
コード例 #7
0
        public void LoadSKLRecording(String SKLFile)
        {
            ArrayList SKLRecordingHelp = null;

            try
            {
                SKLRecordingHelp = TSkeletonHelper.ReadRecordingFromFile(SKLFile);
            }
            catch (Exception e)
            {
                String msg = "SKL file " + SKLFile + " loading error: " + e.Message;
                HendlerHolder.DisplayMessage(this, msg);
                return;
            }
            if (SKLRecordingHelp == null)
            {
                String msg = "SKL file " + SKLFile + " seems to be empty.";
                HendlerHolder.DisplayMessage(this, msg);
                return;
            }
            sKLFileName  = SKLFile;
            SKLRecording = SKLRecordingHelp;
            if (SKLRecording != null)
            {
                ProgressSlider.Maximum = SKLRecording.Count - 1;
                ProgressSlider.Value   = ProgressSlider.Maximum;
                ProgressSlider.Value   = 0;
                if (SKLRecording.Count > 0)
                {
                    DrawImage((TSkeleton[])SKLRecording[0]);
                }
            }
            else
            {
                ProgressSlider.Maximum = 0;
                ProgressSlider.Value   = 0;
                DrawImage(null);
            }
        }
コード例 #8
0
        private void SkeletonOutput_Drop(object sender, DragEventArgs e)
        {
            if (IsPlaying == true || recording == true || HendlerHolder.FileDroppingEnabled == false)
            {
                string msg = "File dropping has been disabled either by internal processing (like recording or playing) or by the user in main menu.";
                HendlerHolder.DisplayMessage(this, msg);
                return;
            }
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                // Note that you can have more than one file.
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                for (int a = 0; a < files.Length; a++)
                {
                    if (System.IO.Path.GetExtension(files[a]).ToLower() == ".skl")
                    {
                        if (HendlerHolder.IsKinectPlayerWindow(this))
                        {
                            HendlerHolder.OpenNewPlayerWindow(true, files[a]);
                        }
                        else
                        {
                            LoadSKLRecording(files[0]);
                            Title = files[0];
                        }
                    }
                }
                // Assuming you have one file that you care about, pass it off to whatever
                // handling code you have defined.

                /*Dispatcher.Invoke(
                 *  new Action(
                 *  () =>
                 *  {
                 *      this.parentMainWindow.LoadSkeletonFile(files[0]);
                 *  }));*/
            }
        }
コード例 #9
0
        private void PlayerThread()
        {
            int                line  = 0;
            GDLInterpreter     inter = null;
            RecognitionCounter recognitionCounter = HendlerHolder.OpenRecognitionCounter();

            Dispatcher.Invoke(
                new Action(
                    () =>
            {
                line = (int)ProgressSlider.Value;
                if (HendlerHolder.MainWindow.inter != null)
                {
                    inter = new GDLInterpreter(HendlerHolder.MainWindow.inter.FeatureTable, HendlerHolder.MainWindow.inter.RuleTable);
                }
            }));
            TSkeleton[] TSkeletons = null;
            while (line < SKLRecording.Count && IsPlaying)
            {
                TSkeletons = (TSkeleton[])SKLRecording[line];

                if (inter != null)
                {
                    double    seconds   = (double)TSkeletons[0].TimePeriod / 1000.0;
                    Point3D[] bodyParts = HendlerHolder.GenerateBodyPartArray(TSkeletons[0], 0);
                    //String[] con = inter.ReturnConclusions(fT, 0, seconds);
                    //String[] con = inter.ReturnConclusions(bodyParts, 0, seconds);
                    String[] con                        = inter.ReturnConclusions(bodyParts, seconds);
                    String   allConclusions             = "";
                    String   conclusionsWithExclamation = "";
                    for (int a = 0; a < con.Length; a++)
                    {
                        allConclusions += con[a] + "\r\n";
                        if (con[a].Contains("!"))
                        {
                            conclusionsWithExclamation += con[a] + "\r\n";
                        }
                        Dispatcher.Invoke(
                            new Action(
                                () =>
                        {
                            recognitionCounter.AddToDictionary(con[a]);
                        }));
                    }
                    UpdateGDLOutput(allConclusions, conclusionsWithExclamation);
                }


                Dispatcher.Invoke(new Action(
                                      () =>
                {
                    ProgressSlider.Value += 1;
                    DrawImage(TSkeletons);
                }));
                Thread.Sleep((int)TSkeletons[0].TimePeriod);
                line++;
            }
            Dispatcher.Invoke(new Action(
                                  () =>
            {
                StopPlaying();
            }));
        }