Exemple #1
0
        public void test(Bitmap b)
        {
            ColorImage img = new ColorImage(b);
            PatchMatcher.MatchResult b1 = b1patt.matching(img);
            PatchMatcher.MatchResult b2 = b2patt.matching(img);
            PatchMatcher.MatchResult g1 = g1patt.matching(img);
            PatchMatcher.MatchResult g2 = g2patt.matching(img);
            PatchMatcher.MatchResult r1 = r2patt.matching(img);
            bool mkb1 = false, mkb2 = false, mkg1 = false, mkr2 = false,mkg2=false;
            if (b2.score < 9000)
            {
                mkb2 = true;    //B2検出
            }
            else if (b1.score < 8000)
            {
                mkb1 = true;    //B1検出
            }
            if (g2.score < 10000)
            {
                mkg2 = true;    //G2検出
            }
            else if (g1.score < 8000)
            {
                mkg1 = true;    //G1検出
            }
            if (r1.score < 8000)
            {
                mkr2 = true;    //R2検出
            }
            //            System.Console.WriteLine(sw.ElapsedMilliseconds+"[ms]");
            //アクションの決定
            if (!this.st.b1 && mkb1)
            {
                //新規B1
                System.Console.WriteLine("B1検出" + b1.score + ":" + b2.score + ":" + g1.score + ":" + g2.score + ":" + r1.score);
                int ti = (this.st.down_idx + this.st.up_idx);
                if (isEnable(ti))

                {
                     SendKeys.SendWait("{UP}");
               }
                this.st.rep = PadState.Repeat.None;
                this.st.up_idx++;
            }
            if (!this.st.b2 && mkb2)
            {
                //新規B2
                System.Console.WriteLine("B2検出" + b1.score + ":" + b2.score + ":" + g1.score + ":" + g2.score + ":" + r1.score);
                if (this.st.rep == PadState.Repeat.None)
                {
                    this.st.rep = PadState.Repeat.Blue;
                    this.st.repeat_counter = rep_tbl[this.st.ud_idx];
                    this.st.ud_idx++;
                }
                else
                {
                    this.st.rep = PadState.Repeat.None;
                }

            }
            if (!this.st.g1 && mkg1)
            {
                //新規G1
                System.Console.WriteLine("G1検出" + b1.score + ":" + b2.score + ":" + g1.score + ":" + g2.score + ":" + r1.score);
                int ti=(this.st.down_idx+this.st.up_idx);
                if (isEnable(ti))
                {
                    SendKeys.SendWait("{DOWN}");
                }
                this.st.rep = PadState.Repeat.None;
                this.st.down_idx++;
            }
            if (!this.st.g2 && mkg2)
            {
                //新規G2
                System.Console.WriteLine("G2検出" + b1.score + ":" + b2.score + ":" + g1.score + ":" + g2.score + ":" + r1.score);
                if (this.st.rep == PadState.Repeat.None)
                {
                    this.st.rep = PadState.Repeat.Green;
                    this.st.repeat_counter = rep_tbl[this.st.ud_idx];
                    this.st.ud_idx++;
                }
                else
                {
                    this.st.rep = PadState.Repeat.None;
                }
            }
            if (!this.st.r2 && mkr2)
            {
                //新規R2
                System.Console.WriteLine("R2検出");
                if (this.st.rep == PadState.Repeat.None)
                {
                    this.st.rep = PadState.Repeat.Dual;
                    this.st.repeat_counter = rep_tbl[this.st.ud_idx];
                    this.st.ud_idx++;
                }
                else
                {
                    this.st.rep = PadState.Repeat.None;
                }
            }

            //ステータスの決定
            this.st.b1 = mkb1;
            this.st.b2 = mkb2;
            this.st.g1 = mkg1;
            this.st.g2 = mkg2;
            this.st.r2 = mkr2;
        }
Exemple #2
0
 public PatchMatcher(Bitmap i_patch)
 {
     this._patch = new ColorImage(i_patch);
 }
Exemple #3
0
 public MatchResult matching(ColorImage i_src)
 {
     int cw = i_src.w - this._patch.w;
     int ch = i_src.h - this._patch.h;
     MatchResult ret = new MatchResult(0, 0, int.MaxValue, (int)(this._patch.w * this._patch.h * Math.Sqrt(255 * 255 * 3)));
     for (int sy = 0; sy <= ch; sy++)
     {
         for (int sx = 0; sx <= cw; sx++)
         {
             int r = getScore(i_src, sx, sy, this._patch);
             if (r < ret.score)
             {
                 ret.set(sx, sy, r);
             }
         }
     }
     return ret;
 }
Exemple #4
0
 private static int getScore(ColorImage i_s, int tx, int ty, ColorImage i_patch)
 {
     int sum = 0;
     for (int y = 0; y < i_patch.h; y++)
     {
         for (int x = 0; x < i_patch.w; x++)
         {
             UInt32 ps = i_s.buf[i_s.w * (y+ty) + x+tx];
             UInt32 pp = i_patch.buf[i_patch.w * y + x];
             int rs = (int)(((ps >> 0) & 0xff) - ((pp >> 0) & 0xff));
             int gs = (int)(((ps >> 8) & 0xff) - ((pp >> 8) & 0xff));
             int bs = (int)(((ps >>16) & 0xff) - ((pp >>16) & 0xff));
             sum += (int)Math.Sqrt(rs * rs + gs * gs + bs * bs);
         }
     }
     return sum;
 }