Home Forums Software Development How to convert EyeX X & Y into Canvas.X, Canvas.Y positions?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4209
    TRO
    Participant

    I am building a very simple WPF app to show the position on a Canvas of both eyes.

    I have 2 ellipse, one for each eye on a Canvas.

    Obviously the EyeX coordinates don’t map directly into Canvas.X and Canvas.Y positions so how would I achieve this?

    thanks

    #4210
    TRO
    Participant

    My code so far:

        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                this.Loaded += MainWindow_Loaded;
                this.Closing += (s, e) => { this.EyePositionDataStream.Dispose(); };
            }
    
            private EyeXFramework.EyePositionDataStream EyePositionDataStream { get; set; }
    
            private void MainWindow_Loaded(object sender, RoutedEventArgs routedEventArgs)
            {
                this.EyePositionDataStream = (Application.Current as App).WpfEyeXHost.CreateEyePositionDataStream();
    
                this.EyePositionDataStream.Next += (s, e) =>
                {
                    txtLeftEye.Text = string.Format("LEFT: X: {0:0.00}, Y: {1:0.00}", e.LeftEye.X, e.LeftEye.Y);
                    txtRightEye.Text = string.Format("RIGHT: X: {0:0.00}, Y: {1:0.00}", e.RightEye.X, e.RightEye.Y);
    
                    leftEye.SetValue(Canvas.LeftProperty, e.LeftEye.X);
                    leftEye.SetValue(Canvas.TopProperty, e.LeftEye.Y);
    
                    rightEye.SetValue(Canvas.LeftProperty, e.RightEye.X);
                    rightEye.SetValue(Canvas.TopProperty, e.RightEye.Y);
                };
            }
        }
    #4524

    Hi,

    I would use the normalized eye coordinates if you want to visualize the eye positions. The positions are in the 0-1 range, so you will need to scale they eyes yourself in the canvas.

                stream.Next += (s, e) =>
                {
                    Debug.WriteLine("EyePos = {0} {1} {2} {3}", 
                    e.LeftEyeNormalized.X,
                    e.LeftEyeNormalized.Y,
                    e.RightEyeNormalized.X,
                    e.RightEyeNormalized.Y);
                };

    Hope it helps,

    Denny

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.