Es läuft ...

07/05/2009 23:00 Gertos#46
Quote:
Originally Posted by meilleur View Post
I want to use the commande /position, how can i make my bot read this ?
Create a Bitmap from the Screen and run an analyse logic on the Bitmap.

I have notice some things that makes this process easier.

1. The font is using just ONE Color. ( e.g. the Box on the top is using diffrent gray values )
2. The position of the diffrent lines is always the same



Process-Logik:

1. Just get the pixel with the color that you want and make them black.
2. Make all other Colors White.
3. Try to sepearte the diffrent charaters. e.g. by finding a Column that is white.


Bitmap 1

Code:
.................
.X............x..
.X...............
.X......xxx...x..
.X.....xx  x..x..
.X.....xxxxx..x..
.X.....x......x..
.Xxxxx..xxx...x..
.................
Bitmap 2
Split in 3 picutures by removing all unecessary white lines
Code:
-------......---.
-X....-......-x-.
-X....--------.-.
-X....-.xxx.--x-.
-X....-xx  x--x-.
-X....-xxxxx--x-.
-X....-x....--x-.
-Xxxxx-.xxx.--x-.
----------------.
Picture 1

Code:
X....
X....
X....
X....
X....
X....
Xxxxx
Picture 2

Code:
.xxx.
xx  x
xxxxx
x....
.xxx.
Compare the Picutre with a Database and ask the user for an letter , if you have found a unknowen one.
Somethimes there is no full white Column between two letters, so you have to 'train' the logik a bit that is learns all necessary words.


I hope this rough concept leads you in the right direction :)
07/05/2009 23:18 meilleur#47
Quote:
Originally Posted by Gertos View Post
Create a Bitmap from the Screen and run an analyse logic on the Bitmap.

I have notice some things that makes this process easier.

1. The font is using just ONE Color. ( e.g. the Box on the top is using diffrent gray values )
2. The position of the diffrent lines is always the same



Process-Logik:

1. Just get the pixel with the color that you want and make them black.
2. Make all other Colors White.
3. Try to sepearte the diffrent charaters. e.g. by finding a Column that is white.


Bitmap 1

Code:
.................
.X............x..
.X...............
.X......xxx...x..
.X.....xx  x..x..
.X.....xxxxx..x..
.X.....x......x..
.Xxxxx..xxx...x..
.................
Bitmap 2
Split in 3 picutures by removing all unecessary white lines
Code:
-------......---.
-X....-......-x-.
-X....--------.-.
-X....-.xxx.--x-.
-X....-xx  x--x-.
-X....-xxxxx--x-.
-X....-x....--x-.
-Xxxxx-.xxx.--x-.
----------------.
Picture 1

Code:
X....
X....
X....
X....
X....
X....
Xxxxx
Picture 2

Code:
.xxx.
xx  x
xxxxx
x....
.xxx.
Compare the Picutre with a Database and ask the user for an letter , if you have found a unknowen one.
Somethimes there is no full white Column between two letters, so you have to 'train' the logik a bit that is learns all necessary words.


I hope this rough concept leads you in the right direction :)
Thank very much for help
When I creat a bitmap to analyse it I use getpixel/setpixel right?and in tow dimension I gues and that will be very slow
I never used the bitmap method before, I know that there is an aleternative method by pointer
07/06/2009 01:50 Gertos#48
no GetPixel and SetPixel is to slow.

There are better/faster functions available for this.

I have posted an example here:
[Only registered and activated users can see links. Click Here To Register...]


Check this post as well
[Only registered and activated users can see links. Click Here To Register...]
It contains some ultra fast code ( for C# ) to do some work with a Bitmap.
07/06/2009 23:08 meilleur#49
Thank you for you help Gertos
07/07/2009 23:36 meilleur#50
I found OCR programme that have an amazing accuracy but it is trial 100 file, in the website you can download the demo and sample code source, this last is it usable or just sample?
[Only registered and activated users can see links. Click Here To Register...]
07/08/2009 01:05 Night Dragon#51
Quote:
Originally Posted by meilleur View Post
I found OCR programme that have an amazing accuracy but it is trial 100 file, in the website you can download the demo and sample code source, this last is it usable or just sample?
[Only registered and activated users can see links. Click Here To Register...]
Hmmm.. they call it a 'sample code' and yet in C# the code appears to be a fully functioning script. They even give comments on each section and give the code to use their dll. Even better yet (I can't believe this XD) they included the command to show how many samples you have left on your license. They basically just handed over the keys lmao.

Good find meilleur!! I will play with this some more when I have more time.
07/08/2009 02:29 meilleur#52
I founed one fully fonctionel(not trial ^^), it is a sourceCode in vb6, I tried it with bmp 100% accuracy
07/08/2009 11:42 Altaric2#53
You can use MODI from micro$oft office 2003 it works too, that's what i did
i'll still have a look at this one
07/08/2009 14:17 meilleur#54
Quote:
Originally Posted by Altaric2 View Post
You can use MODI from micro$oft office 2003 it works too, that's what i did
i'll still have a look at this one
I know that exist in office but never used it
07/10/2009 20:33 meilleur#55
I tried the MODI and It havn't worked with my Bmp
07/10/2009 21:30 Gertos#56
for me this sounds like breaking a butterfly on a wheel.
Do you really need a full OCR program just to read some character from the screen ?

An easy pattern compare can do the same in my opinion.
07/10/2009 22:09 meilleur#57
Quote:
Originally Posted by Gertos View Post
for me this sounds like breaking a butterfly on a wheel.
Do you really need a full OCR program just to read some character from the screen ?

An easy pattern compare can do the same in my opinion.
Following what you wrote I just need to compare char not need to read it.If I want to correct the position how I can do ?
07/10/2009 23:15 Gertos#58
maybe it is the best if I post some sample code:

I hope you understand a bit German :)

Code:
        public Dictionary<string, string> OCR_Table;

       public static Bitmap GetBitmap(int x, int y, int dx, int dy)
        {
            Bitmap screenCopy = new Bitmap(dx, dy); 
            using (Graphics gdest = Graphics.FromImage(screenCopy)) 

            using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero)) 
            { 
                IntPtr hSrcDC = gsrc.GetHdc(); 
                IntPtr hDC = gdest.GetHdc(); 
                int retval = BitBlt(hDC, 0, 0, dx, dy, hSrcDC, x, y, (int)CopyPixelOperation.SourceCopy); 

                gdest.ReleaseHdc(); 
                gsrc.ReleaseHdc(); 
            }

            return screenCopy;

        }

        private string AnalyseNPC_Name_Phase2(int Mode, Bitmap bild, int x, int y, int x2, int y2)
        {
            // Bild abmalen und ins log schreiben 

            string Zeile = "";


            for (int yy = y; yy <= y2; yy++)
            {
                for (int xx = x; xx <= x2; xx++)
                {
                    Color c = bild.GetPixel(xx, yy);

                    if (Mode == 0)
                    {
                        if (c.B < 80 && c.R < 80 & c.G < 80)
                            Zeile += "X";
                        else if (c.B < 100 && c.R < 100 & c.G < 100)
                            Zeile += "x";
                        else if (c.B < 120 && c.R < 120 & c.G < 120)
                            Zeile += "+";
                        else if (c.B < 140 && c.R < 140 & c.G < 140)
                            Zeile += ".";
                        else
                            Zeile += "_";
                    }
                    else
                    {
                        if (c.B > 100 && c.R > 100 & c.G > 100)
                            Zeile += "X";
                        else
                            Zeile += "_";

                    }

                }
                Zeile += "\n";
            }
            //AddToProtokoll(Zeile);

            // 
            string Buchstabe;
            if (OCR_Table.TryGetValue(Zeile, out Buchstabe) == false)
            {
                if (LearnMode == true)
                {
                    // Dialog anzeigen
                    OCR_Ask_for_Letter dlg = new OCR_Ask_for_Letter();
                    dlg.richTextBox1.AppendText(Zeile);
                    dlg.ShowDialog();
                    Buchstabe = dlg.textBox1.Text;

                    if (Buchstabe.Length > 0)
                    {
                        OCR_Table.Add(Zeile, Buchstabe);
                    }
                }
                else
                    Buchstabe = "?";
            }

            return Buchstabe;
        }


        private string AnalyseNPC_Name_Phase1(int Mode, Bitmap bild)
        {
            // 1. Bild in Buchstaben trennen
            string erg = "";
            bool inBuchstabe = false;
            int minX = 9999;
            int minY = 9999;
            int maxY = -1;

            int UngueltigeZeichenFaktor = 0;

            for (int x = 0; x < bild.Width; x++)
            {
                bool SchwarzFlag = false;
                for (int y = 0; y < bild.Height; y++)
                {
                    // stehen in der aktuellen Row Daten ?
                    Color c = bild.GetPixel(x, y);

                    if (Mode == 0)
                    {
                        // Schwarze Schrift auf grauem grund
                        if (c.B < 100 && c.R < 100 & c.G < 100)
                        {
                            SchwarzFlag = true;
                            if (y < minY) minY = y;
                            if (y > maxY) maxY = y;
                            if (x < minX) minX = x;
                            inBuchstabe = true;
                        }
                    }
                    else
                    {
                        // weiße schrift auf schwarzem grund
                        if (c.B > 100 && c.R > 100 & c.G > 100)
                        {
                            SchwarzFlag = true;
                            if (y < minY) minY = y;
                            if (y > maxY) maxY = y;
                            if (x < minX) minX = x;
                            inBuchstabe = true;
                        }

                    }

                }
                if ((SchwarzFlag == false) && (inBuchstabe == true))
                {
                    // erste leere Reihe hinter einem Buchstaben gefunden
                    string text = "Phase 1: x:" + minX.ToString() + "-" + x.ToString() + " y:" + minY.ToString() + "-" + maxY.ToString() + "\n";
                    //AddToProtokoll(text);

                    string Zeichen = AnalyseNPC_Name_Phase2(Mode, bild, minX, minY, x, maxY);
                    erg += Zeichen;

                    if (Zeichen == "?")
                        UngueltigeZeichenFaktor -= 1;
                    else
                        UngueltigeZeichenFaktor += 1;



                    // alles wieder auf Anfang
                    minX = 9999; minY = 9999; maxY = -1; inBuchstabe = false;
                }
            }


            if (UngueltigeZeichenFaktor < 0)    // um zufallstreffer zu vermeiden.
                erg = "";

            // AddToProtokoll(">>>:" + erg + "\n");

            return erg;
        }



        private string AnalyseNPC_Name(int Mode  /* 0 = normaler Text , 1 = xp in % ( sw hintergrund bei ws schrift ) */)
        {
            Bitmap bild=null;
            if (Mode == 0)
            {
                bild = Tools.GetBitmap(BasisX + 743, BasisY + 22, 185, 13);
            }
            else if (Mode == 1)
            {
                bild = Tools.GetBitmap(BasisX + 6, BasisY + 94, 40, 9);
            }

            // MainWindow.mainWindow.pictureBox1.Image = bild;


            string erg = AnalyseNPC_Name_Phase1(Mode, bild);

            return erg;
        }
This is an very easy Bitmap to String Converter.

Function AnalyseNPC_Name_Phase1() is splitting the text into single charaters.

Function AnalyseNPC_Name_Phase2() is converting the bitmap of a single character into a string and stores in a Dictionary.

The LearnMode variable controlls if the code is in bot-mode or in learning Mode.
In LearnMode it will ask the user for unknowen letters with an dialog.

Not in the example is the code for saving the OCR_Table Dictionary and the Dialog that asks the User for a Charater in the case it found something new.
07/11/2009 03:39 meilleur#59
Quote:
Originally Posted by Gertos View Post
maybe it is the best if I post some sample code:

I hope you understand a bit German :)

Code:
        public Dictionary<string, string> OCR_Table;

       public static Bitmap GetBitmap(int x, int y, int dx, int dy)
        {
            Bitmap screenCopy = new Bitmap(dx, dy); 
            using (Graphics gdest = Graphics.FromImage(screenCopy)) 

            using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero)) 
            { 
                IntPtr hSrcDC = gsrc.GetHdc(); 
                IntPtr hDC = gdest.GetHdc(); 
                int retval = BitBlt(hDC, 0, 0, dx, dy, hSrcDC, x, y, (int)CopyPixelOperation.SourceCopy); 

                gdest.ReleaseHdc(); 
                gsrc.ReleaseHdc(); 
            }

            return screenCopy;

        }

        private string AnalyseNPC_Name_Phase2(int Mode, Bitmap bild, int x, int y, int x2, int y2)
        {
            // Bild abmalen und ins log schreiben 

            string Zeile = "";


            for (int yy = y; yy <= y2; yy++)
            {
                for (int xx = x; xx <= x2; xx++)
                {
                    Color c = bild.GetPixel(xx, yy);

                    if (Mode == 0)
                    {
                        if (c.B < 80 && c.R < 80 & c.G < 80)
                            Zeile += "X";
                        else if (c.B < 100 && c.R < 100 & c.G < 100)
                            Zeile += "x";
                        else if (c.B < 120 && c.R < 120 & c.G < 120)
                            Zeile += "+";
                        else if (c.B < 140 && c.R < 140 & c.G < 140)
                            Zeile += ".";
                        else
                            Zeile += "_";
                    }
                    else
                    {
                        if (c.B > 100 && c.R > 100 & c.G > 100)
                            Zeile += "X";
                        else
                            Zeile += "_";

                    }

                }
                Zeile += "\n";
            }
            //AddToProtokoll(Zeile);

            // 
            string Buchstabe;
            if (OCR_Table.TryGetValue(Zeile, out Buchstabe) == false)
            {
                if (LearnMode == true)
                {
                    // Dialog anzeigen
                    OCR_Ask_for_Letter dlg = new OCR_Ask_for_Letter();
                    dlg.richTextBox1.AppendText(Zeile);
                    dlg.ShowDialog();
                    Buchstabe = dlg.textBox1.Text;

                    if (Buchstabe.Length > 0)
                    {
                        OCR_Table.Add(Zeile, Buchstabe);
                    }
                }
                else
                    Buchstabe = "?";
            }

            return Buchstabe;
        }


        private string AnalyseNPC_Name_Phase1(int Mode, Bitmap bild)
        {
            // 1. Bild in Buchstaben trennen
            string erg = "";
            bool inBuchstabe = false;
            int minX = 9999;
            int minY = 9999;
            int maxY = -1;

            int UngueltigeZeichenFaktor = 0;

            for (int x = 0; x < bild.Width; x++)
            {
                bool SchwarzFlag = false;
                for (int y = 0; y < bild.Height; y++)
                {
                    // stehen in der aktuellen Row Daten ?
                    Color c = bild.GetPixel(x, y);

                    if (Mode == 0)
                    {
                        // Schwarze Schrift auf grauem grund
                        if (c.B < 100 && c.R < 100 & c.G < 100)
                        {
                            SchwarzFlag = true;
                            if (y < minY) minY = y;
                            if (y > maxY) maxY = y;
                            if (x < minX) minX = x;
                            inBuchstabe = true;
                        }
                    }
                    else
                    {
                        // weiße schrift auf schwarzem grund
                        if (c.B > 100 && c.R > 100 & c.G > 100)
                        {
                            SchwarzFlag = true;
                            if (y < minY) minY = y;
                            if (y > maxY) maxY = y;
                            if (x < minX) minX = x;
                            inBuchstabe = true;
                        }

                    }

                }
                if ((SchwarzFlag == false) && (inBuchstabe == true))
                {
                    // erste leere Reihe hinter einem Buchstaben gefunden
                    string text = "Phase 1: x:" + minX.ToString() + "-" + x.ToString() + " y:" + minY.ToString() + "-" + maxY.ToString() + "\n";
                    //AddToProtokoll(text);

                    string Zeichen = AnalyseNPC_Name_Phase2(Mode, bild, minX, minY, x, maxY);
                    erg += Zeichen;

                    if (Zeichen == "?")
                        UngueltigeZeichenFaktor -= 1;
                    else
                        UngueltigeZeichenFaktor += 1;



                    // alles wieder auf Anfang
                    minX = 9999; minY = 9999; maxY = -1; inBuchstabe = false;
                }
            }


            if (UngueltigeZeichenFaktor < 0)    // um zufallstreffer zu vermeiden.
                erg = "";

            // AddToProtokoll(">>>:" + erg + "\n");

            return erg;
        }



        private string AnalyseNPC_Name(int Mode  /* 0 = normaler Text , 1 = xp in % ( sw hintergrund bei ws schrift ) */)
        {
            Bitmap bild=null;
            if (Mode == 0)
            {
                bild = Tools.GetBitmap(BasisX + 743, BasisY + 22, 185, 13);
            }
            else if (Mode == 1)
            {
                bild = Tools.GetBitmap(BasisX + 6, BasisY + 94, 40, 9);
            }

            // MainWindow.mainWindow.pictureBox1.Image = bild;


            string erg = AnalyseNPC_Name_Phase1(Mode, bild);

            return erg;
        }
This is an very easy Bitmap to String Converter.

Function AnalyseNPC_Name_Phase1() is splitting the text into single charaters.

Function AnalyseNPC_Name_Phase2() is converting the bitmap of a single character into a string and stores in a Dictionary.

The LearnMode variable controlls if the code is in bot-mode or in learning Mode.
In LearnMode it will ask the user for unknowen letters with an dialog.

Not in the example is the code for saving the OCR_Table Dictionary and the Dialog that asks the User for a Charater in the case it found something new.
Merci Gretos. I fear that the problem it is not with german as I can use translator :p but with c# I have to understand it and translate it to vb6 and I think I have just have to learn another langage a modern one, I discovred the image treatment domain in programmation and i loved it especially OCR
07/12/2009 23:22 meilleur#60
I started programming c# with mono (.net compiler) in ubuntu (Linux distribution), if I want to export my project in MV2008(or inverse) will I have problem with compatibility?