まず最初に、これはおそらく遅くなると言わなければならないので、赤い四角形が速く動いている場合は、別の解決策が必要になります。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