From 482800d5aeca65fdfe29ccb9a0794619da3bca0b Mon Sep 17 00:00:00 2001 From: NumesSanguis lab Date: Wed, 18 Apr 2018 23:14:37 +0900 Subject: [PATCH] real-time OpenFace with configuration file for ZeroMQ --- openface/MainWindow.xaml.cs | 104 ++++++++++++++++++++++++++---------- openface/config.xml | 9 ++++ 2 files changed, 84 insertions(+), 29 deletions(-) mode change 100755 => 100644 openface/MainWindow.xaml.cs create mode 100644 openface/config.xml diff --git a/openface/MainWindow.xaml.cs b/openface/MainWindow.xaml.cs old mode 100755 new mode 100644 index f3b8361..c655f82 --- a/openface/MainWindow.xaml.cs +++ b/openface/MainWindow.xaml.cs @@ -67,6 +67,8 @@ using NetMQ.Sockets; using Newtonsoft.Json; using System.Net; +using System.IO; +using System.Xml; namespace OpenFaceOffline { @@ -78,24 +80,30 @@ public struct JsonData public double confidence; public struct Pose { - public double x; - public double y; - public double z; - public double pitch; - public double roll; - public double yaw; + public double pose_Tx; + public double pose_Ty; + public double pose_Tz; + public double pose_Rx; + public double pose_Ry; + public double pose_Rz; } public Pose pose; public struct Gaze { - public double x; - public double y; - //public Point + public double gaze_angle_x; + public double gaze_angle_y; + public double gaze_0_x; + public double gaze_0_y; + public double gaze_0_z; + public double gaze_1_x; + public double gaze_1_y; + public double gaze_1_z; } public Gaze gaze; public Dictionary au_c; public Dictionary au_r; } + /// /// Interaction logic for MainWindow.xaml /// @@ -104,6 +112,8 @@ public partial class MainWindow : Window // By Huang PublisherSocket pubSocket = null; long frame_no = 0; + string topic = "openface"; + //Mode running_mode = Mode.standalone; // Timing for measuring FPS #region High-Resolution Timing @@ -184,11 +194,44 @@ public static DateTime CurrentTime public MainWindow() { - String hostName = Dns.GetHostName(); + bool bPush = false; + + string configfile_name = "config.xml"; + + FileStream stream = new FileStream(configfile_name, FileMode.Open); + XmlDocument document = new XmlDocument(); + document.Load(stream); + + string serveraddress = "localhost"; + int port = 5570; + + + XmlNodeList list = document.GetElementsByTagName("Mode"); + if (list.Count > 0 && ((XmlElement)list[0]).InnerText.ToLower().Equals("push")) + bPush = true; + list = document.GetElementsByTagName("IP"); + if(list.Count > 0) + { + serveraddress = ((XmlElement)list[0]).InnerText; + } + list = document.GetElementsByTagName("Port"); + if(list.Count > 0) + { + port = Int32.Parse(((XmlElement)list[0]).InnerText); + } + list = document.GetElementsByTagName("Topic"); + if(list.Count > 0) + { + topic = ((XmlElement)list[0]).InnerText; + } + + + String hostName = Dns.GetHostName(); IPAddress[] addresses = Dns.GetHostAddresses(hostName); string myaddress = "localhost"; + foreach (IPAddress address in addresses) { if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) @@ -216,7 +259,10 @@ public MainWindow() // Added by Huang pubSocket = new PublisherSocket(); pubSocket.Options.SendHighWatermark = 1000; - pubSocket.Connect("tcp://" + myaddress + ":5570"); //bind + if(bPush) + pubSocket.Connect("tcp://" + serveraddress + ":" + port); + else + pubSocket.Bind("tcp://" + myaddress + ":" + port); } @@ -467,7 +513,6 @@ private void RecordObservation(RecorderOpenFace recorder, RawImage vis_image, bo // added by Huang private void SendZeroMQMessage(bool success, float fx, float fy, float cx, float cy, double openface_timestamp) { - //List> eye_landmarks = null; Tuple gaze_angle = new Tuple(0, 0); List pose = new List(); List non_rigid_params = landmark_detector.GetNonRigidParams(); @@ -475,7 +520,7 @@ private void SendZeroMQMessage(bool success, float fx, float fy, float cx, float NetMQMessage output_message = new NetMQMessage(); - output_message.Append("openface"); + output_message.Append(topic); JsonData json_data = new JsonData(); @@ -496,27 +541,28 @@ private void SendZeroMQMessage(bool success, float fx, float fy, float cx, float pose = new List(); landmark_detector.GetPose(pose, fx, fy, cx, cy); - //json_data.pose.yaw = pose[4] * 180 / Math.PI + 0.5; - //json_data.pose.roll = pose[5] * 180 / Math.PI + 0.5; - //json_data.pose.pitch = pose[3] * 180 / Math.PI + 0.5; - json_data.pose.yaw = pose[4]; - json_data.pose.roll = pose[5]; - json_data.pose.pitch = pose[3]; - json_data.pose.x = pose[0]; - json_data.pose.y = pose[1]; - json_data.pose.z = pose[2]; - gaze_angle = gaze_analyser.GetGazeAngle(); - //json_data.gaze.x = gaze_angle.Item1 * (180.0 / Math.PI); - //json_data.gaze.y = gaze_angle.Item2 * (180.0 / Math.PI); - json_data.gaze.x = gaze_angle.Item1; - json_data.gaze.y = gaze_angle.Item2; + json_data.pose.pose_Tx = pose[0]; + json_data.pose.pose_Ty = pose[1]; + json_data.pose.pose_Tz = pose[2]; + json_data.pose.pose_Rx = pose[3]; + json_data.pose.pose_Ry = pose[4]; + json_data.pose.pose_Rz = pose[5]; - json_data.au_c = face_analyser.GetCurrentAUsClass(); + gaze_angle = gaze_analyser.GetGazeAngle(); + var gaze = gaze_analyser.GetGazeCamera(); + json_data.gaze.gaze_angle_x = gaze_angle.Item1; + json_data.gaze.gaze_angle_y = gaze_angle.Item2; + json_data.gaze.gaze_0_x = gaze.Item1.Item1; + json_data.gaze.gaze_0_y = gaze.Item1.Item2; + json_data.gaze.gaze_0_z = gaze.Item1.Item3; + json_data.gaze.gaze_1_x = gaze.Item2.Item1; + json_data.gaze.gaze_1_y = gaze.Item2.Item2; + json_data.gaze.gaze_1_z = gaze.Item2.Item3; + json_data.au_c = face_analyser.GetCurrentAUsClass(); - //var au_regs_scaled = new Dictionary(); Dictionary au_regs = face_analyser.GetCurrentAUsReg(); json_data.au_r = new Dictionary(); foreach (KeyValuePair au_reg in au_regs) diff --git a/openface/config.xml b/openface/config.xml new file mode 100644 index 0000000..966bcd8 --- /dev/null +++ b/openface/config.xml @@ -0,0 +1,9 @@ + + + push + + + 127.0.0.1 + 5570 + openface + \ No newline at end of file