using Crestron.SimplSharp; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.UI; using CrestronOpenCvSharp.Capture; using PhotoBooth; using Directory = Crestron.SimplSharp.CrestronIO.Directory; using Path = Crestron.SimplSharp.CrestronIO.Path; namespace CrestronOpenCvSharp; public class ControlSystem : CrestronControlSystem { private FacialRecognition? _facialRecognition; private MjpegCapture? _capture; private UiHandler? _uiHandler; private XpanelForHtml5 _xpanel; private Contract _contract; // Default snapshot URL of a Bosch camera private const string Url = "http://192.168.1.221/snap.jpg"; private readonly string? _directory; public ControlSystem() : base() { try { Crestron.SimplSharpPro.CrestronThread.Thread.MaxNumberOfUserThreads = 20; _directory = Path.Combine(Directory.GetApplicationRootDirectory(), $"html"); Console.WriteLine($"Home directory = {_directory}"); } catch (Exception e) { ErrorLog.Error("Error in the constructor: {0}", e.Message); } } public override void InitializeSystem() { try { _xpanel = new XpanelForHtml5(0x03, this); _xpanel.Register(); _contract = new Contract(_xpanel); _facialRecognition = new FacialRecognition(_directory, _contract); _capture = new MjpegCapture(Url, _directory, _facialRecognition, _contract); _uiHandler = new UiHandler(_capture); _contract.Main.btnStartCapture_PressEvent += MainOnbtnStartCapture_PressEvent; _contract.Main.btnStopCapture_PressEvent += MainOnbtnStopCapture_PressEvent; //_capture.StartCapture(5000); } catch (Exception e) { ErrorLog.Error("Error in InitializeSystem: {0}", e.Message); } } private void MainOnbtnStopCapture_PressEvent(object? sender, UIEventArgs uiEventArgs) { _capture?.StopCapture(); } private void MainOnbtnStartCapture_PressEvent(object? sender, UIEventArgs uiEventArgs) { _capture?.StartCapture(2000); } }