// 根据进程名查找窗体区域 public DetectionRect findProcessWindowRect(string processName) { DetectionRect srcRect = new DetectionRect(); //缺省使用使用全屏作为工作屏幕,找不到进程窗体区域就使用缺省值 srcRect.setValues(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Process[] allProcess = Process.GetProcesses(); if (allProcess != null && allProcess.Length > 0) { foreach (Process process in allProcess) { if (process != null && process.ProcessName != null) { string tmpName = process.ProcessName.ToLower(); if (tmpName.StartsWith(processName.ToLower())) { //如果MainWindowHandle不为0,则获取找到的进程的窗口 IntPtr hWnd = process.MainWindowHandle; if (hWnd != IntPtr.Zero) { RECT winRect = new RECT(); GetWindowRect(hWnd, ref winRect); //h为窗口句柄 RECT clientRect = new RECT(); GetClientRect(hWnd, ref clientRect); //h为窗口句柄 srcRect.setValues(winRect.Left + (winRect.Right - winRect.Left - clientRect.Right) / 2, winRect.Top + (winRect.Bottom - winRect.Top - clientRect.Bottom), clientRect.Right, clientRect.Bottom); break; } } } } } return(srcRect); }
public ScreenDetection(Form mainForm, PictureBox outPictureBox) { this.mainForm = mainForm; this.outPictureBox = outPictureBox; this.detectionNet = CvDnn.ReadNetFromTensorflow(modelFile, configFile); //this.detectionNet = CvDnn.ReadNetFromTensorflow(modelFile); //this.detectionNet.SetPreferableBackend(Backend.DEFAULT); //this.detectionNet.SetPreferableTarget(Target.CPU); this.detectionNet.SetPreferableBackend(Backend.CUDA); this.detectionNet.SetPreferableTarget(Target.CUDA); this.labelNames = File.ReadAllLines(labelFile) .Select(line => line.Split('\n').Last()) .ToArray(); //设置初始检测区域 rawDetectionRect = new DetectionRect(); //缺省使用使用全屏作为工作屏幕 rawDetectionRect.setValues(0, 0, 900, 760); SetSrcScreenRect(rawDetectionRect); }