Jump to content

Imagesearch srtange issue


totoita
 Share

Recommended Posts

Hi,

I am building a script with success then i have got this problem:

this works:
 

$result = _ImageSearch ( 'btnrecycle.bmp', 0, $posx1_green, $posy1_green, 0)

it returns 1 in $result

this works (1 line above):
 

$result2 = _ImageSearch('green_crate.bmp', 0, $posx1_btn_recycle, $posy1_btn_recycle, 0)

it return 1 in $result2
but this did not works either:
 

$result = _ImageSearch ( 'btnrecycle.bmp', 0, $posx1_green, $posy1_green, 0)
$result2 = _ImageSearch('green_crate.bmp', 0, $posx1_btn_recycle, $posy1_btn_recycle, 0)

without changing anything (except to uncomment the line of course).
Inserting a msgbox bewteen line 1 and 2 and another msgbox after the second line, give me 2 differents value for $result.

1st msgbox gives 1 and the 2nd msgbox gives nothing !
Why the second research change the value return by the first one, they are 2 different variable ?

Those variable are not declared.
I try different solution, adding a declaration as local or global for both variable but it does not change anything.

I probably miss something but what ?

windows 7 64bit or windows xp (same iussue)
autoit 3.5.4
ImageSearchDLL.dll 92k (2008 in details)

Edited by Melba23
Added additional details from second post - most of which just repeated the first
Link to comment
Share on other sites

i did not put them in the post...but just imagine 1 msgbox insert between the line 1 and 2..so it becames 3 lines..and another after the new line 3.

$result = _ImageSearch ( 'btnrecycle.bmp', 0, $posx1_green, $posy1_green, 0)
MsgBox(0x0, 'result recycle btl:', $result, 0) ; give me 1
$result2 = _ImageSearch('green_crate.bmp', 0, $posx1_btn_recycle, $posy1_btn_recycle, 0)
MsgBox(0x0, 'result recycle btl:', $result, 0) ; give me nothing..empty..


 

Link to comment
Share on other sites

  • Developers

Could it be that the area where the msgbox appeared isn't fully re-painted before the second _ImageSearch()?
Try adding a sleep(1000) after the first msgbox() to test.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ImageSearch.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>

;search in selection left (472,561) bottom right (850, 968)
MsgBox(0,"MSG","placer l image juste derrière")
Sleep ( 400 )
Local $cratediscovered = 0
Local $fortesting_list_of_arti_lvl_found
Local $iTimeout = 10

Local $posx1_green=0 ;
Local $posy1_green=0 ;

Local $posx1_btn_recycle = 0 ; 
Local $posy1_btn_recycle = 0 

Local $ipixelColor = 0

Local $x_pixelcolor = 0
Local $y_pixelcolor = 0
Local $x_pixelcolor1 = 0
Local $y_pixelcolor1 = 0
Local $x_pixelcolor2 = 0
Local $y_pixelcolor2 = 0
Local $x_pixelcolor3 = 0
Local $y_pixelcolor3 = 0
Local $x_pixelcolor4 = 0
Local $y_pixelcolor4 = 0

Local $x_pixelcolor_hundred = 0
Local $y_pixelcolor_hundred = 0


Local $iColor = 9999
Local $iColor1 = 1
Local $iColor2 = 1
Local $iColor3 = 1
Local $iColor4 = 1

Local $iColor20 = 1
Local $iColor30 = 1

Local  $arr[300][4]

Local $i_forarray = 0
Local $y_forarray = 0

$oDictionary = ObjCreate("Scripting.Dictionary")

$oDictionary.ADD("1000", "1")
$oDictionary.ADD("1100", "2")
$oDictionary.ADD("0100", "3")
$oDictionary.ADD("0011", "4")
$oDictionary.ADD("0101", "5")
$oDictionary.ADD("0111", "6")
$oDictionary.ADD("0000", "7")
$oDictionary.ADD("0110", "8")
$oDictionary.ADD("0001", "9")

;
; find recycle bin and move to the center of it
; change 2nd argument to 0 to return the top left coord instead

;$result = _ImageSearch ( 'green_crate.bmp', 0, $posx1_green, $posy1_green, 0)
$result = _ImageSearch ( 'btnrecycle.bmp', 0, $posx1_green, $posy1_green, 0)
MsgBox(0x0, 'result recycle btl:', $result, 0)
$result2 = _ImageSearch('green_crate.bmp', 0, $posx1_btn_recycle, $posy1_btn_recycle, 0)
MsgBox(0x0, 'result recycle btl:', $result, 0)

;MsgBox(0x0, 'result green crate:', $result2, 0)
;while ( $result = 1 and $cratediscovered < 9)
if ($result = 1) Then
     MouseMove($posx1_green, $posy1_green,3)
     ;MouseMove($posx1_green, $posy1_green,3)
    ;MsgBox(0,"red crate found","green crate found..")
    ;MsgBox($MB_SYSTEMMODAL, "Title", "poistion x et y, x: " & $posx1_green & " y: " &$posy1_green & " seconds or select the OK button.")

    MouseClick($MOUSE_CLICK_LEFT, $posx1_green, $posy1_green)
    Sleep ( 50 )


    $x_pixelcolor20 = $posx1_green + 42
    $y_pixelcolor20 = $posy1_green + 47 ;le bas du dernier l de level

    $x_pixelcolor30 = $posx1_green + 42
    $y_pixelcolor30 = $posy1_green + 39 ; le haut du dernier l de level

    $x_pixelcolor1 = $posx1_green + 42 + 7
    $y_pixelcolor1 = $posy1_green + 47

    $x_pixelcolor2 = $posx1_green + 42 + 7
    $y_pixelcolor2 = $posy1_green + 47 - 1

    $x_pixelcolor3 = $posx1_green + 42 + 7
    $y_pixelcolor3 = $posy1_green + 47 - 2

    $x_pixelcolor4 = $posx1_green + 42 + 7
    $y_pixelcolor4 = $posy1_green + 47 - 4

    $x_pixelcolor_hundred = $posx1_green + 42 + 32
    $y_pixelcolor_hundred = $posy1_green + 42 - 3


    ;Local $iColor20 = PixelGetColor($x_pixelcolor20, $y_pixelcolor20)
    ;Local $iColor30 = PixelGetColor($x_pixelcolor30, $y_pixelcolor30)
    ;MsgBox($MB_SYSTEMMODAL, "", "le l de level -- " & ",icolor20=" & $iColor20 & ",icolor30=" & $iColor30)


     $iColor1 = PixelGetColor($x_pixelcolor1, $y_pixelcolor1)
     $iColor2 = PixelGetColor($x_pixelcolor2, $y_pixelcolor2)
     $iColor3 = PixelGetColor($x_pixelcolor3, $y_pixelcolor3)
     $iColor4 = PixelGetColor($x_pixelcolor4, $y_pixelcolor4)

     $iColor_hundred = PixelGetColor($x_pixelcolor_hundred, $y_pixelcolor_hundred) ; check if it is 1,1x or 1xx
    ;MsgBox($MB_SYSTEMMODAL, "", "icolor= " & $iColor & ",icolor1=" & $iColor1 & ",icolor2=" & $iColor2 & ",icolor3=" & $iColor3 & ",icolor4=" & $iColor4)

    if ($iColor1 <> 0) then $iColor1 = 1 ; 1 is for "not black"
    if ($iColor2 <> 0) then $iColor2 = 1
    if ($iColor3 <> 0) then $iColor3 = 1
    if ($iColor4 <> 0) then $iColor4 = 1
    if ($iColor_hundred <> 0) then $iColor_hundred = 1 ; so it is a 1xx artifact if <> 0 ..bracket detected..

    ;MsgBox($MB_SYSTEMMODAL, "", "icolor= " & $iColor & ",icolor1=" & $iColor1 & ",icolor2=" & $iColor2 & ",icolor3=" & $iColor3 & ",icolor4=" & $iColor4)
    ;MsgBox($MB_SYSTEMMODAL, "", "The decimal color is: " & $iColor & "---1:" & $iColor1 & "---2:" & $iColor2 & "---3:" & $iColor3 & "---4:" & $iColor4)

    ;$iColor1 = PixelGetColor($x_pixelcolor1, $y_pixelcolor1)
    ;$iColor2 = PixelGetColor($x_pixelcolor2, $y_pixelcolor2)
    ;$iColor3 = PixelGetColor($x_pixelcolor3, $y_pixelcolor3)
    ;$iColor4 = PixelGetColor($x_pixelcolor4, $y_pixelcolor4)
   $iColor = $iColor1 & $iColor2 & $iColor3 & $iColor4


   If Not ($oDictionary.Exists($iColor)) Then
     ;MsgBox(0x0, 'Item Two', $oDictionary.Item('Two'), 2)
    ; MsgBox(0x0, 'Chiffres trouvés:', $oDictionary.Item($iColor), 2)
     ;MouseClick($MOUSE_CLICK_LEFT, $posx1_green, $posy1_green)
    ;
     MsgBox($MB_SYSTEMMODAL, "Title", "Chiffres non trouvés, program will exit", 0)
     Exit
   Else
     $fortesting_list_of_arti_lvl_found = $fortesting_list_of_arti_lvl_found & " - " & $oDictionary.Item($iColor) ; for testing only
   EndIf
   If ($iColor < 5 and   $iColor_hundred <> 1) then
     MouseClick($MOUSE_CLICK_LEFT, $posx1_btn_recycle, $posy1_btn_recycle)
     MouseClick($MOUSE_CLICK_LEFT, $posx1_green, $posy1_green)

     ;$posx1_btn_recycle
   EndIf
   ;MsgBox($MB_SYSTEMMODAL, "", "The decimal color is: " & $iColor & "-1:" & $iColor1 & "-2:" & $iColor2 & "-3:" & $iColor3 & "-4:" & $iColor4)
    ;MsgBox($MB_SYSTEMMODAL, "", "icolor= " & $iColor & ",icolor1=" & $iColor1 & ",icolor2=" & $iColor2 & ",icolor3=" & $iColor3 & ",icolor4=" & $iColor4)
    ;MsgBox(0x0, 'Chiffre trouvé:', $iColor)
    ;$iColor1 = 1
    ;$iColor2 = 1
    ;$iColor3 = 1
    ;$iColor4 = 1
    $result = _ImageSearch('green_crate.bmp', 0, $posx1_green, $posy1_green, 0)
    $cratediscovered =  $cratediscovered + 1

;WEnd
;$fortesting_list_of_arti_lvl_found
MsgBox(0x0, 'Artif trouvées:', $fortesting_list_of_arti_lvl_found, 0)

EndIf

it s a working code..many things are in comments.

Link to comment
Share on other sites

;$result = _ImageSearch ( 'green_crate.bmp', 0, $posx1_green, $posy1_green, 0)
$result = _ImageSearch ( 'btnrecycle.bmp', 0, $posx1_green, $posy1_green, 0)
MsgBox(0x0, 'result recycle btl:', $result, 0)
$result2 = _ImageSearch('green_crate.bmp', 0, $posx1_btn_recycle, $posy1_btn_recycle, 0)
MsgBox(0x0, 'result recycle btl:', $result, 0)

Is that a typo? Or is the 2nd msgbox supposed to show the same variable $result?

Link to comment
Share on other sites

It was no typo, it was to demostrate the issue:

On ‎20‎.‎02‎.‎2016 at 11:11 AM, totoita said:

Inserting a msgbox bewteen line 1 and 2 and another msgbox after the second line, give me 2 differents value for $result.

1st msgbox gives 1 and the 2nd msgbox gives nothing !
Why the second research change the value return by the first one, they are 2 different variable ?

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