Jump to content

191 + 1 = 1? w...t...h?


Sori
 Share

Go to solution Solved by Sori,

Recommended Posts

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.

Interesting! I like to see how this project progresses. Keep us updated please!

Edited by YogiBear
Link to comment
Share on other sites

What you tink is the number one is in fact a lowercase L

"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

Link to comment
Share on other sites

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.

 

I changed the dilimiter to " ", pWidth stays as [1], height changes to [3], but it still gives a 0 when converting it into a number.

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

So anyway, my point was that non-numeric characters at the beginning of the number_string can affect the output you get dramatically. What you need to do is ditch non-numbers and then use Number() or even better Int() to get number out of the string.

Characters that are at the beginning of the string for which you assume is the number may or may not be visible to you when you display them inside MsgBox.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

So anyway, my point was that non-numeric characters at the beginning of the number_string can affect the output you get dramatically. What you need to do is ditch non-numbers and then use Number() or even better Int() to get number out of the string.

Characters that are at the beginning of the string for which you assume is the number may or may not be visible to you when you display them inside MsgBox.

 

How can I read the raw data of a variable, or is there a way to remove everything except the numbers?

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

I've created a reproducer script. It shows the string returned by _GetFileProperty starts with an unreadable character. I modified the script so it works now:

#include <Array.au3>

$path = @ScriptDir & "\test.jpg"
$prop = _GetFileProperty($path, "Dimensions")
ConsoleWrite(">" & $prop & "<" & @LF)
$dArray = StringSplit($prop, " x ")
$pWidth = Number(StringMid($dArray[1], 2))
ConsoleWrite(VarGetType($pWidth) & @LF)


;===============================================================================
;
; Description:          Returns the requested property or an array of all properties
;                           for the specified file.
; Syntax:               _GetFileProperty( $sPath, optional $sProp )
; Parameter(s):     $sPath -    Path and filename of the file to query
;                           $sProp -    (optional) Name of property to return
;                                       if not specified will return array of all properties
; Requirement(s):       AutoIt 3.2 or higher
; Return Value(s):  On Success - Returns string value of property OR
;                                            Returns 2 dimensional array (property name,value)
;                           On Failure - Returns nothing
;                                            @error = 1 - file does not exist
;                                            @error = 2 - unable to get property
; Author(s):            Sean Hart (autoit AT hartmail DOT ca)
;                           (idea from GetExtProperty by Simucal, thanks)
; Note(s):              Special
;
;===============================================================================
Func _GetFileProperty($sPath, $sProp = "")
    ; Declare local variables
    Local $sFile, $sDir, $oShell, $oDir, $oFile, $i, $count, $aProps[1][3]

    ; Init counter used for array of properties
    $count = 0

    ; Check file exists first
    If Not FileExists($sPath) Then
        SetError(1)
        Return
    Else
        ; Pull file name and directory from full file path
        $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
        $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))

        ; Create required objects
        $oShell = ObjCreate("shell.application")
        $oDir = $oShell.NameSpace($sDir)
        $oFile = $oDir.Parsename($sFile)

        ; Loop through 99 possible property numbers (allows for future additions to property fields)
        For $i = 0 To 99
            ; If no property specified then add to array
            If ($sProp = "") Then
                ; Only add if property name is not blank
                If ($oDir.GetDetailsOf($oDir.Items, $i) <> "") Then
                    ; Increase counter and redimension array
                    $count = $count + 1
                    ReDim $aProps[$count + 1][3]

                    ; Add property name and value to array
                    $aProps[$count][1] = $oDir.GetDetailsOf($oDir.Items, $i)
                    $aProps[$count][2] = $oDir.GetDetailsOf($oFile, $i)
                EndIf

                ; If property name matches property being requested, return value
            ElseIf $oDir.GetDetailsOf($oDir.Items, $i) = $sProp Then
                Return $oDir.GetDetailsOf($oFile, $i)
            EndIf
        Next

        ; If array was populated return array, otherwise return error 2
        If $count > 0 Then
            Return $aProps
        Else
            SetError(2)
            Return
        EndIf
    EndIf
EndFunc   ;==>_GetFileProperty

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

You should use the GetFileProperty version in my signature, that one is seriously outdated.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 

I've created a reproducer script. It shows the string returned by _GetFileProperty starts with an unreadable character. I modified the script so it works now:

#include <Array.au3>

$path = @ScriptDir & "\test.jpg"
$prop = _GetFileProperty($path, "Dimensions")
ConsoleWrite(">" & $prop & "<" & @LF)
$dArray = StringSplit($prop, " x ")
$pWidth = Number(StringMid($dArray[1], 2))
ConsoleWrite(VarGetType($pWidth) & @LF)


;===============================================================================
;
; Description:          Returns the requested property or an array of all properties
;                           for the specified file.
; Syntax:               _GetFileProperty( $sPath, optional $sProp )
; Parameter(s):     $sPath -    Path and filename of the file to query
;                           $sProp -    (optional) Name of property to return
;                                       if not specified will return array of all properties
; Requirement(s):       AutoIt 3.2 or higher
; Return Value(s):  On Success - Returns string value of property OR
;                                            Returns 2 dimensional array (property name,value)
;                           On Failure - Returns nothing
;                                            @error = 1 - file does not exist
;                                            @error = 2 - unable to get property
; Author(s):            Sean Hart (autoit AT hartmail DOT ca)
;                           (idea from GetExtProperty by Simucal, thanks)
; Note(s):              Special
;
;===============================================================================
Func _GetFileProperty($sPath, $sProp = "")
    ; Declare local variables
    Local $sFile, $sDir, $oShell, $oDir, $oFile, $i, $count, $aProps[1][3]

    ; Init counter used for array of properties
    $count = 0

    ; Check file exists first
    If Not FileExists($sPath) Then
        SetError(1)
        Return
    Else
        ; Pull file name and directory from full file path
        $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
        $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))

        ; Create required objects
        $oShell = ObjCreate("shell.application")
        $oDir = $oShell.NameSpace($sDir)
        $oFile = $oDir.Parsename($sFile)

        ; Loop through 99 possible property numbers (allows for future additions to property fields)
        For $i = 0 To 99
            ; If no property specified then add to array
            If ($sProp = "") Then
                ; Only add if property name is not blank
                If ($oDir.GetDetailsOf($oDir.Items, $i) <> "") Then
                    ; Increase counter and redimension array
                    $count = $count + 1
                    ReDim $aProps[$count + 1][3]

                    ; Add property name and value to array
                    $aProps[$count][1] = $oDir.GetDetailsOf($oDir.Items, $i)
                    $aProps[$count][2] = $oDir.GetDetailsOf($oFile, $i)
                EndIf

                ; If property name matches property being requested, return value
            ElseIf $oDir.GetDetailsOf($oDir.Items, $i) = $sProp Then
                Return $oDir.GetDetailsOf($oFile, $i)
            EndIf
        Next

        ; If array was populated return array, otherwise return error 2
        If $count > 0 Then
            Return $aProps
        Else
            SetError(2)
            Return
        EndIf
    EndIf
EndFunc   ;==>_GetFileProperty

 

Using the new script wielded the same results.

I tried it with both " " and " x " as the dilimiter.

Edit:

Ignore half of what I say, I didn't read your code correctly.

Let me try implementing this into my own code.

----------

You should use the GetFileProperty version in my signature, that one is seriously outdated.

AutoIt Error

Line 7 (File "C:UsersThe Lucky CraneDesktopAIOtherGetFileProperty.au3"):

For $I = 1 to $aFiles[0]

For $I = 1 to $aFiles^Error

Error: Subscript used with non-Array variable.

eh... how do I properly call this thing?

Why is it asking me for a folder location. I want to feed it the path inside the code.

Edited 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.

Link to comment
Share on other sites

Using the new script wielded the same results.

I tried it with both " " and " x " as the dilimiter.

There is no need to change the script.

Modify this line so it points to your picture file.

$path = @ScriptDir & "\test.jpg"

The result should then be "Int32".

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

The header of the UDF explains in excruciating detail how to use it. The top part is ONLY a demo, the Function is all that matters.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BTW, that stringsplit should probably be using flag 1 instead of the default flag of 0.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Solution

There is no need to change the script.

Modify this line so it points to your picture file.

$path = @ScriptDir & "\test.jpg"

The result should then be "Int32".

Func GetDimensions($picName)
   Dim $prop
   $path = "C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName
   $prop = _GetFileProperty($path, "Dimensions")
   ConsoleWrite(">" & $prop & "<" & @LF)
   $dArray = StringSplit($prop, " x ")
   $pWidth = Number(StringMid($dArray[1], 2)) ;Removes first character from dArray[1] and then converts into number.
   $pHeight = Number($dArray[4])
   ConsoleWrite(VarGetType($pWidth) & @LF)
EndFunc

All is working.

Thank you very much, Water.

Edited 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.

Link to comment
Share on other sites

Ah, finally good news ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

My math is off for the coordinates. Probably just an issue with converting picture coordinates into desktop coordinates. Oh well... I can figure that one out on my own ;o
Thank you everyone for your help.

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

Dim $timer = TimerInit()
      ;Run code
MsgBox(0, "TimerDiff", TimerDiff($timer))

Picture: 191 x 47

Normal Full Screen search -

Pic at Top left of screen: 15 milliseconds

Pic at Bottom Right of Screen: 31 milliseconds

Advanced Search -

Pic at Top left of screen: 33 milliseconds

Pic at Bottom Right of Screen: 48 milliseconds

Pic in same location as last search: 18 milliseconds

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

Dim $timer = TimerInit()
      ;Run code
MsgBox(0, "TimerDiff", TimerDiff($timer))

Picture: 191 x 47

Normal Full Screen search -

Pic at Top left of screen: 15 milliseconds

Pic at Bottom Right of Screen: 31 milliseconds

Advanced Search -

Pic at Top left of screen: 33 milliseconds

Pic at Bottom Right of Screen: 48 milliseconds

Pic in same location as last search: 18 milliseconds

If FileExists("C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName) = 1 Then
      If RegRead("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Width") = "" Then
         GetDimensions($picName)
      Else
         $pWidth = RegRead("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Width")
         $pHeight = RegRead("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Height")
      EndIf
Func GetDimensions($picName)
   Dim $prop
   $path = "C:\Users\The Lucky Crane\Desktop\AI\Images\" & $picName
   $prop = _GetFileProperty($path, "Dimensions")
   $dArray = StringSplit($prop, " x ")
   $pWidth = Number(StringMid($dArray[1], 2))
   $pHeight = Number($dArray[4])
   RegWrite("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Width", "REG_SZ", $pWidth)
   RegWrite("HKEY_CURRENT_USER\Software\TheLuckyCrane\Image Locations",$picName & " Height", "REG_SZ", $pHeight)   
EndFunc

Pic in same location as last search: 2 milliseconds

Getting the dimensions is a huge bottleneck, so you should only do it one time.

I'll have to figure out a solution for if the reference picture changes size.

(Like if you save a new picture, but forget to erase the old dimensions, or whatever)

Edited 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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...