Jump to content
Sign in to follow this  
svenjatzu

It could be so easy but im to newby - imagesearch with different pictures

Recommended Posts

svenjatzu

Hi team im on my way to write a little tool for my work but i stuck in here becuse im more or less new.

someone maybe can help me with it please?

 

Thise is my script up to now.
 

#include <ImageSearch.au3>

Local $left = 15
Local $top = 645
Local $right = 289
Local $bottom = 798
Local $tolerance = 150
Local $transparency = 0

$file = "\Desktop\imagesearch\cas.png"
sleep(5000)

while true
    dg_get_images()
    sleep(1000)
Wend

Func dg_get_images()
   $x1=0
   $y1=0

   do
      $result =  _ImageSearchArea($file, 1, $left, $top, $right, $bottom, $x1, $y1, $tolerance, $transparency)
   until $result = 1;

   if $result=1 Then
      SoundPlay(@WindowsDir & "\media\tada.wav", 1)
   EndIf
EndFunc

The point is now i got several pictures like cas.png, cis.png, cod,png etc...

First thing i wanna get working is that if cas.png or cis.png or cod.png is found the sound tada.wav should be played.

 

someone please be so cind and help me quickly with this?

 

 

Share this post


Link to post
Share on other sites
svenjatzu

can it work like this

$file1 = "\Desktop\imagesearch\cos.png"
$file = "\Desktop\imagesearch\cas.png"
sleep(5000)

while true
    dg_get_images()
    sleep(1000)
Wend

Func dg_get_images()
   $x1=0
   $y1=0

   do
      $result =  _ImageSearchArea($file, 1, $left, $top, $right, $bottom, $x1, $y1, $tolerance, $transparency)
   until $result = 1;

   if $result=1 Then
      SoundPlay(@WindowsDir & "\media\tada.wav", 1)
   EndIf
EndFunc

or

Func dg_get_images()
   $x1=0
   $y1=0

   do
      $result =  _ImageSearchArea($file1, 1, $left, $top, $right, $bottom, $x1, $y1, $tolerance, $transparency)
   until $result = 1;

   if $result=1 Then
      SoundPlay(@WindowsDir & "\media\tada.wav", 1)
   EndIf
EndFunc

then

playsound?

 

Share this post


Link to post
Share on other sites
water

This won't work as you can't have two functions with the same name.
What do you ant to do when an images gets found at the end? Now you just play a sound.

Depending on your goal we might suggest a more reliable way to solve your problem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
svenjatzu

hi water,

im building a tool for my work where i can search for pictures with.

i think imagesearch is the beast way to do it due to we work alot of with java and i dont think its possible to read out numbers out of java with autoit?

yas thats right it plays a sound thats all it should do. its about when special numbers appear i need to act but i cant stare at the monitor all the day.

so what i try to create is a tool that alarms me when eg numbers around 1-120, 120-240, and 250-360 appear 2 times reapeating  sending sound tada and on 3 times repeat it should play another warning sound.

Share this post


Link to post
Share on other sites
water

These numbers appear in a ascending order? Means you have to wait until 1-120 appears. When found wait for 120-240. When found wait for 250-360.
Or can they all appear in any order?

When a picture gets found how long does it stay on the screen (and then disappears) so you can tell it was found 2 or 3 times?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
svenjatzu

they can apprear in any order

thats why i need a warning system that tells me when a block of numbers appears twice or three times

Share this post


Link to post
Share on other sites
water
Posted (edited)
#include <ImageSearch.au3>

Local $iLeft = 15, $iTop = 645, $iRight = 289, $iBottom = 798, $iTolerance = 150, $iTransparency = 0, $x1 = 0, $y1 = 0
Local $aImages[][] = [["\Desktop\imagesearch\cas.png", 0], ["\Desktop\imagesearch\cos.png", 0]]
While True
    For $i = 0 To UBound($aImages, 1) - 1
        If _ImageSearchArea($aImages[$i][0], 1, $iLeft, $iTop, $iRight, $iBottom, $x1, $y1, $iTolerance, $iTransparency) Then $aImages[$i][0] = $aImages[$i][0] + 1
        If $aImages[$i][0] = 2 Then SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        If $aImages[$i][0] = 3 Then 
            SoundPlay(@WindowsDir & "\media\othersound.wav", 1)
            $aImages[$i][0] = 0
        EndIf
    Next
WEnd

The count for each images is reset as soon as the image got found 3 times.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
svenjatzu

i gonna try this, thanks : )

 

Share this post


Link to post
Share on other sites
svenjatzu

so then theres another question,

how can i include several numbers, eg the range of  250-360 is saved in 12 numbers, 250 260 270 280 etc,

i think its this part

Local $aImages[][] = [["\Desktop\imagesearch\cas.png", 0], ["\Desktop\imagesearch\cos.png", 0]]

where i can add the numbers 250 - 360 like this

Local $aImages[][] = [["\Desktop\imagesearch\250.png", 0], ["\Desktop\imagesearch\260.png", 0], ["\Desktop\imagesearch\270.png", 0], ["\Desktop\imagesearch\280.png", 0], ["\Desktop\imagesearch\290.png", 0], ["\Desktop\imagesearch\300.png", 0], ["\Desktop\imagesearch\310.png", 0], ["\Desktop\imagesearch\320.png", 0], ["\Desktop\imagesearch\330.png", 0], ["\Desktop\imagesearch\340.png", 0], ["\Desktop\imagesearch\350.png", 0], ["\Desktop\imagesearch\360.png", 0]]

?

and next question then is, if i dont want to make 3 .exe running at same time i think i need to do it like this

#include <ImageSearch.au3>

Local $iLeft = 15, $iTop = 645, $iRight = 289, $iBottom = 798, $iTolerance = 150, $iTransparency = 0, $x1 = 0, $y1 = 0
Local $aImages[][] = [["\Desktop\imagesearch\cas.png", 0], ["\Desktop\imagesearch\cos.png", 0]]
Local $bImages[][] = [["\Desktop\imagesearch\cas.png", 0], ["\Desktop\imagesearch\cos.png", 0]]
Local $cImages[][] = [["\Desktop\imagesearch\cas.png", 0], ["\Desktop\imagesearch\cos.png", 0]]
While True
    For $i = 0 To UBound($aImages, 1) - 1
        If _ImageSearchArea($aImages[$i][0], 1, $iLeft, $iTop, $iRight, $iBottom, $x1, $y1, $iTolerance, $iTransparency) Then $aImages[$i][0] = $aImages[$i][0] + 1
        If $aImages[$i][0] = 2 Then SundPlay(@WindowsDir & "\media\tada.wav", 1)
        If $aImages[$i][0] = 3 Then 
            SoundPlay(@WindowsDir & "\media\othersound.wav", 1)
            $aImages[$i][0] = 0
        EndIf
        For $i = 0 To UBound($bImages, 1) - 1
        If _ImageSearchArea($bImages[$i][0], 1, $iLeft, $iTop, $iRight, $iBottom, $x1, $y1, $iTolerance, $iTransparency) Then $aImages[$i][0] = $bImages[$i][0] + 1
        If $bImages[$i][0] = 2 Then SundPlay(@WindowsDir & "\media\tada.wav", 1)
        If $bImages[$i][0] = 3 Then 
            SoundPlay(@WindowsDir & "\media\othersound.wav", 1)
            baImages[$i][0] = 0
        EndIf
            For $i = 0 To UBound($cImages, 1) - 1
        If _ImageSearchArea($cImages[$i][0], 1, $iLeft, $iTop, $iRight, $iBottom, $x1, $y1, $iTolerance, $iTransparency) Then $cImages[$i][0] = $cImages[$i][0] + 1
        If $cImages[$i][0] = 2 Then SundPlay(@WindowsDir & "\media\tada.wav", 1)
        If $cImages[$i][0] = 3 Then 
            SoundPlay(@WindowsDir & "\media\othersound.wav", 1)
            $cImages[$i][0] = 0
        EndIf
    Next
WEnd

 

i guess this could work?

Share this post


Link to post
Share on other sites
water
13 minutes ago, svenjatzu said:

where i can add the numbers 250 - 360 like this

Perfect solution as you describe it.

Why do you need to run the imagesearch 3 times looging for the same images?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
svenjatzu

thats the point im not so reql experienced in coding so my first thougt was so i can run 3 exes with your code for the 3 different ranges of numbers.

now the thing is the imagesearch is somehow slow, is it possible to speed it up a bit?

Share this post


Link to post
Share on other sites
svenjatzu

hm now i again got this error

 

"C:\Program Files (x86)\AutoIt3\Include\ImageSearch.au3" (52) : ==> Subscript used on non-accessible variable.:
if $result[0]="0" then return 0
if $result^ ERROR

Share this post


Link to post
Share on other sites
svenjatzu
21 minutes ago, svenjatzu said:

hm now i again got this error

 

"C:\Program Files (x86)\AutoIt3\Include\ImageSearch.au3" (52) : ==> Subscript used on non-accessible variable.:
if $result[0]="0" then return 0
if $result^ ERROR

this solved by replacing path with @desktopdir

Share this post


Link to post
Share on other sites
svenjatzu
1 hour ago, water said:
#include <ImageSearch.au3>

Local $iLeft = 15, $iTop = 645, $iRight = 289, $iBottom = 798, $iTolerance = 150, $iTransparency = 0, $x1 = 0, $y1 = 0
Local $aImages[][] = [["\Desktop\imagesearch\cas.png", 0], ["\Desktop\imagesearch\cos.png", 0]]
While True
    For $i = 0 To UBound($aImages, 1) - 1
        If _ImageSearchArea($aImages[$i][0], 1, $iLeft, $iTop, $iRight, $iBottom, $x1, $y1, $iTolerance, $iTransparency) Then $aImages[$i][0] = $aImages[$i][0] + 1
        If $aImages[$i][0] = 2 Then SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        If $aImages[$i][0] = 3 Then 
            SoundPlay(@WindowsDir & "\media\othersound.wav", 1)
            $aImages[$i][0] = 0
        EndIf
    Next
WEnd

The count for each images is reset as soon as the image got found 3 times.

hmm this doesnt work for me, i open the picture with what my former code worked closed it again and reopened it again many times, waiting in between for a minute but it doesnt run the sound so i changed it to msgbox but also no msg is popping up.

what do i do wrong? maybe its a prob with the path @desktopdir\imagesearch\cas.png?

Share this post


Link to post
Share on other sites
water

I know nothing about the _ImageSearch UDF but I suggest to check the return values of the function. This tells oyu what goes wrong.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

×