Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases > Coding Snippets
You last visited: Today at 01:28

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#] Image Search Code

Discussion on [C#] Image Search Code within the Coding Snippets forum part of the Coding Releases category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Mar 2009
Posts: 1
Received Thanks: 4
[C#] Image Search Code

I want to share this code used to find an image within another.
Made it hotnoob watching videos and researching the method that uses "LockBits".

Here is the code:
PHP Code:
private struct PixelData
        
{
            public 
byte red;
            public 
byte green;
            public 
byte blue;
            public 
byte alpha;
            
        }


        
/// <summary>
        /// Se utiliza para obtener las coordenadas de una imagen dentro de otra. Devuelve el resultado en formato "Point"
        /// </summary>
        /// <param name="Fondo">Imagen base donde se encuentra la que se va a buscar</param>
        /// <param name="Imagen">Imagen que se desea buscar</param>
        /// <param name="Var">Cantidad permitida de variacion de pixeles, mientras menor sea menos sensible será el algoritmo</param>
        /// <returns>Point</returns>
        
public unsafe Point Busqueda(Bitmap FondoBitmap Imagenint Var)
        {

            
bool Encontrado false;
            
int Xinterno 0;
            
int Yinterno 0;
            
BitmapData FondoLock Fondo.LockBits(new Rectangle(00Fondo.WidthFondo.Height), ImageLockMode.ReadOnlyPixelFormat.Format32bppRgb);
            
BitmapData ImagenLock Imagen.LockBits(new Rectangle(00Imagen.WidthImagen.Height), ImageLockMode.ReadOnlyPixelFormat.Format32bppRgb);

            
PixelDataFondoP = (PixelData*)FondoLock.Scan0.ToPointer();
            
PixelDataImagenP = (PixelData*)ImagenLock.Scan0.ToPointer();

            for (
int Y 0< (FondoLock.Height ImagenLock.Height); Y++)
            {
                for (
int X 0< (FondoLock.Width ImagenLock.Width); X++)
                {
                    
PixelDataRFondo = (PixelData*)(FondoP Fondo.Width X);
                    
PixelDataRImagen = (PixelData*)(ImagenP);

                    if ((
Math.Abs(RFondo->red RImagen->red) <= Var) && (Math.Abs(RFondo->blue RImagen->blue) <= Var) && (Math.Abs(RFondo->green RImagen->green) <= Var))
                    {
                        
Encontrado true;
                        for (
Yinterno 0Yinterno < (ImagenLock.Height); Yinterno++)
                        {
                            for (
Xinterno 0Xinterno < (ImagenLock.Width); Xinterno++)
                            {
                                
PixelDataMFondo = (PixelData*)(RFondo Yinterno FondoLock.Width Xinterno);
                                
PixelDataMImagen = (PixelData*)(RImagen Yinterno ImagenLock.Width Xinterno);

                                if ((
Math.Abs(MFondo->red MImagen->red) > Var) || (Math.Abs(MFondo->blue MImagen->blue) > Var) || (Math.Abs(MFondo->green MImagen->green) > Var))
                                {
                                    
Encontrado false;
                                }
                            }
                        }
                        if (
Encontrado == true)
                        {
                            
Fondo.UnlockBits(FondoLock);
                            
Imagen.UnlockBits(ImagenLock);
                            return new 
Point((+ (Xinterno 2)), (+ (Yinterno 2)));
                        }
                    }

                }
            }
            
Fondo.UnlockBits(FondoLock);
            
Imagen.UnlockBits(ImagenLock);
            return new 
Point();
        } 
GonzaFz is offline  
Thanks
4 Users
Old 02/03/2014, 19:28   #2
 
[uLow]NTX?!'s Avatar
 
elite*gold: 0
Join Date: May 2013
Posts: 1,266
Received Thanks: 627
Nice that you Share your code, but you can Posts Code Snippets here:


#moverequest
[uLow]NTX?! is offline  
Thanks
1 User
Old 02/19/2014, 01:18   #3


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Arrow .NET Languages -> Coding Snippets

#moved
MrSm!th is offline  
Reply


Similar Threads Similar Threads
search pixel on image.bmp
09/04/2013 - AutoIt - 8 Replies
I need to know a metod or a simple function/UDF wich i can do a pixelsearch on an image that is in the same folder of the script. How can i do this?
How do i use image search using Auotit?
06/14/2013 - AutoIt - 2 Replies
Basically what i wanna do is this video. Autoit ImageSearch - YouTube Thanks.:handsdown::handsdown::handsdown: I wanna find any image on my screen no matter where it is and click it.The link given there is now working. I use windows 7 64 bit. any help please?
Image search
05/23/2013 - AutoIt - 1 Replies
Wie binde ich bilder in meine exe ein? Ich möchte nämlich nur die exe haben und sie verschicken können, ohne, dass ich die bilder immer beilegen muss. LG Tom
Image search API
11/28/2012 - Web Development - 2 Replies
Heyho, ich wollte mal nachfragen ob wer von euch Dienste / API's kennt womit man Bilder suchen kann? Am besten gratis. Yahoo API - Gibt es nicht mehr Google API - Wird bald mal geschlossen, die neue kostet ab 100 Anfragen Geld Flickr API - Geht zwar, aber die Resultate lassen eher zu wünschen übrig Instagram API - Geht, aber man kann nur nach einen Tag ohne Leerzeichen etc. suchen Pinterest hat z.Z. keine API mehr
Image Search Problem
06/23/2010 - AutoIt - 9 Replies
Heyy ich bin gerade dabei einen Bot zu Schreiben, leider habe ich ein Problem mit Image Search ... irgendwie checke ich das nicht so :( Ich habe vor dass wenn man Start klickt dass der Bot nach einem Bild sucht und dann mit der Maus dorthin geht und ein Linksklick macht. Hier mal der Source Code von mein Bot: #include <GUIConstants.au3> Global $INTERVALL



All times are GMT +1. The time now is 01:29.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.