Strange x / y shift in WPF application.

Forum for C#/Windows development

Strange x / y shift in WPF application.

Postby albert » 07 Jul 2015, 14:26

I have strange x and y coordinates shift in the WPF application (please see the screen shot: http://s8.postimg.org/l3etopwl1/Capture.jpg).
Small white ellipse (on the bottom right of the red square) is the gaze pointer that shows outputs from eye tracker while watching red square in the middle.

The snippet below shows the way I’m setting position of the gaze pointer (following code runs in WPF application).
Code: Select all
var x = Screen.PrimaryScreen.Bounds.X;
var y = Screen.PrimaryScreen.Bounds.Y;
         
var screenX = (int)Math.Round(x + gazeData.SmoothedCoordinates.X, 0);
var screenY = (int)Math.Round(y + gazeData.SmoothedCoordinates.Y, 0);

I’m using TheEyeTribeSDK-0.9.56-x86 with TETCSharpClient 0.9.56. I’m calibrating tracker via EyeTribe UI and then run the application. It was tested on several persons with same results, tracker was in proper position calibrated with best rank. Does anyone have an idea what might causing it? Please assume that application’s surrounding doesn’t affect the output position of the gaze pointer.

Thank you for your support!
albert
 
Posts: 2
Joined: 02 Jul 2015, 06:58

Re: Strange x / y shift in WPF application.

Postby lichter » 07 Jul 2015, 16:09

You probably need to convert to/from device-independent pixels (DIP).

Code: Select all
    public partial class MyPage : IGazeListener
    {
        private readonly double _logicalDpi;
        private readonly double _rawDpi;

        public MyPage()
        {
            InitializeComponent();

            // Get pixel density information
            var display = DisplayInformation.GetForCurrentView();
            _logicalDpi = display.LogicalDpi;
            _rawDpi = display.RawDpiX;
            Debug.WriteLine("Logical DPI: " + _logicalDpi);
            Debug.WriteLine("Raw DPI: " + _rawDpi);
        }

        public async void OnGazeUpdate(GazeData gazeData)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, delegate()
            {
                try
                {
                    // Calculate the gaze location in logical (display independent, layout) pixels
                    double logicalX = gazeData.SmoothedCoordinates.X * 96.0 / _logicalDpi;
                    double logicalY = gazeData.SmoothedCoordinates.Y * 96.0 / _logicalDpi;

                    // Draw indicator at (logicalX, logicalY)
                    // ....
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            });
        }
    }
lichter
 
Posts: 2
Joined: 29 Jan 2015, 19:18

Re: Strange x / y shift in WPF application.

Postby chithiravelus » 14 Jul 2015, 21:35

Hi Friend, sorry to disturb you in between your query.

I had downloaded the TET client master. please tell me how to call TET client program into our application for eye click event. thank you

share me the code please if you have done alreadyh
chithiravelus
 
Posts: 4
Joined: 18 Feb 2015, 10:08

Re: Strange x / y shift in WPF application.

Postby albert » 25 Oct 2015, 22:48

Hi again

This fix works great for Win 8/8.1 Store and Win10 Universal apps. However for WPF applications, this below worked for me:

Code: Select all
var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static);

var dpiX = (int)dpiXProperty.GetValue(null, null);
var dpiY = (int)dpiYProperty.GetValue(null, null);
albert
 
Posts: 2
Joined: 02 Jul 2015, 06:58


Return to C#



cron