检测所有出现的相同图像

时间:2017-12-28 04:52:49

标签: image-processing automation autoit

我的脚本识别给定的图像,但如果存在两个相同的图像,它将忽略第二个图像。我想把它算作在不同地点找到2次。有五行可以显示相同的文本图像:

屏幕

enter image description here

图像

enter image description here

输出from line 113

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

源代码(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)

如果输出窗口如下所示,则应该最多可以添加25:

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

另一个例子:

enter image description here

我正在寻找一种不会跳过数字或将其从之前的镜头添加到下一个镜头的解决方案。

Source code (new)

1 个答案:

答案 0 :(得分:2)

相对容易,因为所有搜索过的图像都在彼此之下(当搜索到的图像位于随机位置时会更加困难):

#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