Exemple #1
0
 private void SendOscData(SensorEmitterReading values)
 {
     if (oscEnabled)
     {
         var sender = new SharpOSC.UDPSender(OSCIP.Text, decimal.ToInt32(OSCIPPort.Value));
         if (magnetchk.Checked)
         {
             if (values.MagnetometerDataValid)
             {
                 var message = new SharpOSC.OscMessage("/magnet/", (float)values.MagnetometerX, (float)values.MagnetometerY, (float)values.MagnetometerZ, (float)values.MagneticHeading);
                 sender.Send(message);
             }
         }
         if (gravitychk.Checked)
         {
             var message = new SharpOSC.OscMessage("/gravity/", (float)values.GravityX, (float)values.GravityY, (float)values.GravityZ);
             sender.Send(message);
         }
         if (quaternionchk.Checked)
         {
             var message = new SharpOSC.OscMessage("/quaternin/", (float)values.QuaternionX, (float)values.QuaternionY, (float)values.QuaternionZ,(float)values.QuaternionW);
             sender.Send(message);
         }
         if (acclerationchk.Checked)
         {
             var message = new SharpOSC.OscMessage("/accleration/", (float)values.LinearAccelerationX, (float)values.LinearAccelerationY, (float)values.LinearAccelerationZ);
             sender.Send(message);
         }
         if (rotationchk.Checked)
         {
             var message = new SharpOSC.OscMessage("/rotation/", (float)values.RotationRateX, (float)values.RotationRateY, (float)values.RotationRateZ, (float)values.RotationRoll, (float)values.RotationYaw, (float)values.RotationPitch);
             sender.Send(message);
         }
     }
 }
        public void TestBundle()
        {
            var listener = new UDPListener(55555);

            var sender1 = new SharpOSC.UDPSender("localhost", 55555);
            var msg1    = new SharpOSC.OscMessage("/test/address1", 23, 42.42f, "hello world", new byte[3] {
                2, 3, 4
            });
            var msg2 = new SharpOSC.OscMessage("/test/address2", 34, 24.24f, "hello again", new byte[5] {
                5, 6, 7, 8, 9
            });
            var dt     = DateTime.Now;
            var bundle = new SharpOSC.OscBundle(Utils.DateTimeToTimetag(dt), msg1, msg2);

            sender1.Send(bundle);
            sender1.Send(bundle);
            sender1.Send(bundle);

            var recv = (OscBundle)listener.Receive();

            recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();


            Assert.AreEqual(dt.Date, recv.Timestamp.Date);
            Assert.AreEqual(dt.Hour, recv.Timestamp.Hour);
            Assert.AreEqual(dt.Minute, recv.Timestamp.Minute);
            Assert.AreEqual(dt.Second, recv.Timestamp.Second);
            //Assert.AreEqual(dt.Millisecond, recv.DateTime.Millisecond); Ventus not accurate enough

            Assert.AreEqual("/test/address1", recv.Messages[0].Address);
            Assert.AreEqual(4, recv.Messages[0].Arguments.Count);
            Assert.AreEqual(23, recv.Messages[0].Arguments[0]);
            Assert.AreEqual(42.42f, recv.Messages[0].Arguments[1]);
            Assert.AreEqual("hello world", recv.Messages[0].Arguments[2]);
            Assert.AreEqual(new byte[3] {
                2, 3, 4
            }, recv.Messages[0].Arguments[3]);

            Assert.AreEqual("/test/address2", recv.Messages[1].Address);
            Assert.AreEqual(4, recv.Messages[1].Arguments.Count);
            Assert.AreEqual(34, recv.Messages[1].Arguments[0]);
            Assert.AreEqual(24.24f, recv.Messages[1].Arguments[1]);
            Assert.AreEqual("hello again", recv.Messages[1].Arguments[2]);
            Assert.AreEqual(new byte[5] {
                5, 6, 7, 8, 9
            }, recv.Messages[1].Arguments[3]);

            listener.Close();
        }
Exemple #3
0
        public void ListenerSingleMSG()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            var msg = new SharpOSC.OscMessage("/test/", 23.42f);

            sender.Send(msg);

            while (true)
            {
                var pack = listener.Receive();
                if (pack == null)
                {
                    Thread.Sleep(1);
                }
                else
                {
                    break;
                }
            }

            listener.Dispose();
        }
        public void TestMessage()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            // Test every message type (except Symbol)
            var msg1 = new SharpOSC.OscMessage(
                "/test/address",

                23,
                42.42f,
                "hello world",
                new byte[3] {
                2, 3, 4
            },
                -123456789123,
                new Timetag(DateTime.Now.Date).Tag,
                new Timetag(DateTime.Now.Date.AddMonths(1)),
                (double)1234567.890,
                new Symbol("wut wut"),
                (char)'x',
                new RGBA(20, 40, 60, 255),
                new Midi(3, 110, 55, 66),
                true,
                false,
                null,
                Double.PositiveInfinity
                );

            OscMessage msgRevc = null;

            sender.Send(msg1);
            msgRevc = (OscMessage)listener.Receive();
            Assert.NotNull(msgRevc);

            Assert.AreEqual("/test/address", msgRevc.Address);
            Assert.AreEqual(16, msgRevc.Arguments.Count);

            Assert.AreEqual(23, msgRevc.Arguments[0]);
            Assert.AreEqual(42.42f, msgRevc.Arguments[1]);
            Assert.AreEqual("hello world", msgRevc.Arguments[2]);
            Assert.AreEqual(new byte[3] {
                2, 3, 4
            }, msgRevc.Arguments[3]);
            Assert.AreEqual(-123456789123, msgRevc.Arguments[4]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date), msgRevc.Arguments[5]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date.AddMonths(1)), msgRevc.Arguments[6]);
            Assert.AreEqual((double)1234567.890, msgRevc.Arguments[7]);
            Assert.AreEqual(new Symbol("wut wut"), msgRevc.Arguments[8]);
            Assert.AreEqual((char)'x', msgRevc.Arguments[9]);
            Assert.AreEqual(new RGBA(20, 40, 60, 255), msgRevc.Arguments[10]);
            Assert.AreEqual(new Midi(3, 110, 55, 66), msgRevc.Arguments[11]);
            Assert.AreEqual(true, msgRevc.Arguments[12]);
            Assert.AreEqual(false, msgRevc.Arguments[13]);
            Assert.AreEqual(null, msgRevc.Arguments[14]);
            Assert.AreEqual(Double.PositiveInfinity, msgRevc.Arguments[15]);

            listener.Close();
        }
Exemple #5
0
        static int Main(string[] args)
        {
            string[] param = new string[] { };
            param = validateInput(args);
            if (param.Length == 4)
            {
                //Console.WriteLine("Send  to {0}:{1}, with path {2}  and action {3}", param[0], param[1], param[2], param[3]);
                var host   = param[0];
                var port   = int.Parse(param[1]);
                var path   = param[2];
                var action = param[3];

                //var message = new SharpOSC.OscMessage("/h2r-graphics/clear", 23, 42.01f, "hello world");
                //var sender = new SharpOSC.UDPSender("127.0.0.1", 8181);


                var message = new SharpOSC.OscMessage(path, action);
                var sender  = new SharpOSC.UDPSender(host, port);
                sender.Send(message);
                Console.WriteLine("Envío to {0}:{1}, with path {2}  and action {3}", param[0], param[1], param[2], param[3]);
                Console.WriteLine("");
                return(0);
            }
            return(1);
        }
Exemple #6
0
        public void TestByteCallback()
        {
            bool cbCalled = false;
            // The cabllback function
            HandleBytePacket cb = delegate(byte[] packet)
            {
                var msg = (OscMessage)OscPacket.GetPacket(packet);
                Assert.AreEqual(2, msg.Arguments.Count);
                Assert.AreEqual(23, msg.Arguments[0]);
                Assert.AreEqual("hello world", msg.Arguments[1]);
                cbCalled = true;
            };

            var l1 = new UDPListener(55555, cb);

            var sender = new SharpOSC.UDPSender("localhost", 55555);
            var msg1   = new SharpOSC.OscMessage("/test/address", 23, "hello world");

            sender.Send(msg1);

            // Wait until callback processes its message
            var start = DateTime.Now;

            while (cbCalled == false && start.AddSeconds(2) > DateTime.Now)
            {
                Thread.Sleep(1);
            }

            Assert.IsTrue(cbCalled);

            l1.Close();
        }
Exemple #7
0
        public void TestCallback()
        {
            bool cbCalled = false;
            // The cabllback function
            HandleOscPacket cb = delegate(OscPacket packet)
            {
                var msg = (OscMessage)packet;
                Assert.AreEqual(2, msg.Arguments.Count);
                Assert.AreEqual(23, msg.Arguments[0]);
                Assert.AreEqual("hello world", msg.Arguments[1]);
                cbCalled = true;
            };

            var l1 = new UDPListener(55555, cb);

            var sender = new SharpOSC.UDPSender("localhost", 55555);
            var msg1 = new SharpOSC.OscMessage("/test/address", 23, "hello world");
            sender.Send(msg1);

            // Wait until callback processes its message
            var start = DateTime.Now;
            while(cbCalled == false && start.AddSeconds(2) > DateTime.Now)
                Thread.Sleep(1);

            Assert.IsTrue(cbCalled);

            l1.Close();
        }
        public void TestBundle()
        {
            var listener = new UDPListener(55555);

            var sender1 = new SharpOSC.UDPSender("localhost", 55555);
            var msg1 = new SharpOSC.OscMessage("/test/address1", 23, 42.42f, "hello world", new byte[3] { 2, 3, 4 });
            var msg2 = new SharpOSC.OscMessage("/test/address2", 34, 24.24f, "hello again", new byte[5] { 5, 6, 7, 8, 9 });
            var dt = DateTime.Now;
            var bundle = new SharpOSC.OscBundle(Utils.DateTimeToTimetag(dt), msg1, msg2);

            sender1.Send(bundle);
            sender1.Send(bundle);
            sender1.Send(bundle);

            var recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();

            Assert.AreEqual(dt.Date, recv.Timestamp.Date);
            Assert.AreEqual(dt.Hour, recv.Timestamp.Hour);
            Assert.AreEqual(dt.Minute, recv.Timestamp.Minute);
            Assert.AreEqual(dt.Second, recv.Timestamp.Second);
            //Assert.AreEqual(dt.Millisecond, recv.DateTime.Millisecond); Ventus not accurate enough

            Assert.AreEqual("/test/address1", recv.Messages[0].Address);
            Assert.AreEqual(4, recv.Messages[0].Arguments.Count);
            Assert.AreEqual(23, recv.Messages[0].Arguments[0]);
            Assert.AreEqual(42.42f, recv.Messages[0].Arguments[1]);
            Assert.AreEqual("hello world", recv.Messages[0].Arguments[2]);
            Assert.AreEqual(new byte[3] { 2, 3, 4 }, recv.Messages[0].Arguments[3]);

            Assert.AreEqual("/test/address2", recv.Messages[1].Address);
            Assert.AreEqual(4, recv.Messages[1].Arguments.Count);
            Assert.AreEqual(34, recv.Messages[1].Arguments[0]);
            Assert.AreEqual(24.24f, recv.Messages[1].Arguments[1]);
            Assert.AreEqual("hello again", recv.Messages[1].Arguments[2]);
            Assert.AreEqual(new byte[5] { 5, 6, 7, 8, 9 }, recv.Messages[1].Arguments[3]);

            listener.Close();
        }
        private void oscIP_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox oscIP = (TextBox)sender;

            System.Net.IPAddress temp;

            if (oscIP.Text.Split('.').Length == 4 && System.Net.IPAddress.TryParse(oscIP.Text, out temp))
            {
                osc = new SharpOSC.UDPSender("127.0.0.1", 10000);

                for (int i = 0; i < 10; i++)
                {
                    SharpOSC.OscMessage msg = new SharpOSC.OscMessage("/test", "test");
                    osc.Send(msg);
                }
            }
        }
        private double[] PrintAngles(Body skeleton)
        {
            // Unit vectors
            Vector3D XVector = new Vector3D(1.0, 0.0, 0.0);
            Vector3D YVector = new Vector3D(0.0, 1.0, 0.0);
            Vector3D ZVector = new Vector3D(0.0, 0.0, -1.0);
            // Major required vectors within the skeleton
            Vector3D RightHand       = new Vector3D(skeleton.Joints[JointType.HandTipRight].Position.X, skeleton.Joints[JointType.HandTipRight].Position.Y, skeleton.Joints[JointType.HandTipRight].Position.Z);
            Vector3D RightHandXZ     = new Vector3D(skeleton.Joints[JointType.HandTipRight].Position.X, 0, skeleton.Joints[JointType.HandTipRight].Position.Z);
            Vector3D LeftHand        = new Vector3D(skeleton.Joints[JointType.HandTipLeft].Position.X, skeleton.Joints[JointType.HandTipLeft].Position.Y, skeleton.Joints[JointType.HandTipLeft].Position.Z);
            Vector3D LeftHandXZ      = new Vector3D(skeleton.Joints[JointType.HandTipLeft].Position.X, 0, skeleton.Joints[JointType.HandTipLeft].Position.Z);
            Vector3D LeftShoulder    = new Vector3D(skeleton.Joints[JointType.ShoulderLeft].Position.X, skeleton.Joints[JointType.ShoulderLeft].Position.Y, skeleton.Joints[JointType.ShoulderLeft].Position.Z);
            Vector3D LeftShoulderXZ  = new Vector3D(skeleton.Joints[JointType.ShoulderLeft].Position.X, 0, skeleton.Joints[JointType.ShoulderLeft].Position.Z);
            Vector3D RightShoulder   = new Vector3D(skeleton.Joints[JointType.ShoulderRight].Position.X, skeleton.Joints[JointType.ShoulderRight].Position.Y, skeleton.Joints[JointType.ShoulderRight].Position.Z);
            Vector3D RightShoulderXZ = new Vector3D(skeleton.Joints[JointType.ShoulderRight].Position.X, 0, skeleton.Joints[JointType.ShoulderRight].Position.Z);
            Vector3D Hip             = new Vector3D((skeleton.Joints[JointType.HipLeft].Position.X + skeleton.Joints[JointType.HipRight].Position.X) / 2, (skeleton.Joints[JointType.HipLeft].Position.Y + skeleton.Joints[JointType.HipRight].Position.Y) / 2, (skeleton.Joints[JointType.HipLeft].Position.Z + skeleton.Joints[JointType.HipRight].Position.Z) / 2);
            Vector3D HipXZ           = new Vector3D((skeleton.Joints[JointType.HipLeft].Position.X + skeleton.Joints[JointType.HipRight].Position.X) / 2, 0, (skeleton.Joints[JointType.HipLeft].Position.Z + skeleton.Joints[JointType.HipRight].Position.Z) / 2);

            //joint angles
            Vector3D Left  = LeftHandXZ - HipXZ;
            Vector3D Right = RightHandXZ - HipXZ;

            // Joint angle array to be returned to the calling statement
            double distance_left  = (LeftHandXZ - HipXZ).Length;
            double distance_right = (RightHandXZ - HipXZ).Length;

            double[] parameters = new double[6];
            parameters[0] = Left.X;
            parameters[1] = -Left.Z;
            parameters[2] = Right.X;
            parameters[3] = -Right.Z;
            parameters[4] = distance_left;
            parameters[5] = distance_right;
            if (skeleton.Joints[JointType.ShoulderRight].TrackingState == TrackingState.Tracked &&
                skeleton.Joints[JointType.HandTipRight].TrackingState == TrackingState.Tracked &&
                skeleton.Joints[JointType.HipRight].TrackingState == TrackingState.Tracked &&
                skeleton.Joints[JointType.ShoulderLeft].TrackingState == TrackingState.Tracked &&
                skeleton.Joints[JointType.HandTipLeft].TrackingState == TrackingState.Tracked &&
                skeleton.Joints[JointType.HipLeft].TrackingState == TrackingState.Tracked)
            {
                var message = new SharpOSC.OscMessage("test/1", parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5]);
                sender.Send(message);
            }
            return(parameters);
        }
Exemple #11
0
        public void ListenerLoadTest()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            var msg = new SharpOSC.OscMessage("/test/", 23.42f);

            for (int i = 0; i < 1000; i++)
                sender.Send(msg);

            for (int i = 0; i < 1000; i++)
            {
                var receivedMessage = listener.Receive();
                Assert.NotNull(receivedMessage);
            }

            listener.Dispose();
        }
Exemple #12
0
        public void ListenerLoadTest()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            var msg = new SharpOSC.OscMessage("/test/", 23.42f);

            for (int i = 0; i < 1000; i++)
            {
                sender.Send(msg);
            }

            for (int i = 0; i < 1000; i++)
            {
                var receivedMessage = listener.Receive();
                Assert.NotNull(receivedMessage);
            }

            listener.Dispose();
        }
        public MainPage()
        {
            this.InitializeComponent();

            osc = new SharpOSC.UDPSender("127.0.0.1", 5000);

            foreach (HostName localHostName in NetworkInformation.GetHostNames())
            {
                if (localHostName.IPInformation != null)
                {
                    if (localHostName.Type == HostNameType.Ipv4)
                    {
                        oscIP.Text = localHostName.ToString();
                        break;
                    }
                }
            }

            SharpOSC.OscMessage msg = new SharpOSC.OscMessage("/test", "test");
            osc.Send(msg);

            Scan();
        }
        public void TestMessage()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            // Test every message type (except Symbol)
            var msg1 = new SharpOSC.OscMessage(
                "/test/address",

                23,
                42.42f,
                "hello world",
                new byte[3] { 2, 3, 4 },
                -123456789123,
                new Timetag(DateTime.Now.Date).Tag,
                new Timetag(DateTime.Now.Date.AddMonths(1)),
                (double)1234567.890,
                new Symbol("wut wut"),
                (char)'x',
                new RGBA(20, 40, 60, 255),
                new Midi(3, 110, 55, 66),
                true,
                false,
                null,
                Double.PositiveInfinity
            );

            OscMessage msgRevc = null;

            sender.Send(msg1);
            msgRevc = (OscMessage)listener.Receive();
            Assert.NotNull(msgRevc);

            Assert.AreEqual("/test/address", msgRevc.Address);
            Assert.AreEqual(16, msgRevc.Arguments.Count);

            Assert.AreEqual(23,												msgRevc.Arguments[0]);
            Assert.AreEqual(42.42f,											msgRevc.Arguments[1]);
            Assert.AreEqual("hello world",									msgRevc.Arguments[2]);
            Assert.AreEqual(new byte[3] { 2, 3, 4 },						msgRevc.Arguments[3]);
            Assert.AreEqual(-123456789123,									msgRevc.Arguments[4]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date),					msgRevc.Arguments[5]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date.AddMonths(1)),	msgRevc.Arguments[6]);
            Assert.AreEqual((double)1234567.890,							msgRevc.Arguments[7]);
            Assert.AreEqual(new Symbol("wut wut"),							msgRevc.Arguments[8]);
            Assert.AreEqual((char)'x',										msgRevc.Arguments[9]);
            Assert.AreEqual(new RGBA(20, 40, 60, 255),						msgRevc.Arguments[10]);
            Assert.AreEqual(new Midi(3, 110, 55, 66),						msgRevc.Arguments[11]);
            Assert.AreEqual(true,											msgRevc.Arguments[12]);
            Assert.AreEqual(false,											msgRevc.Arguments[13]);
            Assert.AreEqual(null,											msgRevc.Arguments[14]);
            Assert.AreEqual(Double.PositiveInfinity,						msgRevc.Arguments[15]);

            listener.Close();
        }
Exemple #15
0
        // Capturing and processing the video frame by frame

        /*   private void RecordingLoop()
         * {
         *     // Set up the recording objects first
         *     Thread.CurrentThread.IsBackground = true;
         *
         *     System.IO.StreamWriter output_head_pose_file = null;
         *
         *     if (record_head_pose)
         *     {
         *         String filename_poses = output_root + "/trial_" + trial_id + ".poses.txt";
         *         output_head_pose_file = new System.IO.StreamWriter(filename_poses);
         *         output_head_pose_file.WriteLine("time(ms), success, pose_X(mm), pose_Y(mm), pose_Z(mm), pitch(deg), yaw(deg), roll(deg)");
         *     }
         *
         *     VideoWriter video_writer = null;
         *
         *     if (record_video)
         *     {
         *         double fps = processing_fps.GetFPS();
         *         String filename_video = output_root + "/trial_" + trial_id + ".avi";
         *         video_writer = new VideoWriter(filename_video, img_width, img_height, fps, true);
         *     }
         *
         *     // The timiing should be when the item is captured, but oh well
         *     Stopwatch stopWatch = new Stopwatch();
         *     stopWatch.Start();
         *
         *     while (recording)
         *     {
         *         Tuple<RawImage, bool, List<double>> recording_object;
         *         if (recording_objects.TryDequeue(out recording_object))
         *         {
         *
         *             if (record_video)
         *             {
         *                 video_writer.Write(recording_object.Item1);
         *             }
         *
         *             if (record_head_pose)
         *             {
         *                 String output_pose_line = stopWatch.ElapsedMilliseconds.ToString();
         *                 if (recording_object.Item2)
         *                     output_pose_line += ", 1";
         *                 else
         *                     output_pose_line += ", 0";
         *
         *                 for (int i = 0; i < recording_object.Item3.Count; ++i)
         *                 {
         *                     double num = recording_object.Item3[i];
         *                     if (i > 2)
         *                     {
         *                         output_pose_line += ", " + num * 180 / Math.PI;
         *                     }
         *                     else
         *                     {
         *                         output_pose_line += ", " + num;
         *                     }
         *                 }
         *                 output_head_pose_file.WriteLine(output_pose_line);
         *             }
         *         }
         *
         *         Thread.Sleep(10);
         *     }
         *
         *     // Clean up the recording
         *     if (record_head_pose)
         *     {
         *         output_head_pose_file.Close();
         *     }
         * }
         *
         * // Capturing and processing the video frame by frame*/
        private void VideoLoop(UtilitiesOF.SequenceReader reader)
        {
            Thread.CurrentThread.IsBackground = true;

            String root = AppDomain.CurrentDomain.BaseDirectory;
            FaceModelParameters model_params = new FaceModelParameters(root, false);
            CLNF face_model = new CLNF(model_params);
            GazeAnalyserManaged gaze_analyser = new GazeAnalyserManaged();

            DateTime?startTime = CurrentTime;

            var lastFrameTime = CurrentTime;

            while (running)
            {
                //////////////////////////////////////////////
                // CAPTURE FRAME AND DETECT LANDMARKS FOLLOWED BY THE REQUIRED IMAGE PROCESSING
                //////////////////////////////////////////////

                RawImage frame = reader.GetNextImage();

                lastFrameTime = CurrentTime;
                processing_fps.AddFrame();

                var grayFrame = reader.GetCurrentFrameGray();

                if (mirror_image)
                {
                    frame.Mirror();
                    grayFrame.Mirror();
                }

                bool detectionSucceeding = ProcessFrame(face_model, gaze_analyser, model_params, frame, grayFrame, reader.GetFx(), reader.GetFy(), reader.GetCx(), reader.GetCy());

                lock (recording_lock)
                {
                    if (recording)
                    {
                        // Add objects to recording queues
                        List <double> pose = new List <double>();
                        face_model.GetPose(pose, reader.GetFx(), reader.GetFy(), reader.GetCx(), reader.GetCy());
                        RawImage image = new RawImage(frame);
                        recording_objects.Enqueue(new Tuple <RawImage, bool, List <double> >(image, detectionSucceeding, pose));
                    }
                }

                List <Tuple <System.Windows.Point, System.Windows.Point> > lines = null;
                List <Tuple <double, double> > eye_landmarks = null;
                List <System.Windows.Point>    landmarks     = new List <System.Windows.Point>();
                List <Tuple <System.Windows.Point, System.Windows.Point> > gaze_lines = null;
                Tuple <double, double> gaze_angle = new Tuple <double, double>(0, 0);
                double scale = face_model.GetRigidParams()[0];

                if (detectionSucceeding)
                {
                    List <Tuple <double, double> > landmarks_doubles = face_model.CalculateVisibleLandmarks();

                    foreach (var p in landmarks_doubles)
                    {
                        landmarks.Add(new System.Windows.Point(p.Item1, p.Item2));
                    }

                    eye_landmarks = face_model.CalculateVisibleEyeLandmarks();

                    gaze_lines = gaze_analyser.CalculateGazeLines(reader.GetFx(), reader.GetFy(), reader.GetCx(), reader.GetCy());
                    gaze_angle = gaze_analyser.GetGazeAngle();

                    lines = face_model.CalculateBox(reader.GetFx(), reader.GetFy(), reader.GetCx(), reader.GetCy());
                }

                if (reset)
                {
                    face_model.Reset();
                    reset = false;
                }

                // Visualisation updating
                try
                {
                    Dispatcher.Invoke(DispatcherPriority.Render, new TimeSpan(0, 0, 0, 0, 200), (Action)(() =>
                    {
                        if (latest_img == null)
                        {
                            latest_img = frame.CreateWriteableBitmap();
                        }

                        List <double> pose = new List <double>();
                        face_model.GetPose(pose, reader.GetFx(), reader.GetFy(), reader.GetCx(), reader.GetCy());

                        int yaw = (int)(pose[4] * 180 / Math.PI + 0.5);
                        int yaw_abs = Math.Abs(yaw);

                        int roll = (int)(pose[5] * 180 / Math.PI + 0.5);
                        int roll_abs = Math.Abs(roll);

                        int pitch = (int)(pose[3] * 180 / Math.PI + 0.5);
                        int pitch_abs = Math.Abs(pitch);

                        YawLabel.Content = yaw_abs + "°";
                        RollLabel.Content = roll_abs + "°";
                        PitchLabel.Content = pitch_abs + "°";
                        var message = new SharpOSC.OscMessage("/n_set", 1006, "freq", (pitch_abs * 10) + 150);
                        var oscSender = new SharpOSC.UDPSender("127.0.0.1", 57110);
                        oscSender.Send(message);

                        if (yaw > 0)
                        {
                            YawLabelDir.Content = "Right";
                        }
                        else if (yaw < 0)
                        {
                            YawLabelDir.Content = "Left";
                        }
                        else
                        {
                            YawLabelDir.Content = "Straight";
                        }

                        if (pitch > 0)
                        {
                            PitchLabelDir.Content = "Down";
                        }
                        else if (pitch < 0)
                        {
                            PitchLabelDir.Content = "Up";
                        }
                        else
                        {
                            PitchLabelDir.Content = "Straight";
                        }

                        if (roll > 0)
                        {
                            RollLabelDir.Content = "Left";
                        }
                        else if (roll < 0)
                        {
                            RollLabelDir.Content = "Right";
                        }
                        else
                        {
                            RollLabelDir.Content = "Straight";
                        }

                        XPoseLabel.Content = (int)pose[0] + " mm";
                        YPoseLabel.Content = (int)pose[1] + " mm";
                        ZPoseLabel.Content = (int)pose[2] + " mm";

                        String x_angle = String.Format("{0:F0}°", gaze_angle.Item1 * (180.0 / Math.PI));
                        String y_angle = String.Format("{0:F0}°", gaze_angle.Item2 * (180.0 / Math.PI));
                        YawLabelGaze.Content = x_angle;
                        PitchLabelGaze.Content = y_angle;

                        if (gaze_angle.Item1 > 0)
                        {
                            YawLabelGazeDir.Content = "Right";
                        }
                        else if (gaze_angle.Item1 < 0)
                        {
                            YawLabelGazeDir.Content = "Left";
                        }
                        else
                        {
                            YawLabelGazeDir.Content = "Straight";
                        }

                        if (gaze_angle.Item2 > 0)
                        {
                            PitchLabelGazeDir.Content = "Down";
                        }
                        else if (gaze_angle.Item2 < 0)
                        {
                            PitchLabelGazeDir.Content = "Up";
                        }
                        else
                        {
                            PitchLabelGazeDir.Content = "Straight";
                        }

                        double confidence = face_model.GetConfidence();

                        if (confidence < 0)
                        {
                            confidence = 0;
                        }
                        else if (confidence > 1)
                        {
                            confidence = 1;
                        }

                        frame.UpdateWriteableBitmap(latest_img);

                        webcam_img.Source = latest_img;
                        webcam_img.Confidence = confidence;
                        webcam_img.FPS = processing_fps.GetFPS();
                        if (!detectionSucceeding)
                        {
                            webcam_img.OverlayLines.Clear();
                            webcam_img.OverlayPoints.Clear();
                            webcam_img.OverlayEyePoints.Clear();
                            webcam_img.GazeLines.Clear();
                        }
                        else
                        {
                            webcam_img.OverlayLines = lines;
                            webcam_img.OverlayPoints = landmarks;
                            webcam_img.FaceScale = scale;

                            List <System.Windows.Point> eye_landmark_points = new List <System.Windows.Point>();
                            foreach (var p in eye_landmarks)
                            {
                                eye_landmark_points.Add(new System.Windows.Point(p.Item1, p.Item2));
                            }


                            webcam_img.OverlayEyePoints = eye_landmark_points;
                            webcam_img.GazeLines = gaze_lines;

                            // Publish the information for other applications
                            String str_head_pose = String.Format("{0}:{1:F2}, {2:F2}, {3:F2}, {4:F2}, {5:F2}, {6:F2}", "HeadPose", pose[0], pose[1], pose[2],
                                                                 pose[3] * 180 / Math.PI, pose[4] * 180 / Math.PI, pose[5] * 180 / Math.PI);

                            zero_mq_socket.Send(new ZFrame(str_head_pose, Encoding.UTF8));

                            String str_gaze = String.Format("{0}:{1:F2}, {2:F2}", "GazeAngle", gaze_angle.Item1 * (180.0 / Math.PI), gaze_angle.Item2 * (180.0 / Math.PI));

                            zero_mq_socket.Send(new ZFrame(str_gaze, Encoding.UTF8));
                        }
                    }));

                    while (running & pause)
                    {
                        Thread.Sleep(10);
                    }
                }
                catch (TaskCanceledException)
                {
                    // Quitting
                    break;
                }
            }
            reader.Close();
            System.Console.Out.WriteLine("Thread finished");
        }
Exemple #16
0
        static void Main(string[] args)
        {
            double average;
            double sumOfSquaresOfDifferences;
            double sdx;
            double sdy;
            float  two = 2;

            double[] last10x             = new double[10];
            double[] last10y             = new double[10];
            float[]  last10sdx           = new float[10];
            float[]  last10sdy           = new float[10];
            float    lastx               = 200;
            float    lasty               = 200;
            var      sender              = new SharpOSC.UDPSender("127.0.0.1", 6448);
            var      sender2             = new SharpOSC.UDPSender("127.0.0.1", 6449);
            var      sender3             = new SharpOSC.UDPSender("127.0.0.1", 12003);
            int      numSet              = 0;
            int      clickCounter        = 0;
            int      noClick             = 0;
            var      host                = new Host();
            var      gazePointDataStream = host.Streams.CreateGazePointDataStream();

            gazePointDataStream.GazePoint((gazePointX, gazePointY, _) => {
                lastx           = (float)gazePointX;
                lasty           = (float)gazePointY;
                last10x[numSet] = gazePointX;
                last10y[numSet] = gazePointY;
                numSet          = numSet + 1;
                if (numSet > 9)
                {
                    average = last10x.Average();
                    sumOfSquaresOfDifferences = last10x.Select(val => (val - average) * (val - average)).Sum();
                    sdx     = Math.Sqrt(sumOfSquaresOfDifferences / last10x.Length);
                    average = last10y.Average();
                    sumOfSquaresOfDifferences = last10y.Select(val => (val - average) * (val - average)).Sum();
                    sdy = Math.Sqrt(sumOfSquaresOfDifferences / last10y.Length);

                    for (int i = 0; i < 9; i++)
                    {
                        last10sdx[i] = last10sdx[i + 1];
                        last10sdy[i] = last10sdy[i + 1];
                    }
                    last10sdx[9] = (float)sdx;
                    last10sdy[9] = (float)sdy;
                    numSet       = 0;
                    //Console.WriteLine("X: {0} Y:{1}", last10sdx[0], last10sdy[0]);
                }
                //Console.WriteLine("X: {0} Y:{1}", last10sdx[0], last10sdy[0]);
                var message = new SharpOSC.OscMessage("/wek/inputs", last10sdx[0], last10sdx[1], last10sdx[2], last10sdx[3], last10sdx[4], last10sdx[5], last10sdx[6], last10sdx[7], last10sdx[8], last10sdx[9],
                                                      last10sdy[0], last10sdy[1], last10sdy[2], last10sdy[3], last10sdy[4], last10sdy[5], last10sdy[6], last10sdy[7], last10sdy[8], last10sdy[9]);
                //var message = new SharpOSC.OscMessage("/wek/inputs", last10sdx[0]);


                sender.Send(message);
                sender2.Send(message);

                //Console.WriteLine("X: {0} Y:{1}", gazePointX, gazePointY);
            });


            //Console.WriteLine("X: {0} Y:{1}", gazePointX, gazePointY));


            SharpOSC.HandleOscPacket callback = delegate(SharpOSC.OscPacket packet)
            {
                var messageReceived = (SharpOSC.OscMessage)packet;
                int receivedMessage = Int32.Parse(messageReceived.Arguments[0].ToString());

                //if (messageReceived.Arguments[0] == 2)
                if (receivedMessage == 2)
                {
                    clickCounter++;
                    if (clickCounter > 100)
                    {
                        clickCounter = 0;
                        noClick      = 0;
                        Console.WriteLine("Sent Coordinates!");
                        Console.WriteLine("Class: {0}", messageReceived.Arguments[0]);
                        var message2 = new SharpOSC.OscMessage("/wek/outputs", lastx, lasty);
                        sender3.Send(message2);
                    }
                }
                else
                {
                    noClick = noClick + 1;
                    if (noClick == 40)
                    {
                        noClick      = 0;
                        clickCounter = 0;
                    }
                }
            };

            var listener = new SharpOSC.UDPListener(12002, callback);

            ///Console.WriteLine("Press enter to stop");


            while (true)
            {
            }
        }
Exemple #17
0
        public void ListenerSingleMSG()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            var msg = new SharpOSC.OscMessage("/test/", 23.42f);

            sender.Send(msg);

            while (true)
            {
                var pack = listener.Receive();
                if (pack == null)
                    Thread.Sleep(1);
                else
                    break;
            }

            listener.Dispose();
        }