我有一个实用程序,我正在与其他几个人一起测试,它截取另一个窗口的截图,然后使用OpenCV在该截图中查找较小的图像.
这是没有问题的,但是,我试图让它更有效率,并且想知道,而不是每X毫秒拍摄一次窗口截图,如果有一种方法我可以将屏幕"流"到我的应用程序,然后对每个通过的新帧运行一个函数.
这是我目前的代码:
public static bool ContainsImage(Detection p_Detection, out long elapsed)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Image<Gray, byte> imgHaystack = new Image<Gray, byte>(CaptureApplication(p_Detection.WindowTitle));
Image<Gray, byte> imgNeedle = new Image<Gray, byte>(p_Detection.Needle);
if (imgHaystack.Width >= p_Detection.Settings.Resolution || imgHaystack.Height >= p_Detection.Settings.Resolution)
{
imgHaystack = imgHaystack.Resize(imgHaystack.Width / p_Detection.Settings.Scale, imgHaystack.Height / p_Detection.Settings.Scale, Emgu.CV.CvEnum.Inter.Area);
imgNeedle = imgNeedle.Resize(imgNeedle.Width / p_Detection.Settings.Scale, imgNeedle.Height / p_Detection.Settings.Scale, Emgu.CV.CvEnum.Inter.Area);
}
if (imgNeedle.Height < imgHaystack.Height && imgNeedle.Width < imgHaystack.Width)
{
using (Image<Gray, float> result = imgHaystack.MatchTemplate(imgNeedle, Emgu.CV.CvEnum.TemplateMatchingType.CcoeffNormed))
{
result.MinMax(out double[] minValues, …Run Code Online (Sandbox Code Playgroud)