lemming Posted January 6, 2006 Report Share Posted January 6, 2006 Hi all, and happy new year. Here's my proof-of-concept routine for a rudimentary image search in Macex. It consists of two macros: 1) Acquire Search Pixels macro 2) Search For Pixels macro Acquire Search Pixels will define the line of pixels to search for. The default script acquires 25 pixels to the right of the current cursor position. It then saves the data to a text file (Default is C:\PixelSaveFile25.txt). The Search For Pixels macro will figure out the size of the current window, and set up a search grid for the right half only. It then "reads" the grid line by line, starting at the top, to search for the 25 pixels defined earlier. If it finds the pattern, it will beep and move the mouse cursor to the start (i.e. the left) of the pattern. Note: Acquire Search Pixels only works with real cursors, i.e. thr pointing arrow and not the "I" cursor found in word processors. QUICK START 1) Download or copy the two macros from here. Use the "Src for pixels in right-hand window" one instead of "Src for pixels in current window". 2) Define hotkeys for the macros. 3) We will test the macro on this webpage. Yes, this very page. We'll be searching for a button on this page. You can choose any of the buttons typically found in this forum - "Add Reply", "New Topic", "New Poll", "Quote", etc. Basically any button on the right of the window which is quite colorful or unique. 4) First we will acquire a search pattern. Just place the cursor on any button you like, but keep it near the left edge of the button - the script samples 25 pixels to the right of the cursor. Just hit the hotkey for Acquire Search Pixels, and the script should pop up a window titled "Pixels acquired" with some info. 5) To prove that the search really works, just move, resize, or scroll around in the window. This will move the position of the button. I recommend making the window smaller so that the search will be faster, but also make sure the button is still on the right side. 6) Now hit the hotkey for Search For Pixels, and if all goes well, the button will be found in a few seconds. You'll hear a beep and the cursor will be moved to the button (to the left of it, just like when you acquired pixels). To create these scripts, I had to work around some major shortcomings in the Macex script language, namely: 1) it lacks Arrays 2) it has a maximum no. of 99 variables, 3) and it is a strongly-typed language. I also wanted to create a script without dynamic execution (e.g. "Run Macro in Variable") and without any add-ons (sorry, Joe and company) or other external programs. The search does not have to be limited to the right-hand side. In fact, I've also included the macro for a full-window search. The search is currently quite slow, up to 6 seconds for a 360 x 300 grid on a P4 2.8GHz PC. The bigger the search area, the slower it takes. But this is version 1.0, so I hope to speed it up later. Would appreciate any ideas for improvements. -Lemming image_search.mex Quote Link to comment Share on other sites More sharing options...
fredk Posted January 7, 2006 Report Share Posted January 7, 2006 Hey, quite remarkable although, as you said, it is a tad bit slow, especially on the entire window search. Thanks for sharing. I guess now that there may be a tool to find 'buttons' I may need to learn how to actually PRESS the darn button using MacroExpress. Quote Link to comment Share on other sites More sharing options...
lemming Posted January 9, 2006 Author Report Share Posted January 9, 2006 Hey, quite remarkable although, as you said, it is a tad bit slow, especially on the entire window search. Thanks for sharing. I guess now that there may be a tool to find 'buttons' I may need to learn how to actually PRESS the darn button using MacroExpress. Yea, as I posted earlier, you should try to limit the search area to make it faster. You could make changes to the search area listed in the script, or perhaps you could add code to resize the window which you will be searching in. Macex already has a Resize Windows command. But in most cases, you don't even have to search the entire window. A common assumption by users is that their search object can appear "anywhere" on screen, when in fact, it is almost always confined to a certain region of the screen, for instance, the top right-hand quadrant, or somewhere along the middle portion of the screen. As for pressing the button, just use Mouse Command -> Left Button Click. My script already positions the mouse cursor on the button, if it is found. Lemming Quote Link to comment Share on other sites More sharing options...
kevin Posted January 9, 2006 Report Share Posted January 9, 2006 Have you tried to set the Macro Priority to speed up the macros? To try this, download tweakme3.mxe from www.macros.com/downmore.htm and save it on your hard drive. Then either double-click on it or import it into your existing macro file. When you run it, choose a value of -1. This will turn off the Macro Priority feature giving full priority to macros. Quote Link to comment Share on other sites More sharing options...
ol3ears Posted January 10, 2006 Report Share Posted January 10, 2006 "The search is currently quite slow, up to 6 seconds for a 360 x 300 grid on a P4 2.8GHz PC. The bigger the search area, the slower it takes. But this is version 1.0, so I hope to speed it up later." Search for the 'most unique' pixels first. IE those pixels unique in colour or relative geometry. This will allow you to do a quick high level scan before committing yourself to a slow grid scan. Quote Link to comment Share on other sites More sharing options...
lemming Posted January 10, 2006 Author Report Share Posted January 10, 2006 ...Search for the 'most unique' pixels first. IE those pixels unique in colour or relative geometry. This will allow you to do a quick high level scan before committing yourself to a slow grid scan. I've conducted some experiments with separate parts of the script, and have discovered the search itself is pretty fast - it usually finishes in less than a second. The slow part is actually the line reading. For every pixel in the search grid, my script will: 1. Get pixel color (an integer) 2. Convert integer to string 3. Append string to another variable (serves as an array for the line) Repeat that step thousands, or tens of thousands of times, and you can see why it is slow. For searching I just make use of Macex's "Get Position of Text in a Text Variable" command, which in effect, is a search command. Since it is built-in, it works pretty fast. The number of search pixels and size of the search grid do not seem to affect the search time - if the lines have been read first. So what I really need now is a faster way to "read" the lines in a search grid. Unfortunately, the "most unique pixels first" approach would not work fo me in this case. Lemming. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.