1

これに似たトピックがたくさんあることは知っていますが、私が探しているものに対する正確な答えがあったものはありませんでした。

あなたはおそらく(FPS)ゲームを知っており、解像度が1024x768のゲーム画面で、赤い長方形(敵)を見つけてマウスをそこに移動する必要があります。私の主な問題は、その赤い四角形を見つけることです。わかりましたので、これまでに試したことは次のとおりです。

AForge を試してみましたが、メモリが不足しています。

ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0);
TemplateMatch[] matchings = tm.ProcessImage(image1.Clone(r,
        System.Drawing.Imaging.PixelFormat.Format24bppRgb), image2);

CopyfromScreen を使用して image1 を作成し、image2 は私が持っているテンプレートです。

私は LockBits を試したので、ビットマップの 2 次元コード配列を作成し、赤色のコードを見つけて、それが長方形の場合は識別しようとしましたが、アイデアは非常に複雑なようで、ここで 4 日間立ち往生しています。

ウェブにはこれに関する情報がたくさんありますが、調べれば調べるほど混乱します:(

とにかく、ここで私を助けてください:

4

1 に答える 1

0

まず最初に、これはおそらく遅くなると言わなければならないので、赤い四角形が速く動いている場合は、別の解決策が必要になります。C++、CUDA など...

最初: 赤い四角形の画像を保存します。赤い四角形の可能な位置の領域を定義します。

手順:

  1. ゲーム画像をキャプチャします (Graphics CopyFromScreen を使用できます)。処理時間を短縮するために、赤い四角形の領域のみをコピーします。
  2. EmguCV MatchTemplate を使用して、赤い四角形の位置を見つけます。
  3. 位置にマウスを移動します。
  4. 一部のスレッドがスリープし、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
于 2014-03-07T17:23:20.993 に答える