hhzz Posted March 25, 2010 Posted March 25, 2010 (edited) I'm getting the same error below however I am running 32 bit XP. Anything else that can cause this error? Thanks C:\Program Files\AutoIt3\Include\ImageSearch.au3 (44) : ==> Subscript used with non-Array variable.: if $result[0]="0" then return 0 if $result^ ERROR >Exit code: 1 Time: 0.837 I am also on XP 32 bit. I tried ProgAndy's version on post #63 and had the same problem as you described. I then tried Zedna's version on post #64, then it worked for me. There is some difference on the dll provided. Here is Zedna's post earlier. #746436 Nothing against ProgAndy, but that's what I found. Hope it helps you. Added: Actually neither one's DLL worked for me... I did download one a while ago on a different computer and that does work now I don't remember exactly which link I used to get it, but here it is. ImageSearchDLL.dll Edited March 25, 2010 by hhzz
Ryoni Posted April 18, 2010 Posted April 18, 2010 Sven (From the first page) hasn't been on for ages so I'd like to hear have any of you gotten the code he wrote working? ImageSearch made with transparency detection. As the code says: "$transparency = TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of the color to be used as transparency can be omitted if not needed". But so far after numerous of tries it either doesn't find anything or sometimes when the $transparency is set to 'TRANSWHITE', all searches are seen as correct match even if a single pixel isn't correct. Any kind of tips or even example code is welcome of how the $transparency -paramenter should be used to work correctly.
Ryoni Posted April 19, 2010 Posted April 19, 2010 Sven (From the first page) hasn't been on for ages so I'd like to hear have any of you gotten the code he wrote working? ImageSearch made with transparency detection.As the code says: "$transparency = TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of the color to be used as transparency can be omitted if not needed".But so far after numerous of tries it either doesn't find anything or sometimes when the $transparency is set to 'TRANSWHITE', all searches are seen as correct match even if a single pixel isn't correct.Any kind of tips or even example code is welcome of how the $transparency -paramenter should be used to work correctly.Nevermind.. I got it working but just only with pure black as transparency. I wonder why other colors don't seem to work for me.
Xyzm Posted April 23, 2010 Posted April 23, 2010 (edited) I just couldn't believe that AutoIt doesn't have this functionality, and then I was amazed again by how hard it is to find a working "imagesearch" for autoit. I got it to work, more or less, after over 4 hours of trying a dozen DLL's scattered everywhere as well as a dozen .au3's that needed fixing before they worked. The transparency hasn't worked at all and mostly screws the script (thinks it found the image at starting X/Y of the search area). So... is there really no way? Because I love AutoIt, and I'd hate to learn & switch to AHK just because it has 1 simple function that its big brother lacks... /RANT PS: Here's my code. For the picture that it has to find for I tried any file format expandcollapse popupOpt("MouseCoordMode", 0) Opt("MouseClickDelay", 0) Opt("MouseClickDownDelay", 0) Opt("PixelCoordMode", 0) #include <Misc.au3> #include <ImageSearch.au3> $dll = DllOpen("user32.dll") WinWait("com++ test", "") If Not WinActive("COM++", "") Then WinActivate("COM++", "") WinWaitActive("COM++", "") $xxx = 0 $yyy = 0 ;coordinates to search $left = 300 $top = 300 $right = 1300 $bottom = 800 MouseMove($left, $top) Sleep(25) MouseMove($right, $top) Sleep(25) MouseMove($right, $bottom) Sleep(25) MouseMove($left, $bottom) Sleep(25) $MyTolerance = 20 $hasfound = 0 $hasfound = _ImageSearchArea("C:/OBJ_COM_SMALL.bmp", 0, $left, $top, $right, $bottom, $xxx, $yyy, $MyTolerance, 0xff00ff) If $hasfound = 1 Then MouseMove($xxx, $yyy) Sleep(500) MouseClick("right") Send("1") Sleep(2000) Else While $hasfound = 0 $hasfound = _ImageSearchArea("C:/OBJ_COM_SMALL.bmp", 0, $left, $top, $right, $bottom, $xxx, $yyy, $MyTolerance, 0xff00ff) Sleep(200) If $MyTolerance < 200 Then $MyTolerance += 2 Sleep(200) WEnd MouseMove($xxx, $yyy) Sleep(2000) EndIf Edited April 23, 2010 by Xyzm
Sven Posted May 5, 2010 Posted May 5, 2010 (edited) Nevermind.. I got it working but just only with pure black as transparency. I wonder why other colors don't seem to work for me. Thanks for pointing out this problem, going to look into it. I'm browsing these forums every 4 to 6 weeks, but since it doesn't require to log in in order to read it, I usually don't. Ok, so I ran some tests on my desktop, using part of a desktop icon in different versions, one with a black frame, one with a white one, changed appropriately between "transblack" and "transwhite" in the function call, and it works just the way it's supposed to. Also found that passing along hex values works a tiny bit differently. See the description of the _ImageSearch() function in the example code below. This is what I used: expandcollapse popup#include <array.au3> _test() Func _test() $test = _imagesearch("test6w", 0, 0, @DesktopWidth, @DesktopHeight, "transwhite", 50, 3, 1) If IsArray($test) Then _ArrayDisplay($test, "test") Else MsgBox(0, "test", $test) EndIf EndFunc ;==>_test ;=============================================================================== ; Description: Searches for the specified template contained in an image ; ; Syntax: _ImageSearch ; Parameters: ; $file - the .BMP file containing the template to look for ; $x1 - leftmost coordinate of the search area ; $y1 - topmost coordinate of the search area ; $x2 - rightmost coordinate of the search area ; $y2 - bottommost coordinate of the search area ; $transparent - "TRANSBLACK" or "TRANSWHITE", including the '"' ; for hex values, use e.g. "TRANS00FF00" ; $variation - 0 to 255. Used when real colors differ a bit from ; what is used in the template ; $runs - how often the template should be looked for until a result ; is returned; depends on $behavior ; $behavior - 0 = exit on any find ; 1 = exit on first positive find ; 2 = exit after $runs consecutive finds ; ; ; Return Values: success - Returns an array of the coordinate set found ; $array[1] & $array[2] = coordinate set of the top / left position where the template was found ; $array[3] & $array[4] = coordinate set of the center of where the template was found ; ; failure - Returns string 0 ;=============================================================================== Func _Imagesearch($file, $x1 = 0, $y1 = 0, $x2 = @DesktopWidth, $y2 = @DesktopHeight, $trans = "transblack", $variation = 60, $runs = 1, $behavior = 1) If $behavior > 3 Or $behavior < 0 Then $behavior = 1 If $runs < 1 Or $behavior = 0 Then $runs = 1 Dim $aCoords[$runs] = [99999]; just some number to make the _ArrayMax <-> _ArrayMin comparison work on it's first run $findImage = '*' & $trans & ' ' & '*' & $variation & ' ' & $file & ".bmp" $dll = DllOpen("imagesearchdll.dll") While 1 $result = DllCall($dll, "str", "ImageSearch", "int", $x1, "int", $y1, "int", $x2, "int", $y2, "str", $findImage) If $result[0] = "0" Then _ArrayPush($aCoords, 0, 1) Else _ArrayPush($aCoords, 1, 1) If $behavior = 1 Then ExitLoop EndIf If _ArrayMax($aCoords) == _ArrayMin($aCoords) Then ExitLoop Sleep(40) WEnd DllClose($dll) If $aCoords[0] = 1 Then $array = StringSplit($result[0], "|") Dim $aCoords[5] = [4, Int(Number($array[2])), Int(Number($array[3])), Int(Number($array[2])) + Int(Number($array[4]) / 2), Int(Number($array[3])) + Int(Number($array[5]) / 2)] Return ($aCoords) Else Return (0) EndIf EndFunc ;==>_Imagesearch Gave my interpretation of the _Imagesearch() function an overhaul. It now should return results in a more conventional shape. If someone can optimize it to run faster, please feel free to do so. Edited May 5, 2010 by Sven
VAG Posted June 3, 2010 Posted June 3, 2010 Hi Sven, for your $transparent value, I would suggest you can provide a way for the DLL to directly grab the top-left most pixel color of a template image instead of user input. Because most of the time, graphics designer will just set the background around an image obj to be the transparent color for webpage display. This method is implemented in Automation tool like TestComplete for transparent image searching.
hhzz Posted June 4, 2010 Posted June 4, 2010 I just couldn't believe that AutoIt doesn't have this functionality, and then I was amazed again by how hard it is to find a working "imagesearch" for autoit.I got it to work, more or less, after over 4 hours of trying a dozen DLL's scattered everywhere as well as a dozen .au3's that needed fixing before they worked.Xyzm: I am with you... This should be one of the key features of the language. I don't know why this thread is so dead and all the older links are gone.I find your increasing tolerance interesting. How did you arrive at 200 to be the max tolerance not to go over (absolute max is 255 according to the comment in the code)? It would be great if there is a fuzzy image recognition DLL to use instead of only exact match with color variations... At least being able to scale the picture for matching purpose would be great.
Phenom Posted June 7, 2010 Posted June 7, 2010 (edited) What are we supposed to do with the .dll file? Edited June 7, 2010 by Phenom
Sven Posted June 7, 2010 Posted June 7, 2010 I don't think stretchable and more variable templates can work well currently. Just think about the traffic sign recognition and auto driving stuff the car industry is researching for a lot of years now. If such pattern recognition would be as easily done as you think it is, we'd all be driving cars now like they do in movies like Minority Report or Demolition Man. imagesearchdll.dll is pretty good just as it is right now. An enhancement would be if it was made a native AutoIt function, but I don't know if the common history of both AutoHotkey (where this imagesearchdll.dll comes from) and AutoIt allows for this. Things are a bit complicated, if I remember correctly.
Fickle Posted July 18, 2010 Posted July 18, 2010 Whenever I use imagesearch, it functions perfectly and detects anything like it should, however, when i use imagesearcharea(), it only works for the desktop, meaning my wallpaper and whatever is on it. So detecting open windows does not work for me, is this normal?
Valerij Posted September 20, 2010 Posted September 20, 2010 Please help! I need this library for Win 7
Sven Posted September 23, 2010 Posted September 23, 2010 Here you go. Just remember to not use the 64bit AutoIt version with it.ImageSearchDLL.zip riceking and guestscripter 2
Valerij Posted September 25, 2010 Posted September 25, 2010 Here you go. Just remember to not use the 64bit AutoIt version with it.Thanks you, Sven!
Earthgas Posted October 4, 2010 Posted October 4, 2010 hmm i was wondering if image is vertical line will script find it when the exact same line will be horizontal ore in any ather posible position?
JohnOne Posted October 4, 2010 Posted October 4, 2010 hmm i was wondering if image is vertical line will script find it when the exact same line will be horizontal ore in any ather posible position? Not out of the box it wont.But Im sure the image could be manipulated albeit severley affecting its speed.But I woulnt know how anyway. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Earthgas Posted October 4, 2010 Posted October 4, 2010 mibe i could unite ImageSearch and PixelSearch togather,like if script finds image.bmp but it is in different position than in the pic maibe PixelSearch could check that image so it would be like doble safwe
JohnOne Posted October 4, 2010 Posted October 4, 2010 Go for it. Sounds like a great project. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Earthgas Posted October 4, 2010 Posted October 4, 2010 lol making my first script . maibe u could explain me when i open my GUI explorer window how i can make script to take it as full screen?That should make ImageSearch and PixelSearch faster not like if it had to search whole screen.
JohnOne Posted October 4, 2010 Posted October 4, 2010 Should probably use the help forum for that. GUISetState(@SW_MAXIMIZE) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Recommended Posts