好吧,首先我需要说这可能会很慢,所以如果红色矩形移动得很快,你需要一些其他的解决方案。C++、CUDA 等...
第一:保存红色矩形的图像。定义红色矩形的可能位置区域。
脚步:
- 捕获游戏图像(您可以使用 Graphics CopyFromScreen)。仅复制可能是红色矩形的区域,以减少处理时间。
- 使用 EmguCV MatchTemplate 找到红色矩形的位置。
- 将鼠标移动到该位置。
- 一些线程睡眠并重复 1 ......
处理图像使用EmguCV
控制鼠标使用MouseKeyboardActivityMonitor
加速说明:EmguCV 现在有一些 CUDA 支持,所以你可以尝试使用 CUDA 版本的方法。
//You can check if a 8bpp image is enough for the comparison,
//since it will be much more faster. Otherwise, use 24bpp images.
//Bitmap pattern = "YOUR RED RECTANGLE IMAGE HERE!!"
Point location = Point.Empty;
//source is the screen image !!
Image<Bgr, Byte> srcBgr = new Image<Bgr, Byte>(source);
Image<Bgr, Byte> templateBgr = new Image<Bgr, Byte>(pattern);
Image<Gray, Byte> src;
Image<Gray, Byte> template;
src = srcBgr.Convert<Gray, Byte>();
template = templateBgr.Convert<Gray, Byte>();
Image<Gray, float> matchFloat;
matchFloat = src.MatchTemplate(template, TM_TYPE.CV_TM_CCOEFF_NORMED);
if (debug)
{
//matchFloat.Save(@"match.png");
//Process.Start(@"D:\match.png");
}
//Gets the max math value
double max;
double[] maxs, mins;
Point[] maxLocations, minLocations;
matchFloat.MinMax(out mins, out maxs, out minLocations, out maxLocations);
max = maxs[0];
if (max > threshold)
{
location = maxLocations[0];
//Point the mouse... Do your stuff