• Visual screen scraping (C#)

    Home » Forums » Developers, developers, developers » DevOps Lounge » Visual screen scraping (C#)

    Author
    Topic
    #401209

    Here’s what I’d like to do: I’d like to program a something(in C#) that will accept an image as a parameter and will ‘scan’ a window for the image. It would then reply something like: “Image found at position 836,224!”.

    I’ve Googled on this subject, but almost all results talked about screen scraping in DotNet, which means that you can fetch the content of some html page and use it for your own purposes (for example to include weather info on your own homepage). I don’t want to get text and I don’t want to use html or browsers, I want to try and find an image on a specific window in my local machine (without Internet connection).

    Any help, hint or tip would be greatly appreciated.

    __________________________________________________

    Viewing 1 reply thread
    Author
    Replies
    • #788820

      What do you mean by “‘scan’ a window for the image”? Do you mean an image file? Or are you trying to compare pixels of an input image with pixels of a base image to see if the input image is contained in the base image?

      Can you give some examples?
      shrug

      • #788832

        What I mean is indeed comparing pixels of an input image with pixels of a base image. If, for example, I’m playing chess on my computer, I’d like to compare the image of a black pawn with the chessboard on my screen (the base image) and determine where all the black pawns are. Then I can let my PC do some calculations and give me an advice for my move. Of course the position of the pawns is not nearly enough to determine my best move, but as an example I hope you get what I mean.

        This is the idea. Any suggestions on how to obtain the pixels of the game-window and compare them with the image of, for example, a pawn?

        • #788842

          Not to get off-topic here, but if your goal for this process is related to chess then there are MUCH easier ways to perform chess-related calculations than trying to do this with graphics.

          I’m not terribly well-versed with .NET’s GDI+ programming, but I imagine that comparing graphics would be fairly processor-intensive. For instance, I imagine it would have to search on a pixel-by-pixel basis for each pixel of the input image and each pixel of the base image. If pixel 1×1 of the input image matches any pixel of the base image, examine pixel 1×2 of the input image against the next pixel of the base image, etc…. It could be much more trouble than it’s worth.

          Also, something else to consider is that the two images would have to be an exact match – pixel for pixel. It’s not likely that any screenshot would be so precise as to have pixel-for-pixel matching against a control (input image).

          That’s just my 2 cents 2cents

          • #788856

            MarkJ, thank you for your response.

            I’m afraid I don’t completely agree with you. First of all I would do it like this: Compare pixel 1×1 with every pixel of the base image. If they match, cut out a piece of the base image with the exact dimensions of the image you’re looking for and compare these two in one comparison (not pixel by pixel). If they match, good, if not then continue. Yes, the images would have to be an exact match. For my purposes the screenshots are precise enough for me to accept this programming challenge.

            So could you (or anyone else) help me get started here?

          • #788857

            MarkJ, thank you for your response.

            I’m afraid I don’t completely agree with you. First of all I would do it like this: Compare pixel 1×1 with every pixel of the base image. If they match, cut out a piece of the base image with the exact dimensions of the image you’re looking for and compare these two in one comparison (not pixel by pixel). If they match, good, if not then continue. Yes, the images would have to be an exact match. For my purposes the screenshots are precise enough for me to accept this programming challenge.

            So could you (or anyone else) help me get started here?

            • #788878

              You might try a Google search on .NET GDI+

              Here’s a site I’ve used on occasion: GDI+ FAQ

              Hope this helps – good luck!

            • #788953

              MarkJ, thank you very much! I’ve just peeked at the site and it seems an excellent starting place for my challenge.

            • #788954

              MarkJ, thank you very much! I’ve just peeked at the site and it seems an excellent starting place for my challenge.

            • #788879

              You might try a Google search on .NET GDI+

              Here’s a site I’ve used on occasion: GDI+ FAQ

              Hope this helps – good luck!

        • #788843

          Not to get off-topic here, but if your goal for this process is related to chess then there are MUCH easier ways to perform chess-related calculations than trying to do this with graphics.

          I’m not terribly well-versed with .NET’s GDI+ programming, but I imagine that comparing graphics would be fairly processor-intensive. For instance, I imagine it would have to search on a pixel-by-pixel basis for each pixel of the input image and each pixel of the base image. If pixel 1×1 of the input image matches any pixel of the base image, examine pixel 1×2 of the input image against the next pixel of the base image, etc…. It could be much more trouble than it’s worth.

          Also, something else to consider is that the two images would have to be an exact match – pixel for pixel. It’s not likely that any screenshot would be so precise as to have pixel-for-pixel matching against a control (input image).

          That’s just my 2 cents 2cents

      • #788833

        What I mean is indeed comparing pixels of an input image with pixels of a base image. If, for example, I’m playing chess on my computer, I’d like to compare the image of a black pawn with the chessboard on my screen (the base image) and determine where all the black pawns are. Then I can let my PC do some calculations and give me an advice for my move. Of course the position of the pawns is not nearly enough to determine my best move, but as an example I hope you get what I mean.

        This is the idea. Any suggestions on how to obtain the pixels of the game-window and compare them with the image of, for example, a pawn?

    • #788821

      What do you mean by “‘scan’ a window for the image”? Do you mean an image file? Or are you trying to compare pixels of an input image with pixels of a base image to see if the input image is contained in the base image?

      Can you give some examples?
      shrug

    Viewing 1 reply thread
    Reply To: Reply #788879 in Visual screen scraping (C#)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel