Sori Posted November 7, 2013 Posted November 7, 2013 (edited) I'm sure many of you are aware of the image search library. I wanted to make a slightly more advanced version that checks the last known location of an image before checking the full screen. In essense, making the image search faster... Here is what I have. Test.au3 #include <Advanced Image Search.au3> AdvancedImageSearch("Example.bmp", 30) Advanced Image Search.au3 expandcollapse popup#include <GetFileProperty.au3> #include <ImageSearch.au3> Dim $pHeight = 0 Dim $pWidth = 0 Dim $dArray Dim $lastKnownX = "" Dim $lastKnownY = "" Dim $checkXTL = 0 Dim $checkXBR = 0 Dim $checkYTL = 0 Dim $checkYBR = 0 Func AdvancedImageSearch($picName, $transparency) Dim $x = 0 Dim $y = 0 If FileExists("C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName) = 1 Then GetDimensions($picName) $lastKnownX = GetLastX($picName) $lastKnownY = GetLastY($picName) ;If no record of File exists, search entire screen and save location found to registry. If $lastKnownX = "" or _ $lastKnownY = "" Then If _ImageSearchArea("C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName,1,0,0,@DesktopWidth,@DesktopHeight,$x, $y, $transparency) = 1 Then RegWrite("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " X", "REG_SZ", $x) RegWrite("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Y", "REG_SZ", $y) MsgBox(0, $picName, "Found at " & $x & ", " & $y) Else MsgBox(0, $picName, "Image Not Found") EndIf Else ;Check last known location. SetLocationCoordinates() If _ImageSearchArea("C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName,1,$checkXTL,$checkYTL,$checkXBR,$checkYBR,$x, $y, $transparency) = 1 Then MsgBox(0, $picName, "Found at last coordinates") MouseMove($x, $y, 0) Else ;If not found at last location, check entire screen. If _ImageSearchArea("C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName,1,0,0,@DesktopWidth,@DesktopHeight,$x, $y, $transparency) = 1 Then RegWrite("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " X", "REG_SZ", $x) RegWrite("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Y", "REG_SZ", $y) MsgBox(0, $picName, "Found at " & $x & ", " & $y) Else MsgBox(0, $picName, "Not Found") EndIf ;Search total screen EndIf ;Found at Last Coordinates EndIf ;Last Known X Else MsgBox(0, "File Path Error", "Picture: '" & $picName & "' does not exist in Images folder.") EndIf ;File Exists EndFunc Func GetDimensions($picName) Dim $prop $path = "C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName $prop = _GetFileProperty($path, "Dimensions") $dArray = StringSplit($prop, " x ") $pWidth = $dArray[1] ;Picture Width $pHeight = $dArray[4] ;Picture Height EndFunc Func GetLastX($picName) Return RegRead("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " X") EndFunc Func GetLastY($picName) Return RegRead("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Y") EndFunc Func SetLocationCoordinates() ;MsgBox(0, "Last Known X", $lastKnownX) ;MsgBox(0, "Last Known Y", $lastKnownY) MsgBox(0, "pWidth", $pWidth) ;MsgBox(0, "pHeight", $pHeight) ;MsgBox(0, "XTL", $checkXTL) ;MsgBox(0, "YTL", $checkYTL) ;MsgBox(0, "XBR", $checkXBR) ;MsgBox(0, "YBR", $checkYBR) MsgBox(0, "pWidth / 2", $pWidth / 2) ;$checkXTL = ($lastKnownX - (round($pWidth / 2) + 1)) ;$checkXBR = $lastKnownX + (round($pWidth / 2) + 1) ;$checkYTL = $lastKnownY - (round($pHeight / 2) + 1) ;$checkYBR = $lastKnownY + (round($pHeight / 2) + 1) ;MsgBox(0, "XTL", $checkXTL) ;MsgBox(0, "YTL", $checkYTL) ;MsgBox(0, "XBR", $checkXBR) ;MsgBox(0, "YBR", $checkYBR) EndFunc Now... During the "SetLocationCoordinates" function.... $pWidth is 191. Message box shows this to be true. But doing anything to $pWidth, in relation to mathematics (dividing, adding, subtracting) will cause it to show $pWidth as 0. Edited November 7, 2013 by Sori If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
mikell Posted November 7, 2013 Posted November 7, 2013 (edited) Please try using Number($pWidth) and declare $pWidth as Global Edited November 7, 2013 by mikell
water Posted November 7, 2013 Posted November 7, 2013 Even if $pWidth i s a string I always get 192. Which line is in error? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted November 7, 2013 Posted November 7, 2013 Please try using Number($pWidth) When AutoIt does a numeric operation and one of the operands is a string it is implicitely translated to a number. So there should be no need for this to solve this problem. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Sori Posted November 7, 2013 Author Posted November 7, 2013 (edited) Please try using Number($pWidth) and declare $pWidth as Global I tried that, it still made pWidth 0 Let me try the global thing really quick. -- Still shows 0 Even if $pWidth i s a string I always get 192. Which line is in error? If I set pWidth manually, like $pWidth = 191, it would work fine. I'm not entirely sure where it's messing up. Line 75 says 191 Line 81 says 0 If I change it to + 1, it will instead say 1. Edited November 7, 2013 by Sori If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
water Posted November 7, 2013 Posted November 7, 2013 Can you insert a MsgBox(0, "", VargetType($pWidth)) before line 81 and post the result? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Sori Posted November 7, 2013 Author Posted November 7, 2013 When AutoIt does a numeric operation and one of the operands is a string it is implicitely translated to a number. So there should be no need for this to solve this problem. Number($pWidth) / 2 ; 0 Number($pWidth / 2) ; 0 Number($pWidth) ; 0 It doesn't like changing it into a number at all <.< If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
Sori Posted November 7, 2013 Author Posted November 7, 2013 (edited) Can you insert a MsgBox(0, "", VargetType($pWidth)) before line 81 and post the result? String P.S. I was unaware of that function, very convenient Edited November 7, 2013 by Sori If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
Bert Posted November 7, 2013 Posted November 7, 2013 For educational purposes, what would this be used for as far as an application? Curious.... The Vollatran project My blog: http://www.vollysinterestingshit.com/
trancexx Posted November 7, 2013 Posted November 7, 2013 Number($pWidth) / 2 ; 0 Number($pWidth / 2) ; 0 Number($pWidth) ; 0 It doesn't like changing it into a number at all <.< Maybe it's something like this: $pWidth = "l91" ConsoleWrite(Number($pWidth) & @CRLF) ♡♡♡ . eMyvnE
Sori Posted November 7, 2013 Author Posted November 7, 2013 Local $width = Number(0) . . . MsgBox(0, "", VargetType($width)) ; Int32 . $width = Number($pWidth) MsgBox(0, "", $width) ; 0 If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
Sori Posted November 7, 2013 Author Posted November 7, 2013 For educational purposes, what would this be used for as far as an application? Curious.... I'm creating an AI that will be able to control the entirety of my computer and hopefully I can have it learn. The reason I am doing the advanced image recognition is to make image recognition faster for items that are stationary, but can sometimes move. Like an application on the taskbar, or even the quickbar. If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
Sori Posted November 7, 2013 Author Posted November 7, 2013 (edited) Maybe it's something like this: $pWidth = "l91" ConsoleWrite(Number($pWidth) & @CRLF) That seems to have worked. Thank you. Scratch that... It still won't do math on it. It just saves 191 and then adding or dividing still shows 191. Edited November 7, 2013 by Sori If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
trancexx Posted November 7, 2013 Posted November 7, 2013 What do you get when you run my two lines? ♡♡♡ . eMyvnE
Sori Posted November 7, 2013 Author Posted November 7, 2013 What do you get when you run my two lines? Func SetLocationCoordinates() MsgBox(0, "pWidth", $pWidth) MsgBox(0, "", VargetType($pWidth)) ConsoleWrite(Number(($pWidth)) & @CRLF) MsgBox(0, "pWidth", ($pWidth + 1)) EndFunc shows 1 Func SetLocationCoordinates() $pWidth = "191" MsgBox(0, "pWidth", $pWidth) MsgBox(0, "", VargetType($pWidth)) ConsoleWrite(Number(($pWidth)) & @CRLF) MsgBox(0, "pWidth", ($pWidth + 1)) EndFunc Shows 192 If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
trancexx Posted November 7, 2013 Posted November 7, 2013 Forget for second your script and make new one with this exact code in it: $sSori = "l9l" $nSorry = Number($sSori) MsgBox(4096, "Sori Math", $nSorry) ; TADA! What do you get? ♡♡♡ . eMyvnE
Sori Posted November 7, 2013 Author Posted November 7, 2013 (edited) Forget for second your script and make new one with this exact code in it: $sSori = "l9l" $nSorry = Number($sSori) MsgBox(4096, "Sori Math", $nSorry) ; TADA! What do you get? Created a new script... $sSori = "l9l" $nSorry = Number($sSori) MsgBox(4096, "Sori Math", $nSorry) ; TADA! Gave me 0 eh... are those L? Edited November 7, 2013 by Sori If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
Bowmore Posted November 7, 2013 Posted November 7, 2013 Logically the only place that it can be going wrong is in one of these 2 lines in the GetDimensions() function $prop = _GetFileProperty($path, "Dimensions") $dArray = StringSplit($prop, " x ") $dArray[1] probably contains spaces or other chracters before the number repesenting the width. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
trancexx Posted November 7, 2013 Posted November 7, 2013 Created a new script... $sSori = "l9l" $nSorry = Number($sSori) MsgBox(4096, "Sori Math", $nSorry) ; TADA! Gave me 0 eh... are those L? So, how do you explain that? Now do this: $sSori = "191" $nSorry = Number($sSori) MsgBox(4096, "Sori Math", $nSorry) ; TADA! What do you get now? ♡♡♡ . eMyvnE
Sori Posted November 7, 2013 Author Posted November 7, 2013 Logically the only place that it can be going wrong is in one of these 2 lines in the GetDimensions() function $prop = _GetFileProperty($path, "Dimensions") $dArray = StringSplit($prop, " x ") $dArray[1] probably contains spaces or other chracters before the number repesenting the width. dArray is showing as a string, trying to force it into an int causes it to give 0. I'll have to dive into the GetFileProperty au3 and see if I can find anything. If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now