コード例 #1
0
        public PaintLine Paint(SensorBody body, Brush brush)
        {
            PaintLine result = null;

            SensorJoint hand = body.HandRight;

            if (hand.TrackingState != SensorTrackingState.NotTracked)
            {
                var handPoint = new FloatPoint(hand.X, hand.Y);
                if (!handPoint.IsInfinity())
                {
                    var newPoint = new Point {
                        X = handPoint.X, Y = handPoint.Y
                    };
                    if (this.lastPoint != null)
                    {
                        result = new PaintLine
                        {
                            X1    = this.lastPoint.Value.X,
                            Y1    = this.lastPoint.Value.Y,
                            X2    = newPoint.X,
                            Y2    = newPoint.Y,
                            Brush = brush,
                        };
                    }

                    this.lastPoint = newPoint;
                }
            }

            return(result);
        }
コード例 #2
0
        public void Paint(SensorBody body, Brush brush, Canvas canvas)
        {
            var hand = body.HandRight;

            if (hand.TrackingState == SensorTrackingState.Tracked)
            {
                var handPoint = new FloatPoint(hand.X, hand.Y);
                if (!handPoint.IsInfinity())
                {
                    var newPoint = new Point {
                        X = handPoint.X, Y = handPoint.Y
                    };
                    if (this.lastPoint != null)
                    {
                        canvas.Children.Add(new Line
                        {
                            X1                 = this.lastPoint.Value.X,
                            Y1                 = this.lastPoint.Value.Y,
                            X2                 = newPoint.X,
                            Y2                 = newPoint.Y,
                            Stroke             = brush,
                            StrokeThickness    = 20,
                            StrokeDashCap      = PenLineCap.Round,
                            StrokeStartLineCap = PenLineCap.Round,
                            StrokeEndLineCap   = PenLineCap.Round,
                        });
                    }

                    this.lastPoint = newPoint;
                }
            }
        }
コード例 #3
0
        public TestModePaintingSession(IPaintAlgorithm paintAlgorithm)
        {
            this.paintAlgorithm = paintAlgorithm;

            this.backgroundWorker.DoWork += (s, e) =>
            {
                var arguments = (IList <object>)e.Argument;
                var backgroundWithPainting = (RenderTargetBitmap)arguments[0];
                var background             = (RenderTargetBitmap)arguments[1];
                var parentDirectoryPath    = (string)arguments[2];

                var directoryPath = Path.Combine(parentDirectoryPath, DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss"));
                Directory.CreateDirectory(directoryPath);

                // Save the background with the painting
                string backgroundWithPaintingFilePath = Path.Combine(directoryPath, "painting.png");
                DefaultPaintingSession.SaveRenderTargetBitmapAsPng(backgroundWithPainting, backgroundWithPaintingFilePath);

                // Save just the background
                string backgroundFilePath = Path.Combine(directoryPath, "background.png");
                DefaultPaintingSession.SaveRenderTargetBitmapAsPng(background, backgroundFilePath);

                // Save the raw body frame data points
                string csvSerializedSensorDataFilePath = Path.Combine(directoryPath, "sensor_data.csv");
                using (var file = new StreamWriter(csvSerializedSensorDataFilePath))
                {
                    file.WriteLine(SensorBody.GetCsvHeader());
                    foreach (var sensorBodyFrame in this.sensorRecorder.SensorData.BodyFrames)
                    {
                        string[] csvSerializedBodies = sensorBodyFrame.Bodies.Select(b => b.SerializeToCsv()).ToArray();
                        file.WriteLine(string.Join(",", csvSerializedBodies));
                    }
                }

                string jsonSerializedSensorData         = JsonConvert.SerializeObject(this.sensorRecorder.SensorData);
                string jsonSerializedSensorDataFilePath = Path.Combine(directoryPath, "sensor_data.json");
                File.WriteAllText(jsonSerializedSensorDataFilePath, jsonSerializedSensorData);
            };
        }
コード例 #4
0
        public VirtualRepainterViewModel()
        {
            this.recordingFileOpenerBackgroundWorker.DoWork += (s, e) =>
            {
                var recordingFilePath = (string)e.Argument;

                var sensorRecordingData = File.ReadAllText(recordingFilePath);
                this.sensorRecordingPlayer = new SensorRecordingPlayer(sensorRecordingData);
                this.sensorRecordingPlayer.SensorBodyFrameCaptured += (s1, e1) =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SensorBody primaryBody = e1.Bodies[0];
                        this.PaintLines.Add(this.paintAlgorithm.Paint(primaryBody, this.paintBrush));
                    });
                };
                this.sensorRecordingPlayer.Start();
            };

            this.backgroundImageFileOpenerBackgroundWorker.DoWork += (s, e) =>
            {
                var backgroundImageFilePath = (string)e.Argument;
                var backgroundImage         = new BitmapImage();
                backgroundImage.BeginInit();
                backgroundImage.UriSource = new Uri(backgroundImageFilePath);
                backgroundImage.EndInit();
                backgroundImage.Freeze();
                e.Result = backgroundImage;
            };
            this.backgroundImageFileOpenerBackgroundWorker.RunWorkerCompleted += (s, e) =>
            {
                this.CameraImageSource = (BitmapImage)e.Result;
            };

            this.OpenFindRecordingFileDialogCommand       = new RelayCommand(o => OpenRecordingFileDialog());
            this.OpenFindBackgroundImageFileDialogCommand = new RelayCommand(o => OpenFindBackgroundImageFileDialog());
        }
コード例 #5
0
    private void Update()
    {
        // Check if there is a sensor available
        if (bodySensor == null)
        {
            return;
        }

        // Acquire the sensor, cast it to SensorBody
        bodyReader = bodySensor.GetComponent <SensorBody>();
        if (bodyReader == null)
        {
            return;
        }

        // Find the information about found bodies
        Kinect.Body[] data = bodyReader.GetBodies();
        if (data == null)
        {
            return;
        }

        // Assign a tracking ID to every found body
        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }
            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        // Remove bodies that are not being tracked anymore
        List <ulong> knownIds = new List <ulong>(bodyDict.Keys);

        foreach (ulong trackingId in knownIds)
        {
            if (!trackedIds.Contains(trackingId))
            {
                Destroy(bodyDict[trackingId]);
                bodyDict.Remove(trackingId);
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }
            if (body.IsTracked)
            {
                // If no virtual object associated to this body, create one
                if (!bodyDict.ContainsKey(body.TrackingId))
                {
                    bodyDict[body.TrackingId] = CreateBody(body.TrackingId);
                }
                // Perform operations related to body tracking
                RefreshBodyObject(body, bodyDict[body.TrackingId]);
                break;  // <----- Track only one body
            }
        }
    }
コード例 #6
0
 public void Paint(SensorBody body, Brush brush, Canvas canvas, SensorBodyFrame bodyFrame)
 {
     this.paintAlgorithm.Paint(body, brush, canvas);
     this.sensorRecorder.LogBodyFrame(bodyFrame);
 }
コード例 #7
0
 public void Paint(SensorBody body, System.Windows.Media.Brush brush, Canvas canvas, SensorBodyFrame bodyFrame)
 {
     this.paintingAlgorithm.Paint(body, brush, canvas);
 }
コード例 #8
0
ファイル: Sensor.cs プロジェクト: mauriciosousa/creepytracker
    internal void updateBodies()
    {
        BodiesMessage bodiesMessage = lastBodiesMessage;

        if (bodiesMessage == null)
            return;

        foreach (KeyValuePair<string, SensorBody> sb in bodies) {
            sb.Value.updated = false;
        }

        // refresh bodies position
        foreach (Skeleton sk in bodiesMessage.Bodies) {
            SensorBody b;

            if (int.Parse (sk.bodyProperties [BodyPropertiesTypes.Confidence]) < TrackerProperties.Instance.confidenceTreshold) {
                if (bodies.ContainsKey (sk.ID)) {
                    b = bodies [sk.ID];
                    b.updated = true;
                    b.lastUpdated = DateTime.Now;
                }
                continue;
            }

            if (bodies.ContainsKey (sk.ID)) {   //existing bodies
                b = bodies [sk.ID];
            } else {   // new bodies
                b = new SensorBody (sk.ID, SensorGameObject.transform);
                b.gameObject.GetComponent<Renderer> ().material = Material;
                bodies [sk.ID] = b;
                b.sensorID = SensorID;
            }

            b.LocalPosition = CommonUtils.pointKinectToUnity (sk.jointsPositions [Windows.Kinect.JointType.SpineBase]);
            b.updated = true;
            b.lastUpdated = DateTime.Now;
            b.skeleton = sk;
        }

        // remove bodies no longer present
        List<string> keysToRemove = new List<string> ();
        foreach (KeyValuePair<string, SensorBody> sb in bodies) {
            if (!sb.Value.updated) {
                GameObject.Destroy (sb.Value.gameObject);
                keysToRemove.Add (sb.Key);
            }
        }
        foreach (string key in keysToRemove) {
            bodies.Remove (key);
        }
    }
コード例 #9
0
        private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            using (BodyFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    frame.GetAndRefreshBodyData(this.bodies);
                    if (Settings.IsDebugViewEnabled)
                    {
                        RefreshPersonDetectionStates();
                    }

                    DrawSkeletons();

                    if (this.primaryPerson == null)
                    {
                        // If we are not tracking anyone, make the first tracked person in the
                        // frame the primary body.
                        for (int i = 0; i < this.bodies.Count; i++)
                        {
                            var body = this.bodies[i];
                            if (body != null && body.IsTracked && PersonDetector.IsPersonPresent(body, this.bodyPresenceArea))
                            {
                                this.primaryPerson = new Person(i, body.TrackingId);
                                this.StateMachine.Fire(Trigger.PersonEnters);
                                break;
                            }
                        }
                    }
                    else
                    {
                        // If we are tracking someone, check if they are still present and still in
                        // the frame.
                        var primaryBody = this.bodies[this.primaryPerson.BodyIndex];
                        if (primaryBody != null && primaryBody.TrackingId == this.primaryPerson.TrackingId && primaryBody.IsTracked)
                        {
                            var isPrimaryPersonPresent = PersonDetector.IsPersonPresent(primaryBody, this.bodyPresenceArea, this.primaryPerson.ExpectedMaxDistance);
                            if (isPrimaryPersonPresent)
                            {
                                // Primary person is in the frame and is a valid distance from the camera.
                                if (this.StateMachine.IsInState(State.ConfirmingPresence))
                                {
                                    // Calibrate the primary person's distance
                                    this.personCalibrator.AddDistanceFromCamera(primaryBody.DistanceFromSensor());
                                }
                                else if (this.StateMachine.IsInState(State.Painting))
                                {
                                    var primaryBodyAsSensorBody = new SensorBody(primaryBody, this.sensor);
                                    var frameAsSensorFrame      = new SensorBodyFrame(frame, this.sensor);
                                    this.paintingSession.Paint(primaryBodyAsSensorBody, this.currentBrush, this.canvas, frameAsSensorFrame);
                                }
                            }
                            else
                            {
                                this.StateMachine.Fire(Trigger.PersonLeaves);
                            }
                        }
                        else
                        {
                            this.StateMachine.Fire(Trigger.PersonLeaves);
                        }
                    }
                }
            }
        }