Search code examples
image-processingautomationautoit

Detect all occurrences of same image


My script recognizes the given image, but if two of the same images are present it will ignore the second one. I want to count it as found 2 times at different locations. There are five rows where the same text-image can appear:

Screen

enter image description here

Image

enter image description here

Output from line 113

[Results found]: Additional Damage of Critical Hits +1% found.

Source code (excerpt)

Func Awakes_adoch()
   ToolTip('Scanning for adoch awakes', 0, 0)

   $adoch1 = _ImageSearchArea("images/adoch/adoch1.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch1 = 1) Then
      $awake_adoch_attribute_count += 1
   EndIf

   $adoch3 = _ImageSearchArea("images/adoch/adoch3.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch3 = 1) Then
      $awake_adoch_attribute_count += 3
   EndIf

   $adoch5 = _ImageSearchArea("images/adoch/adoch5.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch5 = 1) Then
      $awake_adoch_attribute_count += 5
   EndIf

   $adoch7 = _ImageSearchArea("images/adoch/adoch7.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch7 = 1) Then
      $awake_adoch_attribute_count += 7
   EndIf

   $adoch9 = _ImageSearchArea("images/adoch/adoch9.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch9 = 1) Then
      $awake_adoch_attribute_count += 9
   EndIf

   $adoch11 = _ImageSearchArea("images/adoch/adoch11.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch11 = 1) Then
      $awake_adoch_attribute_count += 11
   EndIf

   $adoch13 = _ImageSearchArea("images/adoch/adoch13.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch13 = 1) Then
      $awake_adoch_attribute_count += 13
   EndIf

   $adoch15 = _ImageSearchArea("images/adoch/adoch15.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch15 = 1) Then
      $awake_adoch_attribute_count += 15
   EndIf

   $adoch17 = _ImageSearchArea("images/adoch/adoch17.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch17 = 1) Then
      $awake_adoch_attribute_count += 17
   EndIf

   $adoch19 = _ImageSearchArea("images/adoch/adoch19.png", 1, 0, 0, 400, 390, $x, $y, 0)
   If ($adoch19 = 1) Then
      $awake_adoch_attribute_count += 19
   EndIf

   Sleep(50)
   ToolTip('[Scan]: Additional Damage of Critical Hits +' & $awake_adoch_attribute_count & '% found.', 0, 0)
EndFunc

Source code (full)

If the output window shows like below, it should be able to add up to 25:

Additional Damage of Critical Hits +3%
DEF + 40
Additional Damage of Critical Hits +3%
DEF + 4
Additional Damage of Critical Hits +19%

Another example:

enter image description here

I’m looking for a solution that doesn’t skip numbers or adds them from a previous shot to the next.

Source code (new)


Solution

  • relatively easy, as all searched images are below each other (would be much more difficult, when searched images were at random locations):

    #include "ImageSearch64.au3"
    
    $searchpath = "c:\users\50022505\Downloads\" ; where are my images?
    $x = 0 ; dummy parameter for coordinates
    $y = 0 ; dummy parameter for coordinates
    $Damage = 100
    
    ConsoleWrite("Initial Damage: " & $Damage & @CRLF)
    AddDamage()
    ConsoleWrite("Resulting Damage: " & $Damage & @CRLF)
    
    Func AddDamage()
        $Damage += GetLocations($searchpath & "adoch1.png")
        $Damage += GetLocations($searchpath & "adoch5.png") * 5
        $Damage += GetLocations($searchpath & "adoch9.png") * 9
        $Damage += GetLocations($searchpath & "adoch11.png") * 11
        Return $Damage
    EndFunc   ;==>AddDamage
    
    Func GetLocations($search)
        Local $Findings = 0, $found = 0
        Local $dx = 0, $dy = 0  ;sub coordinates
        While 1
            Local $found = _ImageSearchArea($search, 1, $dx, $dy, 400, 390, $x, $y, 0)
            If $found = 0 Then Return $Findings ; no more findings
            $Findings += 1
            $dy = $y ; set new coordinate window to search (excluding last finding)
        WEnd
    EndFunc   ;==>GetLocations