Pixel Bot - Image Detection with confidence value?!

10/12/2021 13:16 saixo#1
Greetings, i am currently working on a free fishing bot for new world.

It's my first ever pixel/image detecting bot. I am currently using [Only registered and activated users can see links. Click Here To Register...] to detect for images inside another image(screen area).

However, this only works if colors match perfectly, no clue what exactly the "exact match" bool changes, i did not notices anything, but i think thats more about image sizes.

For python, i've seen [Only registered and activated users can see links. Click Here To Register...] which allows you to search with a confidence value, so it would still detect similar matches.

My question is: Is there some good library like PyAutoGui for C# as well? I'd like to stick to C#, but i cannot find something for my needs & i am not that advanced that i could write it myself.

I've tried to convert the images to 1 bit images so they are only black and white, but still, then for some color variations, it will convert other pixels to Black/White than on the source image, which makes it mismatch again.

Thanks for any help in advance. Have a great day!


//EDIT:
I found [Only registered and activated users can see links. Click Here To Register...] but this would kinda force me to save the images somewhere, i'd like to use the image from Properties.Resources instead. Any way to accomplish it with this?
10/25/2021 04:10 Vitokonuk#2
Hello sir. I have my own fishing bot and i selling on epvp. You can see it from here: [Only registered and activated users can see links. Click Here To Register...]

I can say C# is very bad and slow for image processing technology. You should use Python with PyAutoGui library. It's very good :)
10/25/2021 22:26 saixo#3
Quote:
Originally Posted by Vitokonuk View Post
Hello sir. I have my own fishing bot and i selling on epvp. You can see it from here: [Only registered and activated users can see links. Click Here To Register...]

I can say C# is very bad and slow for image processing technology. You should use Python with PyAutoGui library. It's very good :)
ah no already got it working, just using imagesearchdll.dll from autoit, works pretty well
10/27/2021 04:50 tehpwnerer69#4
Quote:
Originally Posted by saixo View Post
ah no already got it working, just using imagesearchdll.dll from autoit, works pretty well
If you are looking for a native solution, I can tell you how to do this without external libraries.
10/27/2021 21:12 Xemus™#5
Quote:
Originally Posted by tehpwnerer69 View Post
If you are looking for a native solution, I can tell you how to do this without external libraries.
Would be interested.
Currently writing a bot for personal use.
10/28/2021 03:04 tehpwnerer69#6
Quote:
Originally Posted by Xemus™ View Post
Would be interested.
Currently writing a bot for personal use.
Hit me up with a PM

I'll give you the run down
11/01/2021 11:56 killzone#7
Quote:
Originally Posted by saixo View Post
Greetings, i am currently working on a free fishing bot for new world.

It's my first ever pixel/image detecting bot. I am currently using [Only registered and activated users can see links. Click Here To Register...] to detect for images inside another image(screen area).

However, this only works if colors match perfectly, no clue what exactly the "exact match" bool changes, i did not notices anything, but i think thats more about image sizes.

For python, i've seen [Only registered and activated users can see links. Click Here To Register...] which allows you to search with a confidence value, so it would still detect similar matches.

My question is: Is there some good library like PyAutoGui for C# as well? I'd like to stick to C#, but i cannot find something for my needs & i am not that advanced that i could write it myself.

I've tried to convert the images to 1 bit images so they are only black and white, but still, then for some color variations, it will convert other pixels to Black/White than on the source image, which makes it mismatch again.

Thanks for any help in advance. Have a great day!


//EDIT:
I found [Only registered and activated users can see links. Click Here To Register...] but this would kinda force me to save the images somewhere, i'd like to use the image from Properties.Resources instead. Any way to accomplish it with this?
This is the easiest way to implement it.
Less codes and stuff.
[Only registered and activated users can see links. Click Here To Register...]
12/21/2022 20:48 EasyBotMaker#8
Code:
public static Rectangle SearchBitmap(Bitmap bitmap1, Bitmap bitmap2, double tolerance)
        {

            if (bitmap1.Width > bitmap2.Width || bitmap1.Height > bitmap2.Height)
            {
                Bitmap aux = bitmap2;
                bitmap2 = bitmap1;
                bitmap1 = aux;
            }

            if (bitmap1.Height > bitmap2.Height)
            {
                return Rectangle.Empty;
            }

            return SearchBitmapStepTwo(bitmap1, bitmap2, tolerance);

        }

private static Rectangle SearchBitmapStepTwo(Bitmap smallBmp, Bitmap bigBmp, double tolerance)
        {
            BitmapData smallData =
                smallBmp.LockBits(new Rectangle(0, 0, smallBmp.Width, smallBmp.Height),
                       System.Drawing.Imaging.ImageLockMode.ReadOnly,
                       System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            BitmapData bigData =
              bigBmp.LockBits(new Rectangle(0, 0, bigBmp.Width, bigBmp.Height),
                       System.Drawing.Imaging.ImageLockMode.ReadOnly,
                       System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            int smallStride = smallData.Stride;
            int bigStride = bigData.Stride;

            int bigWidth = bigBmp.Width;
            int bigHeight = bigBmp.Height - smallBmp.Height + 1;
            int smallWidth = smallBmp.Width * 3;
            int smallHeight = smallBmp.Height;

            Rectangle location = Rectangle.Empty;
            int margin = Convert.ToInt32(255.0 * tolerance);

            unsafe
            {
                byte* pSmall = (byte*)(void*)smallData.Scan0;
                byte* pBig = (byte*)(void*)bigData.Scan0;

                int smallOffset = smallStride - smallBmp.Width * 3;
                int bigOffset = bigStride - bigBmp.Width * 3;

                bool matchFound = true;

                for (int y = 0; y < bigHeight; y++)
                {
                    for (int x = 0; x < bigWidth; x++)
                    {
                        byte* pBigBackup = pBig;
                        byte* pSmallBackup = pSmall;

                        //Look for the small picture.
                        for (int i = 0; i < smallHeight; i++)
                        {
                            int j = 0;
                            matchFound = true;
                            for (j = 0; j < smallWidth; j++)
                            {
                                //With tolerance: pSmall value should be between margins.
                                int inf = pBig[0] - margin;
                                int sup = pBig[0] + margin;

                                if (sup < pSmall[0] || inf > pSmall[0])
                                {
                                    matchFound = false;
                                    break;
                                }

                                pBig++;
                                pSmall++;

                            }

                            if (!matchFound) break;

                            //We restore the pointers.
                            pSmall = pSmallBackup;
                            pBig = pBigBackup;

                            //Next rows of the small and big pictures.
                            pSmall += smallStride * (1 + i);
                            pBig += bigStride * (1 + i);
                        }

                        //If match found, we return.
                        if (matchFound)
                        {
                            location.X = x;
                            location.Y = y;
                            location.Width = smallBmp.Width;
                            location.Height = smallBmp.Height;
                            break;
                        }
                        //If no match found, we restore the pointers and continue.
                        else
                        {
                            pBig = pBigBackup;
                            pSmall = pSmallBackup;
                            pBig += 3;
                        }
                    }

                    if (matchFound) break;

                    pBig += bigOffset;
                }
            }

            if (bigData != null)
                bigBmp.UnlockBits(bigData);
            if (smallData != null)
                smallBmp.UnlockBits(smallData);


            return location;
        }
Use this you can ad an tolerance.