Thread: Comparing 2 pictures.

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    110

    Comparing 2 pictures.

    Ok the end result of this program is it will take a pic of whatever is ontop in windows mode and compare them with a picture I have to see if they are the same.


    My questions are:

    How do I take a screenshot of whatever is ontop in windows mode?

    How would you recomend comparing 2 pictures to see if they resemble eachother?


    Thankyou.

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Coder87C
    How would you recomend comparing 2 pictures to see if they resemble eachother?
    Just check that they are the same dimensions then compare them pixel by pixel.
    Code:
    bool operator==(const Image& image1, const Image& image2)
    {
    if (image1.width != image2.width)
      return false;
    if (image1.height != image2.height)
      return false;
    
    for x = 0 ... image1.width
      for y = 0...image1.height
        if (image1[x][y] != image2[x][y])
         return false;
    return true;
    }
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    That would tell you if the pictures match each other. I believe he is looking for an algorithm that will tell if the two pictures resemble, or are close to, each other (i.e. having some of the same features). There are many algorithms available for this kind of use, just do a search for "Image Processing" and you should find the topic fairly easily.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    Yeah I put a ticker in that loop and if it was around 50% of actual picture I allowed it.


    My last problem is getting the screenshot of the window.

    Here is the code I found which I slitely modified.

    Code:
    PAINTSTRUCT ps;	
    HDC hdc=BeginPaint(hwnd,&ps);
    HWND hWowWnd = FindWindow("World of Warcraft",NULL);
    HDC hWowDC = GetDC(hWowWnd);
    		BitBlt(hdc,0,0,nScreenWidth,nScreenHeight,hWowDC,0,0,SRCCOPY);
    So First I set the handle of the window to the World of Warcraft handle by using our friendly FindWindow function.

    Then I create a compatibleDC from it...

    then it bitblits the Wow DC

    Now it should just take a screenshot of the Wow window and then blit it in my window, but for some reason it only copys whatever is ontop of the desktop?

    Anyone know?

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    I been doing this all wrong from the begining and working in real time, I still need the screenshot so if anyone knows!!

    I was basing my prog off a Aimbot, which is tottaly wrong, it just searchs for stuff in the picture when I hit a key....

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    1. Hit PrintScreen.
    2. Load up your favorite paint program.
    3. Edit->Paste or Edit->Paste as new image.

    Windows traps the Print screen key and allows you to do quick and dirty screen captures. The downside is that it only allows one image on the clipboard. Hitting print screen multiple times only overwrites the previous image.

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    110
    Yeah, but how do u tell ur program to do that?

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I bet FindWindow is returning NULL which would give you the desktop DC. You might want to check what parameters the FindWindow function takes. I believe you have them reversed, it is classname first then windowname.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Just in case anyone is interested, there is an article here aboud finding similar pictures: http://www.generation5.org/content/2004/aiSomPic.asp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with comparing strings!
    By adrian2009 in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 10:44 PM
  2. Tagging Pictures
    By Tonto in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-17-2008, 02:44 PM
  3. pictures
    By TravisS in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 01-06-2003, 02:31 PM
  4. comparing problem
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 03-05-2002, 06:19 AM
  5. comparing struct members
    By breed in forum C Programming
    Replies: 4
    Last Post: 11-22-2001, 12:27 PM