On 7/5/06, Peter Valdemar Mørch <[EMAIL PROTECTED]> wrote:
If I have a tiny crop of a part of an image, how would I find out if that crop is present in the larger image, and if so, the (x,y) coordinates in the larger image, where the crop is to be found?
To do this simply, just write a 2-dimensional string search. Search for the first pixel that has the same color as the first pixel in the image you're looking for. Then compare pixels until you either find a match or a pixel doesn't match. If the images don't match, start searching again at the pixel after the first one you found. This may be slow in Perl, unless you dump the image into a Perl array and search it that way. Even then it won't be blazingly fast. To do this quickly in a general purpose way may be a bit of work, but for images with few colors, a 2D variant of Boyer-Moore string searching would be fast and efficient. Here's an example for searching strings: * Let's say you're looking for the string "ABC". You would build a table that would have 0 for A, -1 for B, -2 for C, and 3 for any other letter. When searching a string, you would look up the current letter in your table and skip ahead however many letters it says. That way you would only look at every 3rd letter, backtracking a bit if you find a letter that's a B or C, and searching letter-by-letter only if you hit an A. For an image. basically you would build a table that says for any color in the image you're searching for, what the minimum X and Y distances are to the upper-left. I don't think I have time to write such a thing, but it shouldn't be too hard.
Background: I want to write an app to automate mouse operations in a Windows GUI. I plan to use the perl module Win32::Screenshot that returns an Image::Magick perl object of the desktop and then look for e.g. "the OK button", and then send a mouse click to $screenshot->locationOf($okButtonImage) + (10,10)
If the program you are automating uses standard Windows controls, each button will be a window you can find and send a message to. The only time you would need something like searching screenshots is if you are using a program which draws its own buttons (like a Flash app). GNS _______________________________________________ Magick-users mailing list [email protected] http://studio.imagemagick.org/mailman/listinfo/magick-users
