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); } } }
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); } } }