Jump to content

Array help continued


Recommended Posts

Hi everyone,

I have this loop that turns a section of screenshot into a matrix of RGB values. Melba mentioned, in the other thread, to access your arrays you have to extract them from the holding array into a temp array - and then there is no way to make a direct comparison between arrays as with variables. I want to compare them to see if any colors have changed. Pixelchecksum should do the trick, i know how to do that but dont really know how to go about extracting them from them from the holding array to a temporary one. Could someone point me in the right direction? Here is my main loop:

For $i = 0 to 200 Step 1
    Local $anArray
    _ScreenCapture_CaptureWnd($k, $pong_hWnd, 61, 49, 119, 61, False)
    sleep(100)
    _FileImageToArray($k, $anArray)
    $aSlideshow[$i] = $anArray

Next
Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Historical text in question.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

  • Moderators

MasonMill,

I must not have been clear enough in my explanation as you seem to have the idea the wrong way round. ;)

The suggestion was to use PixelCheckSum on the image on the screen to detect any changes. If there were changes, you then take your screen shot, convert it into an array and store it. That way you avoid duplicate screenshots within your slideshow array.

As far as I know, you cannot use PixelCheckSum on the arrays you create from the screenshots - it only works on the displayed pixels. To compare the arrays, you would have to do a direct element-to-element comparison as we discussed earlier. The code would look something like this (not tested):

For $i = 0 To 199
    ; Extract the arrays
    Local $aTemp_Array_1 = $aSlideShow_Array[$i]
    Local $aTemp_Array_2 = $aSlideShow_Array[$i + 1]
    ; Now compare the 2 arrays
    $fError = False
    For $j = 0 To UBound($aTemp_Array_1) - 1 ; you might be able to use a variable here as all your arrays will be the same size
        If $aTemp_Array_1[$j] <> $aTemp_Array_2[$j] Then
            ; Set error flag
            $fError = True
            ; No point in continuing with this comparison
            ExitLoop
        EndIf
    Next
    ; Announce if there was an error
    If $fError Then MsgBox(0, "Error", "Arrays " & $i & " and " $i + 1 & " do not match")
Next

That is a lot of computation if the arrays are of any size.

However, as I explain above, if you use PixelCheckSum BEFORE storing the arrays, you should not need to do this. To use PixelCheckSum to check for differences before saving the array, you would need your loop to look something like this (again not tested):

$iLastCheckSum = 0

For $i = 0 to 200 Step 1
        
    Local $anArray
    
    ; Set the correct PixelMode - relative to client area like ScreenCapture
    $iOldPixelMode = Opt("PixelCoordMode", 2)
    
    ; Activate window
    WinActivate($pong_hWnd)
    
    Do
        ; Get checksum of the area
        $iCurrCheckSum = PixelChecksum(61, 49, 119, 61)
        Sleep(100) ; Suitable delay
        
    Until $iCurrCheckSum <> $iLastCheckSum
    
    ; If we are here, the area has changed
    
    ; Store the current value for the next check
    $iLastCheckSum = $iCurrCheckSum
    ; Capture the screen area
    _ScreenCapture_CaptureWnd($k, $pong_hWnd, 61, 49, 119, 61, False)
    Sleep(100)
    ; Convert to array
    _FileImageToArray($k, $anArray)
    ; Store the array
    $aSlideshow[$i] = $anArray

Next

Sorry if I confused you with my earlier suggestion - I hope this makes up for it. :blink:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I don't know why you guys re reinventing the wheel. I haven't followed exactly but I did see some of the comments in the other thread. I use imagesearch.au3 and imagesearch.dll to search the screen for images. It has a tolerance already built in. You do have to compile it in x86 even if you use x64 though because the dll is compiled 32 bit. And it seems to only search the main screen on 2 monitor setups but I have not found this to be a huge problem. Other than that it works great for what I think you are trying to do.

If you want another method of searching the screen for things you can try a relatively new language called Sikuli. I find it slower and less powerful than autoit, although their built in screen searching is impressive.

Link to comment
Share on other sites

  • Moderators

ShawnW,

don't know why you guys re reinventing the wheel

Because I for one had no idea the other wheel existed! ;)

Thanks for the info - I will now leave this thread in your capable hands! :blink:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I don't know why you guys re reinventing the wheel. I haven't followed exactly but I did see some of the comments in the other thread. I use imagesearch.au3 and imagesearch.dll to search the screen for images. It has a tolerance already built in. You do have to compile it in x86 even if you use x64 though because the dll is compiled 32 bit. And it seems to only search the main screen on 2 monitor setups but I have not found this to be a huge problem. Other than that it works great for what I think you are trying to do.

If you want another method of searching the screen for things you can try a relatively new language called Sikuli. I find it slower and less powerful than autoit, although their built in screen searching is impressive.

Yes I have imagesearch.au3, try doing it when the object you are searching for is slightly transparent. It has no tolerance at all, I have had extensive conversations with junkew(the author) and he doesn't even know how to do it. Problem is it converts RGB values to strings of 0s and 1s. Which is yes it found that EXACT color or not, which also means, no tolerance. So you see running people off that are actually trying to help is quite counter productive so please respect any help that is being given. Especially, when you haven't read it fully.

Link to comment
Share on other sites

First, I wasn't running anyone off. I was just mentioning it since you might have been going to a lot of trouble for nothing if you have not taken a look.

Also, it does have a tolerance, its one of the parameters. Set it to 30-40 for slightly transparent. It's accuracy depends on how much the background behind the transparency changes. Not saying it's perfect as I don't use it all the time, but I have had it work with slight transparency. In one case I had to use the _WaitForImageSearch() instead, the background would change to much and change quickly, but would repeat (flashing transparent menu). In that case the wait allowed for the image to be found because I had it wait 2 seconds and search while waiting. Eventually the values would fall under the tolerance.

-Shawn

Link to comment
Share on other sites

Have a look at here

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Ya i finally found the DLL but im getting an error i cant figure out.

ERROR

Line 40 ...ImageSearch.au3

if $result[0]="0" then return 0

if $result^ ERROR

Error: Subscript used with non-Array variable

here is the code i put together to test things out:

#include <GDIPlus.au3>
#Include <ScreenCapture.au3>
#Include <WinAPI.au3>


Global $coords[2]
Global $pathToBMP = "C:\Users\..." ; Path to the image you want to find

HotKeySet("{F1}", "FindImage")

While 1
    sleep(100)
WEnd

Func FindImage()
    ; The parameters for _ImageSearch are _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance)
    ; Most are self explainitory but $resultPosition = 1 or 0.
    ; It determins what coords are returned, 1 for center of image and 0 for top left.
    $result = _ImageSearch($pathToBMP,0,$coords[0],$coords[1],50)
    
    If $result = 1 Then
        Send("{ESCAPE}")
    EndIf
    
    if $result = 1 then
        msgbox(0,"Result","Found!")
    else
       msgbox(0,"Result","Not Found!")
    endif
    
EndFunc

; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------

;===============================================================================
;
; Description:      Find the position of an image on the desktop
; Syntax:           _ImageSearchArea, _ImageSearch
; Parameter(s):     
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of 
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0 
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
       
    ; If error exit
    if $result[0]="0" then return 0
    
    ; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    $array = StringSplit($result[0],"|")
    
  
   
   $x=Int(Number($array[2]))
   $y=Int(Number($array[3]))
   if $resultPosition=1 then
      $x=$x + Int(Number($array[4])/2)
      $y=$y + Int(Number($array[5])/2)
   endif
   return 1
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;     
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):     
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of 
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0 
;
;
;===============================================================================
Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        sleep(100)
        $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
        if $result > 0 Then
            return 1
        EndIf
    WEnd
    return 0
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;     
; Syntax:           _WaitForImagesSearch
; Parameter(s):     
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;                                ARRAY[1] is the first image
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of 
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns the index of the successful find
;                   On Failure - Returns 0 
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        for $i = 1 to $findImage[0]
            sleep(100)
            $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
            if $result > 0 Then
                return $i
            EndIf
        Next    
    WEnd
    return 0
EndFunc
Edited by MasonMill
Link to comment
Share on other sites

I assume this is line 70 of the script provided.

For some reason AutoIt does not believe that $result is an array. The function may have failed, the dll many not have been found or something else might have happened. You can use IsArray() to test $result and I would recommend checking @error.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

You to not need to "install" then dll. Bo8ster is correct and the function from the dllcall is not being executed properly. I would add this on the line following the DllCall.

If @error Then ConsoleWrite("Error Code: " & @error & @CRLF)

Then run it again, and read the console for the error code.

@error:

1 unable to use the DLL file,

2 unknown "return type",

3 "function" not found in the DLL file,

4 bad number of parameters.

Edit: The dll does need to be in the same folder though.

Edited by ShawnW
Link to comment
Share on other sites

consolewrite, bane of my existence. I know what it does but i can never find it! How do i view consolewrite?

Sound like a paradox to me.

How about you take some time reading the AutoIt help file on a subject before dropping in a new question.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Yes, i have read it many times over.

Writes data to the STDOUT stream. Some text editors can read this stream as can other programs which may be expecting data on this stream.

Someone gave me some text wrapper thing that didnt work and have tried various other means to no avail. No one can give me a straight answer on how to read the STDOUT stream. Why doesnt autoit have like a text field where it shows all this?

Edited by MasonMill
Link to comment
Share on other sites

Why doesnt autoit have like a text field where it shows all this?

Probably because STDOUT is a output stream in relation to the application that generates it.

Anyway. Forums are no IRC chat channels. And I'll leave it at that.

PS: If I'm correct you still have a open replay from ShawnW. You might like to let hem know whether his information was useful to you.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Man you should really try waking up on the right side of the bed tomorrow... I am very gracious for Shawn's help, and thats why I am trying to figure out consolewrite to i can return with something competent. I didn't realize there was a time limit on when i needed to come up with an answer or a thank you for that matter.

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