Пример #1
0
        public void Update()
        {
            if (processHandle != System.IntPtr.Zero)
            {
                trackerAlive = OpenSeeProcessInterface.Alive(processHandle);
                return;
            }
            else
            {
                if (trackerProcess != null)
                {
                    trackerAlive = !trackerProcess.HasExited;
                }
                else
                {
                    trackerAlive = false;
                    return;
                }
            }
            if (dontPrintNow || trackerSB == null)
            {
                return;
            }
            int len = trackerSB.Length;

            if (len > 0)
            {
                string output = trackerSB.ToString();
                UnityEngine.Debug.Log("Tracker: " + output);
                trackerSB.Clear();
            }
        }
Пример #2
0
 public void StopTracker()
 {
     if (processHandle != System.IntPtr.Zero)
     {
         if (OpenSeeProcessInterface.Alive(processHandle))
         {
             OpenSeeProcessInterface.TerminateProcess(processHandle, 0);
         }
         OpenSeeProcessInterface.CloseHandle(processHandle);
         processHandle = System.IntPtr.Zero;
     }
     if (processStdOut != System.IntPtr.Zero)
     {
         OpenSeeProcessInterface.CloseHandle(processStdOut);
         processStdOut = System.IntPtr.Zero;
     }
     if (processStdErr != System.IntPtr.Zero)
     {
         OpenSeeProcessInterface.CloseHandle(processStdErr);
         processStdErr = System.IntPtr.Zero;
     }
     if (trackerProcess != null && !trackerProcess.HasExited)
     {
         trackerProcess.CloseMainWindow();
         trackerProcess.Close();
         if (!dontPrintNow)
         {
             try {
                 trackerProcess.CancelOutputRead();
                 trackerProcess.CancelErrorRead();
             } catch {}
         }
     }
     trackerProcess = null;
 }
Пример #3
0
        public bool StartTracker()
        {
            if (!CheckSetup(true))
            {
                return(false);
            }

            List <string> arguments = new List <string>();

            arguments.Add("--ip");
            arguments.Add(ip);

            if (dynamicPort && !openSeeTarget.listening)
            {
                System.Net.IPEndPoint[] inUse = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners();
                Array.Sort(inUse, delegate(System.Net.IPEndPoint a, System.Net.IPEndPoint b) { return(a.Port.CompareTo(b.Port)); });
                int port = openSeeTarget.listenPort + 1;
                for (int i = 0; i < inUse.Length; i++)
                {
                    if (inUse[i].Port < port)
                    {
                        continue;
                    }
                    if (inUse[i].Port == port)
                    {
                        if (port <= openSeeTarget.listenPort + 500 && port <= IPEndPoint.MaxPort)
                        {
                            port++;
                            continue;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    break;
                }
                openSeeTarget.listenPort = port;
            }

            arguments.Add("--port");
            arguments.Add(openSeeTarget.listenPort.ToString());
            arguments.Add("--model-dir");
            arguments.Add(modelPath);

            arguments.Add("--capture");
            if (videoPath != "" && File.Exists(videoPath))
            {
                arguments.Add(videoPath);
            }
            else
            {
                arguments.Add(cameraIndex.ToString());
            }
            foreach (string argument in commandlineOptions)
            {
                arguments.Add(argument);
            }
            string argumentString = EscapeArguments(arguments.ToArray());

            if (extraOptions != "")
            {
                argumentString = argumentString + " " + extraOptions;
            }

            if (logCommandline)
            {
                UnityEngine.Debug.Log("Starting tracker: " + argumentString);
            }

            StopTracker();

            if (!usePinvoke)
            {
                ProcessStartInfo processStartInfo;
                processStartInfo = new ProcessStartInfo();
                processStartInfo.CreateNoWindow         = true;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardInput  = true;
                processStartInfo.RedirectStandardError  = true;
                processStartInfo.UseShellExecute        = false;
                processStartInfo.FileName  = exePath;
                processStartInfo.Arguments = argumentString;

                trackerSB                = new StringBuilder();
                trackerProcess           = new Process();
                trackerProcess.StartInfo = processStartInfo;
                dontPrintNow             = dontPrint;
                if (!dontPrintNow)
                {
                    trackerProcess.EnableRaisingEvents = true;
                    trackerProcess.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e) {
                        trackerSB.Append(e.Data);
                        trackerSB.Append("\n");
                    });
                    trackerProcess.ErrorDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e) {
                        trackerSB.Append(e.Data);
                        trackerSB.Append("\n");
                    });
                }
                trackerProcess.Start();
                job.AddProcess(trackerProcess.Handle);
                if (!dontPrintNow)
                {
                    trackerProcess.BeginOutputReadLine();
                    trackerProcess.BeginErrorReadLine();
                }

                return(!trackerProcess.HasExited);
            }
            else
            {
                string dir       = Path.GetDirectoryName(exePath);
                string outputLog = Application.persistentDataPath + "/" + pinvokeStdOut;
                string errorLog  = Application.persistentDataPath + "/" + pinvokeStdErr;
                OpenSeeProcessInterface.Start(exePath, "facetracker " + argumentString, dir, true, outputLog, errorLog, out processHandle, out processStdOut, out processStdErr);
                if (processHandle != System.IntPtr.Zero)
                {
                    job.AddProcess(processHandle);
                    return(OpenSeeProcessInterface.Alive(processHandle));
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #4
0
        public bool StartTracker()
        {
            if (!CheckSetup(true))
            {
                return(false);
            }

            List <string> arguments = new List <string>();

            arguments.Add("--ip");
            arguments.Add(ip);
            arguments.Add("--port");
            arguments.Add(openSeeTarget.listenPort.ToString());
            arguments.Add("--model-dir");
            arguments.Add(modelPath);

            arguments.Add("--use-escapi");
            if (useEscapi && (implicitUseOpenCV < 0 || cameraIndex < implicitUseOpenCV))
            {
                arguments.Add("1");
            }
            else
            {
                arguments.Add("0");
            }

            arguments.Add("--capture");
            if (videoPath != "" && File.Exists(videoPath))
            {
                arguments.Add(videoPath);
            }
            else
            {
                arguments.Add(cameraIndex.ToString());
            }
            foreach (string argument in commandlineOptions)
            {
                arguments.Add(argument);
            }
            string argumentString = EscapeArguments(arguments.ToArray());

            StopTracker();

            if (!usePinvoke)
            {
                ProcessStartInfo processStartInfo;
                processStartInfo = new ProcessStartInfo();
                processStartInfo.CreateNoWindow         = true;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardInput  = true;
                processStartInfo.RedirectStandardError  = true;
                processStartInfo.UseShellExecute        = false;
                processStartInfo.FileName  = exePath;
                processStartInfo.Arguments = argumentString;

                trackerSB                = new StringBuilder();
                trackerProcess           = new Process();
                trackerProcess.StartInfo = processStartInfo;
                dontPrintNow             = dontPrint;
                if (!dontPrintNow)
                {
                    trackerProcess.EnableRaisingEvents = true;
                    trackerProcess.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e) {
                        trackerSB.Append(e.Data);
                        trackerSB.Append("\n");
                    });
                    trackerProcess.ErrorDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e) {
                        trackerSB.Append(e.Data);
                        trackerSB.Append("\n");
                    });
                }
                trackerProcess.Start();
                job.AddProcess(trackerProcess.Handle);
                if (!dontPrintNow)
                {
                    trackerProcess.BeginOutputReadLine();
                    trackerProcess.BeginErrorReadLine();
                }

                return(!trackerProcess.HasExited);
            }
            else
            {
                string dir       = Path.GetDirectoryName(exePath);
                string outputLog = Application.persistentDataPath + "/" + pinvokeStdOut;
                string errorLog  = Application.persistentDataPath + "/" + pinvokeStdErr;
                OpenSeeProcessInterface.Start(exePath, "facetracker " + argumentString, dir, true, outputLog, errorLog, out processHandle, out processStdOut, out processStdErr);
                if (processHandle != System.IntPtr.Zero)
                {
                    job.AddProcess(processHandle);
                    return(OpenSeeProcessInterface.Alive(processHandle));
                }
                else
                {
                    return(false);
                }
            }
        }