Пример #1
0
        private void recordFakeSkeleton_Click(object sender, RoutedEventArgs e)
        {
            Random         rand            = new Random();
            SaveFileDialog openFileDialog1 = new SaveFileDialog();

            openFileDialog1.InitialDirectory = "C:\\";
            openFileDialog1.FileName         = "Kosciec1.kosciec";
            if (openFileDialog1.ShowDialog() != 0)
            {
                //Get the path of specified file
                if (openFileDialog1.FileName != "")
                {
                    if (File.Exists(openFileDialog1.FileName))
                    {
                        File.Delete(openFileDialog1.FileName);
                    }
                    recordingPath = openFileDialog1.FileName;
                }
            }
            for (int i = 0; i < 500; ++i)
            {
                SkeletonFrame skeletonToRecord = new SkeletonFrame();
                skeletonToRecord.addPerson(0, new Dictionary <int, CustomJoint>());

                skeletonToRecord.addJointToPerson(0, 0, 150, 150, 2);
                skeletonToRecord.addJointToPerson(0, 1, 150, 90, 1);
                skeletonToRecord.addJointToPerson(0, 2, 135, 30, 1);
                skeletonToRecord.addJointToPerson(0, 3, 125, 3, 1);
                skeletonToRecord.addJointToPerson(0, 4, 180, 60, 2);
                skeletonToRecord.addJointToPerson(0, 5, 195, 105, 2);
                skeletonToRecord.addJointToPerson(0, 6, 210, 150, 2);
                skeletonToRecord.addJointToPerson(0, 7, 215, 170, 2);
                skeletonToRecord.addJointToPerson(0, 8, 105, 60, 2);
                skeletonToRecord.addJointToPerson(0, 9, 90, 110, 2);
                skeletonToRecord.addJointToPerson(0, 10, 85, 175, 1);
                skeletonToRecord.addJointToPerson(0, 11, 80, 195, 2);
                skeletonToRecord.addJointToPerson(0, 12, 180, 165, 2);
                skeletonToRecord.addJointToPerson(0, 13, 170, 240, 2);
                skeletonToRecord.addJointToPerson(0, 14, 165, 315, 2);
                skeletonToRecord.addJointToPerson(0, 15, 180, 320, 2);
                skeletonToRecord.addJointToPerson(0, 16, 110, 165, 2);
                skeletonToRecord.addJointToPerson(0, 17, 110, 240, 2);
                skeletonToRecord.addJointToPerson(0, 18, 120, 315, 2);
                skeletonToRecord.addJointToPerson(0, 19, 127, 325, 2);
                skeletonToRecord.addJointToPerson(0, 20, 140, 45, 2);
                skeletonToRecord.addJointToPerson(0, 21, 225, 180, 2);
                skeletonToRecord.addJointToPerson(0, 22, 210, 180, 2);
                skeletonToRecord.addJointToPerson(0, 23, 90, 200, 2);
                skeletonToRecord.addJointToPerson(0, 24, 75, 200, 2);

                if (i > 250)
                {
                    skeletonToRecord.addPerson(1, new Dictionary <int, CustomJoint>());

                    skeletonToRecord.addJointToPerson(1, 0, 160, 150, 2);
                    skeletonToRecord.addJointToPerson(1, 1, 160, 90, 2);
                    skeletonToRecord.addJointToPerson(1, 2, 145, 30, 2);
                    skeletonToRecord.addJointToPerson(1, 3, 135, 3, 2);
                    skeletonToRecord.addJointToPerson(1, 4, 190, 60, 2);
                    skeletonToRecord.addJointToPerson(1, 5, 205, 105, 2);
                    skeletonToRecord.addJointToPerson(1, 6, 220, 150, 2);
                    skeletonToRecord.addJointToPerson(1, 7, 225, 170, 2);
                    skeletonToRecord.addJointToPerson(1, 8, 115, 60, 2);
                    skeletonToRecord.addJointToPerson(1, 9, 100, 110, 2);
                    skeletonToRecord.addJointToPerson(1, 10, 95, 175, 2);
                    skeletonToRecord.addJointToPerson(1, 11, 90, 195, 2);
                    skeletonToRecord.addJointToPerson(1, 12, 190, 165, 2);
                    skeletonToRecord.addJointToPerson(1, 13, 180, 240, 2);
                    skeletonToRecord.addJointToPerson(1, 14, 175, 315, 2);
                    skeletonToRecord.addJointToPerson(1, 15, 190, 320, 2);
                    skeletonToRecord.addJointToPerson(1, 16, 120, 165, 2);
                    skeletonToRecord.addJointToPerson(1, 17, 120, 240, 2);
                    skeletonToRecord.addJointToPerson(1, 18, 130, 315, 2);
                    skeletonToRecord.addJointToPerson(1, 19, 137, 325, 2);
                    skeletonToRecord.addJointToPerson(1, 20, 150, 45, 2);
                    skeletonToRecord.addJointToPerson(1, 21, 235, 180, 2);
                    skeletonToRecord.addJointToPerson(1, 22, 220, 180, 2);
                    skeletonToRecord.addJointToPerson(1, 23, 100, 200, 2);
                    skeletonToRecord.addJointToPerson(1, 24, 85, 200, 2);
                }

                double temp1;
                double temp2;

                double temp3;
                double temp4;
                for (int bone = 0; bone < 25; ++bone)
                {
                    if (bone == 5 || bone == 6 || bone == 9 || bone == 10)
                    {
                        temp1 = rand.Next(30) - 15;
                        temp2 = rand.Next(30) - 15;
                        temp3 = rand.Next(30) - 15;
                        temp4 = rand.Next(30) - 15;
                    }
                    else
                    {
                        temp1 = rand.Next(10) - 5;
                        temp2 = rand.Next(10) - 5;
                        temp3 = rand.Next(30) - 15;
                        temp4 = rand.Next(30) - 15;
                    }
                    skeletonToRecord.getJoint(0, bone).setX(skeletonToRecord.getJoint(0, bone).getX() + temp1);
                    skeletonToRecord.getJoint(0, bone).setY(skeletonToRecord.getJoint(0, bone).getY() + temp2);

                    if (i > 250)
                    {
                        skeletonToRecord.getJoint(1, bone).setX(skeletonToRecord.getJoint(1, bone).getX() + temp3);
                        skeletonToRecord.getJoint(1, bone).setY(skeletonToRecord.getJoint(1, bone).getY() + temp4);
                    }
                }

                RecordManager.WriteToBinaryFile <SkeletonFrame>(recordingPath, skeletonToRecord, true);
            }
        }
Пример #2
0
        void timer_Tick4(object sender, EventArgs e)
        {
            if (!isMovieAvi2)
            {
                if (currentFrameKosciec2 < allFrames2.Count)
                {
                    SkeletonFrame frame = allFrames2[currentFrameKosciec2];
                    using (DrawingContext dc = this.drawingGroup2.Open())
                    {
                        // czarne tło
                        dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, kosciecVideoKosciec2.Width, kosciecVideoKosciec2.Height));

                        int bodyIndex = 0;

                        foreach (int body in frame.getBodyIds())
                        {
                            Pen drawPen = this.bodyColors[bodyIndex];
                            foreach (var bone in this.bones)
                            {
                                drawPen = this.bodyColors[bodyIndex];
                                if ((frame.getJoint(body, (int)bone.Item1).getTrackingState() != (int)CustomJoint.TrackingState.Tracked) || (frame.getJoint(body, (int)bone.Item2).getTrackingState() != (int)CustomJoint.TrackingState.Tracked))
                                {
                                    drawPen = this.inferredBonePen;
                                }

                                dc.DrawLine(drawPen, new Point(frame.getJoint(body, (int)bone.Item1).getX(), frame.getJoint(body, (int)bone.Item1).getY()),
                                            new Point(frame.getJoint(body, (int)bone.Item2).getX(), frame.getJoint(body, (int)bone.Item2).getY()));
                                kosciecVideoKosciec2.Source = skeletonMovie2;
                            }
                            for (int CustomJointType = 0; CustomJointType < 25; ++CustomJointType)
                            {
                                Brush drawBrush = null;

                                int trackingState = allFrames2[currentFrameKosciec2].getJoint(body, CustomJointType).getTrackingState();

                                if (trackingState == (int)CustomJoint.TrackingState.Tracked)
                                {
                                    drawBrush = this.trackedJointBrush;
                                }
                                else if (trackingState == (int)CustomJoint.TrackingState.Inferred)
                                {
                                    drawBrush = this.inferredJointBrush;
                                }

                                if (drawBrush != null)
                                {
                                    dc.DrawEllipse(drawBrush, null, new Point(frame.getJoint(body, CustomJointType).getX(), frame.getJoint(body, CustomJointType).getY()),
                                                   JointThickness, JointThickness);
                                }
                            }
                            ++bodyIndex;
                        }

                        this.drawingGroup2.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, kosciecVideoKosciec2.Width, kosciecVideoKosciec2.Height));

                        framesKosciec2.Content = (currentFrameKosciec2 + 1).ToString() + " / " + allFrames2.Count.ToString();
                        sliderKosciec2.Value   = currentFrameKosciec2;

                        labelKosciec2.Content = String.Format("{0} / {1} s", string.Format("{0:F1}", (double)currentFrameKosciec2 / allFrames2.Count * (double)allFrames2.Count / framesPerSecond2),
                                                              string.Format("{0:F1}", (double)allFrames2.Count / framesPerSecond2));
                        if (playKosciecMovie2)
                        {
                            currentFrameKosciec2++;
                        }
                    }
                }
                if (currentFrameKosciec2 == allFrames2.Count)
                {
                    playKosciecMovie2 = false;
                }
            }
        }