Что нового

не работает скрипт поиска пикселей

S_K

Новичок
Сообщения
30
Репутация
0
Описание:
не работает скрипт, он должен искать красною точку с какою рядом ещё 2 цвета

Примечания:
Код:
HotKeySet("{ESC}", "_Exit")
HotKeySet("{F3}", "Find")

Func _Exit()
    Exit 0
EndFunc

func Find()
  $x = 0
  $y = 0
  $xx = 0
  $zz = 0
  while 1

   $pos=PixelSearch($x,$y,@DesktopWidth,@DesktopHeight,0xED1C24,2,2) ;центр
    if not @error then
    if $pos[0] <> $xx then

   PixelSearch($pos[0],$pos[1]+1,$pos[0],$pos[1],0xB5E61D,1);вниз от центра
	 if not @error then

   PixelSearch($pos[0],$pos[1]-1,$pos[0],$pos[1],0xFFC90E,1);вверх от центра
     if not @error then

    ConsoleWrite(@CR&$pos[0]&" ; "&$pos[1])

      MouseMove($pos[0],$pos[1],5)
      sleep(200)
      MouseDown("left")
      Sleep(200)
      MouseUp("left")

  endif
  endif
  endif
  endif

    $y+=1
    if $y > @DesktopHeight Then
      if $x > @DesktopWidth Then ExitLoop
      $y = 0
      $x+=@DesktopWidth
    endif
        if not @error then
$xx = $pos[0]
endif
  wend
endfunc

while 1
  sleep(100)
  WEnd
 

Вложения

  • 1pixel (100%).png
    1pixel (100%).png
    288 байт · Просмотры: 148

qqww22

Новичок
Сообщения
115
Репутация
4
Код:
HotKeySet("{ESC}", "_Exit")
HotKeySet("{F3}", "Find")

Func _Exit()
    Exit 0
EndFunc
global $red = 0x00EA282E
global $yellow = 0x0FCF719
func Find()
  $x = 0
  $y = 0
  $xx = 0
  $zz = 0
  while 1

   $pos=PixelSearch($x,$y,@DesktopWidth,@DesktopHeight,$red,2,2) ;центр
    if not @error then
    if $pos[0] <> $xx then

   $pos=PixelSearch($pos[0],$pos[1],@DesktopWidth,@DesktopHeight,$yellow,2,2) ;центр
   if not @error then
      $pos=PixelSearch($pos[0],$pos[1],@DesktopWidth,@DesktopHeight,$red,2,2) ;центр
   if not @error then
      MouseMove($pos[0],$pos[1],5)
      sleep(200)
      MouseDown("left")
      Sleep(200)
      MouseUp("left")
endif
  endif
endif
endif


    $y+=20
    if $y > @DesktopHeight Then
      if $x > @DesktopWidth Then ExitLoop
      $y = 0
      $x+=@DesktopWidth
    endif
        if not @error then
$xx = $pos[0]
endif
  wend
endfunc

while 1
  sleep(100)
  WEnd
 

InnI

AutoIT Гуру
Сообщения
4,922
Репутация
1,432
S_K
Вашу картинку на этой странице находит
Код:
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "_Exit")
HotKeySet("{F3}", "Find")

While Sleep(100)
WEnd

Func Find()
  $Array = _PixelGetArray(0, 0, @DesktopWidth, @DesktopHeight, 0xED1C24)
  If Not $Array[0][0] Then
    MsgBox(0, "", "Не найдены опорные пиксели")
    Return
  EndIf
  For $i = 1 To $Array[0][0]
    If GetSurround($Array[$i][0], $Array[$i][1], 0xFFF200, 0x00A2E8, 0xFFC90E, 0xB5E61D) Then
      MouseMove($Array[$i][0], $Array[$i][1], 0)
      MsgBox(0, "", "Найдено: X=" & $Array[$i][0] & ", Y=" & $Array[$i][1])
      ExitLoop
    EndIf
  Next
  If $i > $Array[0][0] Then MsgBox(0, "", "Не найдены окружающие пиксели")
EndFunc

Func _PixelGetArray($i_X, $i_Y, $i_Width, $i_Height, $i_Color, $h_Wnd = 0, $f_FirstOnly = False)
  Local $i_Size = $i_Width * $i_Height, $a_Pixels[$i_Size + 1][2] = [[0]], $h_DC, $h_MemDC, $h_Bitmap, $t_Bits, $i_Index
  $h_DC = _WinAPI_GetDC($h_Wnd)
  $h_MemDC = _WinAPI_CreateCompatibleDC($h_DC)
  $h_Bitmap = _WinAPI_CreateCompatibleBitmap($h_DC, $i_Width, $i_Height)
  _WinAPI_SelectObject($h_MemDC, $h_Bitmap)
  _WinAPI_BitBlt($h_MemDC, 0, 0, $i_Width, $i_Height, $h_DC, $i_X, $i_Y, $SRCCOPY)
  _WinAPI_DeleteDC($h_MemDC)
  _WinAPI_ReleaseDC($h_Wnd, $h_DC)
  $t_Bits = DllStructCreate('dword[' & $i_Size & ']')
  $p_Bits = DllStructGetPtr($t_Bits)
  _WinAPI_GetBitmapBits($h_Bitmap, 4 * $i_Size, $p_Bits)
  _WinAPI_DeleteObject($h_Bitmap)
  For $i = 0 To $i_Height - 1
    For $j = 0 To $i_Width - 1
      $i_Index += 1
      If BitAND(DllStructGetData($t_Bits, 1, $i_Index), 0x00FFFFFF) = $i_Color Then
        $a_Pixels[0][0] += 1
        $a_Pixels[$a_Pixels[0][0]][0] = $j + $i_X
        $a_Pixels[$a_Pixels[0][0]][1] = $i + $i_Y
        If $f_FirstOnly Then ExitLoop 2
      EndIf
    Next
  Next
  ReDim $a_Pixels[$a_Pixels[0][0] + 1][2]
  Return $a_Pixels
EndFunc

Func GetSurround($X, $Y, $Left, $Right, $Up, $Down)
  If  PixelGetColor($X - 1, $Y) = $Left _
  And PixelGetColor($X + 1, $Y) = $Right _
  And PixelGetColor($X, $Y - 1) = $Up _
  And PixelGetColor($X, $Y + 1) = $Down Then Return True
  Return False
EndFunc

Func _Exit()
  Exit
EndFunc
 

qqww22

Новичок
Сообщения
115
Репутация
4
Re: не работает скрипт поиска пикселей:

S_K сказал(а):
ты проверял свой скрипт на работоспособность?

qqww22 сказал(а):
Код:
HotKeySet("{ESC}", "_Exit")
HotKeySet("{F3}", "Find")

Func _Exit()
    Exit 0
EndFunc
global $red = 0x00EA282E
global $yellow = 0x0FCF719
func Find()
  $x = 0
  $y = 0
  $xx = 0
  $zz = 0
  while 1

   $pos=PixelSearch($x,$y,@DesktopWidth,@DesktopHeight,$red,2,2) ;центр
    if not @error then
    if $pos[0] <> $xx then

   $pos=PixelSearch($pos[0],$pos[1],@DesktopWidth,@DesktopHeight,$yellow,2,2) ;центр
   if not @error then
      $pos=PixelSearch($pos[0],$pos[1],@DesktopWidth,@DesktopHeight,$red,2,2) ;центр
   if not @error then
      MouseMove($pos[0],$pos[1],5)
      sleep(200)
      MouseDown("left")
      Sleep(200)
      MouseUp("left")
endif
  endif
endif
endif


    $y+=20
    if $y > @DesktopHeight Then
      if $x > @DesktopWidth Then ExitLoop
      $y = 0
      $x+=@DesktopWidth
    endif
        if not @error then
$xx = $pos[0]
endif
  wend
endfunc

while 1
  sleep(100)
  WEnd
Цвета смени на свои,твои цвета в твоём примере картинки у меня не находил по этому вписал свои.
 
Автор
S_K

S_K

Новичок
Сообщения
30
Репутация
0
спасибо, но он очень медленно работает :( может можно как-то увеличить скорость работы вашего скрипта?

InnI сказал(а):
S_K

Вашу картинку на этой странице находит
Код:
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "_Exit")
HotKeySet("{F3}", "Find")

While Sleep(100)
WEnd

Func Find()
  $Array = _PixelGetArray(0, 0, @DesktopWidth, @DesktopHeight, 0xED1C24)
  If Not $Array[0][0] Then
    MsgBox(0, "", "Не найдены опорные пиксели")
    Return
  EndIf
  For $i = 1 To $Array[0][0]
    If GetSurround($Array[$i][0], $Array[$i][1], 0xFFF200, 0x00A2E8, 0xFFC90E, 0xB5E61D) Then
      MouseMove($Array[$i][0], $Array[$i][1], 0)
      MsgBox(0, "", "Найдено: X=" & $Array[$i][0] & ", Y=" & $Array[$i][1])
      ExitLoop
    EndIf
  Next
  If $i > $Array[0][0] Then MsgBox(0, "", "Не найдены окружающие пиксели")
EndFunc

Func _PixelGetArray($i_X, $i_Y, $i_Width, $i_Height, $i_Color, $h_Wnd = 0, $f_FirstOnly = False)
  Local $i_Size = $i_Width * $i_Height, $a_Pixels[$i_Size + 1][2] = [[0]], $h_DC, $h_MemDC, $h_Bitmap, $t_Bits, $i_Index
  $h_DC = _WinAPI_GetDC($h_Wnd)
  $h_MemDC = _WinAPI_CreateCompatibleDC($h_DC)
  $h_Bitmap = _WinAPI_CreateCompatibleBitmap($h_DC, $i_Width, $i_Height)
  _WinAPI_SelectObject($h_MemDC, $h_Bitmap)
  _WinAPI_BitBlt($h_MemDC, 0, 0, $i_Width, $i_Height, $h_DC, $i_X, $i_Y, $SRCCOPY)
  _WinAPI_DeleteDC($h_MemDC)
  _WinAPI_ReleaseDC($h_Wnd, $h_DC)
  $t_Bits = DllStructCreate('dword[' & $i_Size & ']')
  $p_Bits = DllStructGetPtr($t_Bits)
  _WinAPI_GetBitmapBits($h_Bitmap, 4 * $i_Size, $p_Bits)
  _WinAPI_DeleteObject($h_Bitmap)
  For $i = 0 To $i_Height - 1
    For $j = 0 To $i_Width - 1
      $i_Index += 1
      If BitAND(DllStructGetData($t_Bits, 1, $i_Index), 0x00FFFFFF) = $i_Color Then
        $a_Pixels[0][0] += 1
        $a_Pixels[$a_Pixels[0][0]][0] = $j + $i_X
        $a_Pixels[$a_Pixels[0][0]][1] = $i + $i_Y
        If $f_FirstOnly Then ExitLoop 2
      EndIf
    Next
  Next
  ReDim $a_Pixels[$a_Pixels[0][0] + 1][2]
  Return $a_Pixels
EndFunc

Func GetSurround($X, $Y, $Left, $Right, $Up, $Down)
  If  PixelGetColor($X - 1, $Y) = $Left _
  And PixelGetColor($X + 1, $Y) = $Right _
  And PixelGetColor($X, $Y - 1) = $Up _
  And PixelGetColor($X, $Y + 1) = $Down Then Return True
  Return False
EndFunc

Func _Exit()
  Exit
EndFunc
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
S_K,
Предупреждение За нарушение общих правил (пункт В.2):
Старайтесь избегать “Over quoting” (преувеличенное цитирование) - цитируйте только необходимую часть сообщения, которая наилучшим образом подчеркнёт суть цитируемого.


С уважением, ваш Глобальный модератор.
 

qqww22

Новичок
Сообщения
115
Репутация
4
S_K сказал(а):
спасибо, но он очень медленно работает :( может можно как-то увеличить скорость работы вашего скрипта?
Попробуй пример Inni,возможно он быстрее.
 
Автор
S_K

S_K

Новичок
Сообщения
30
Репутация
0
Re: не работает скрипт поиска пикселей:

цвета я сразу сменил

qqww22 сказал(а):
Цвета смени на свои,твои цвета в твоём примере картинки у меня не находил по этому вписал свои.
 
Верх