Thread: How to recognize an image on the screen

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    How do you intend to get "a print from the screen"?

    This is NOT a trivial or easy task. Easily a thousand lines of code methinks. Probably more. If you have no idea of even where to start, better believe this is going to take you a long time.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #17
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by MK27 View Post
    How do you intend to get "a print from the screen"?

    This is NOT a trivial or easy task. Easily a thousand lines of code methinks. Probably more. If you have no idea of even where to start, better believe this is going to take you a long time.
    Not hard if the game isn't hardware accelerated. If it is, then yes it's very hard.

    Otherwise you can just call GetDC() on the appropriate window (or the whole screen).

  3. #18
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    Thanks for helping zacs. I've used GetDC before to draw on the screen, but I don't really know how to use it to generate a "print screen". Could you recommend me something to read or something like that?

  4. #19
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Will the car always be the same size/shapy/color? how about showing the car from the same angle? What about ambient background "noise"?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #20
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Sorry, I did not mean it would be a thousand lines to do a screen grab, I meant it would be 1000+ plus to complete the project, and that the first thing you need to be thinking about is the screen grab.

    I don't want to discourage anyone, lala123, I just wanted to make sure you understand that GetDC() or no GetDC(), this is going to be a lot of work.

    Vis. the details, zacs7 provided a link:
    GetDC Function (Windows)
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #21
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    There's no noise and the image will never change (no change in shape, color, etc). What might happen is a smal part of the image (probably a little around the edges) being overlapped by another image. Also the image is not moving, wich should make things easier.

  7. #22
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by lala123 View Post
    There's no noise and the image will never change (no change in shape, color, etc). What might happen is a smal part of the image (probably a little around the edges) being overlapped by another image. Also the image is not moving, wich should make things easier.
    If it's going to be the same colour... you could just find the first pixel of that colour and determine it's size. If it's too small, find another pixel, if it's too big, find another. Sure it's a naive approach, but it would work (although how fast depends on your hardware).

  8. #23
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    I see, but there could other items of that same color I guess. If I could place the screen in a 1024x768 matrix, with 1 space for each pixel I guess it would be a much simpler problem, wouldn't it?

  9. #24
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You are now getting ahead of yourself because you still do not understand what form the data from the screen grab will be in.

    The first thing you need to actually do is the screen grab, and then you will know what form that data is in (eg, it could be "a 1024x768 matrix, with 1 space for each pixel", but I doubt it). You probably won't need to change the form to anything else, you just have to understand what it is (most likely: an array of rows of pixel data -- so yes a matrix -- 3-4 bytes per pixel, interleaved, like a bitmap).

    Until you've done that you're just idling speculating about what maybe might be possible, what in theory I could do if my other abstract idea is correct, etc, but you haven't written any code so most of that is pure pie in the sky and may or may not have anything to do with what is really necessary.
    Last edited by MK27; 02-15-2010 at 10:12 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  10. #25
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    MK27

    Well if I knew how to do it I probably wouldn't be asking for help. I'll start coding when I have something to start with. I guess you are right about me being too much spoiled and wanting everything handed to me. But I'm searching for an answer as we speak and haven't found any.

    I believe that this will be the hardest part of the program, once I have the screen I'll need to create an "imgcmp" routine to find where the click spots are.

  11. #26
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by lala123 View Post
    I believe that this will be the hardest part of the program, once I have the screen I'll need to create an "imgcmp" routine to find where the click spots are.
    Look I'm not trying to be mean, I'm trying to help you get where you are going.

    What I am trying to tell you is: maybe that is the hardest part of the program, but in any case, you have not attempted to do any part of the program yet and there is no point contemplating what is going to happen, or asking for any help, until you at least attempt something.

    "once I have the screen" -- you don't! Stop there. Do not pass GO. Do not collect anything until you have the screen. Then you can start thinking about what you are going to do with it, depending on what "it" turns out to be. Do you see how ridiculously abstract it is for you to say "If I could place the screen in a 1024x768 matrix, with 1 space for each pixel"? What screen are you talking about? The screen is data. Do you know what kind of data? Will that kind of data fit meaningfully into such a matrix? Where is this data that you are going to do all this fancy stuff with? Do you have any such data yet?

    Remember, I'm not being mean, I'm trying to orient your mind to the concrete specifics of the task.

    So zacs7 gave you an idea of how to do this and provided a link to some documentation. Have you looked at that documentation yet? Do you know whether this command will work for you? Have you tried to make it work?

    You need to do a screen grab. You are wasting your time thinking about what you will do with data that you do not have -- you don't even have any idea what that data will look like -- instead of thinking about how to actually get the data and understand it.

    Now smile and be happy
    Last edited by MK27; 02-15-2010 at 12:10 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #27
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    Hehehe I understand what you're saying. Will try coding something now.

  13. #28
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    Alright, so after some searching I believe I might have made some progress. The thing is, I'm pretty clueless about the gdi so I can't really tell if this works or not.

    It's hard doing such thing when you barely know what a bitmap is hehehe... I found some programs and answers on the net and tried to adapt them to my need.

    Code:
        hwndDesktop = GetDesktopWindow ();
        hdcSource = GetWindowDC (hwndDesktop);
    
        hdcDestination = CreateCompatibleDC(hdcSource);
        bitmap = CreateCompatibleBitmap(hdcDestination, 1280, 800); // change to find window size
        objSelect = SelectObject(hdcDestination, bitmap);
    
        BitBlt(hdcDestination, 0, 0, 1280, 800, hdcSource, 0,0, SRCCOPY);
        SelectObject (hdcDestination, objSelect);
    
        DeleteDC(hdcDestination);
        DeleteObject(bitmap);
    If everything goes well, "bitmap" should hold the screen shot.

  14. #29
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    I see now that I should have posted this topic in the windows programming section, sorry for that.

  15. #30
    the magic penguim
    Join Date
    Jul 2005
    Posts
    91
    Will that code work?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Render text
    By Livijn in forum C++ Programming
    Replies: 6
    Last Post: 07-06-2007, 03:32 PM
  3. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  5. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM