Здравствуйте, гость ( Вход | Регистрация )

 
Ответить в эту темуОткрыть новую тему
> FindColor in image
kaltorak
сообщение 19.3.2024, 21:10
Сообщение #1


**

Neophyte
Сообщений: 21
Регистрация: 12.10.2021
Группа: Пользователи
Наличность: 6
Пользователь №: 20.106
Возраст: 30



Hey guys.

I would like to know if it is possible to search for a color in an image. I'm using printscreen to capture a part of a minimized window:

Код
printscreen #handle #x #y 465 465 c:\monster.png


Then I needed to identify whether the color 66047 is present in this monster.png image. If so, Uopilot will know that there are targets within range and will use the area skill to eliminate them.

I looked at the Wiki and some threads and couldn't find anything along those lines.
Пользователь в офлайнеDelete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения
nykep
сообщение 20.3.2024, 14:41
Сообщение #2


****

Apprentice
Сообщений: 233
Регистрация: 1.9.2012
Группа: Пользователи
Наличность: 1213
Пользователь №: 15.246
Возраст: 25



Код
--lua
local screen, width, height = getimage (0, 0 ,1920, 1080)
local a = findcolor (0, 0 ,1920, 1080, 3145726, '%arr', screen, 1, 0)
if a then
    move (arr[1][1], arr[1][2])
end
deleteimage(screen)

Im not very familiar with getimage. This work only in active window. And there is some bugs, maybe someone else will answer better.
https://uopilot.tati.pro/index.php?title=Getimage_(Lua)
https://uopilot.tati.pro/index.php?title=Findimage_(Lua)
Пользователь в онлайне!Delete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения
kaltorak
сообщение 20.3.2024, 15:58
Сообщение #3


**

Neophyte
Сообщений: 21
Регистрация: 12.10.2021
Группа: Пользователи
Наличность: 6
Пользователь №: 20.106
Возраст: 30



Цитата(nykep @ 20.3.2024, 14:41) *

Код
--lua
local screen, width, height = getimage (0, 0 ,1920, 1080)
local a = findcolor (0, 0 ,1920, 1080, 3145726, '%arr', screen, 1, 0)
if a then
    move (arr[1][1], arr[1][2])
end
deleteimage(screen)

Im not very familiar with getimage. This work only in active window. And there is some bugs, maybe someone else will answer better.
https://uopilot.tati.pro/index.php?title=Getimage_(Lua)
https://uopilot.tati.pro/index.php?title=Findimage_(Lua)


First thanks for the answer.

So, my problem is precisely this, in the scenario I'm working on I can't open the image within an application to analyze it, I needed the script to read the file in the background. I managed to apply this logic in Python, but it was cumbersome, I wanted to try to run it directly within Uopilot, whether using the standard language or calling a second script in Lua.
Пользователь в офлайнеDelete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения
nykep
сообщение 20.3.2024, 16:42
Сообщение #4


****

Apprentice
Сообщений: 233
Регистрация: 1.9.2012
Группа: Пользователи
Наличность: 1213
Пользователь №: 15.246
Возраст: 25



Код
--lua
local screen = loadimage([[E:\screen.bmp]]) -- screen - address in memory
local a = findcolor (0, 0 ,1920, 1080, 66047, '%arr', screen, 1, 0)
if a then
    move (arr[1][1], arr[1][2])
end
deleteimage(screen)

I think this is what you need, BUT some coordinate shifts are possible here. I don't know how exactly this works.
https://uopilot.uokit.com/wiki/index.php?title=LoadImage
https://uopilot.uokit.com/wiki/index.php?ti...Loadimage_(Lua)
Пользователь в онлайне!Delete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения
kaltorak
сообщение 20.3.2024, 19:16
Сообщение #5


**

Neophyte
Сообщений: 21
Регистрация: 12.10.2021
Группа: Пользователи
Наличность: 6
Пользователь №: 20.106
Возраст: 30



Цитата(nykep @ 20.3.2024, 16:42) *

Код
--lua
local screen = loadimage([[E:\screen.bmp]]) -- screen - address in memory
local a = findcolor (0, 0 ,1920, 1080, 66047, '%arr', screen, 1, 0)
if a then
    move (arr[1][1], arr[1][2])
end
deleteimage(screen)

I think this is what you need, BUT some coordinate shifts are possible here. I don't know how exactly this works.
https://uopilot.uokit.com/wiki/index.php?title=LoadImage
https://uopilot.uokit.com/wiki/index.php?ti...Loadimage_(Lua)


Thank you very much! In lua it worked perfectly, it looked like this:

Код
--lua
local screen = loadimage([[C:\test1.png]])
local a = findcolor (0, 0 ,1920, 1080, 14085954 , '%arr', screen, 1, 0)
if a then
    log ("True")
    else
        log ("False")
end
deleteimage(screen)


But my main script is not in lua, I did it natively, I tried using loadimage as follows:

Код
set %a [1] LoadImage (C:\test1.png)
set #a findcolor (0 0 1920 1080 (14085954 ) %arr 2 )
if #a > 0
    log True
    else
        log False
end_if


If I could make the logic work natively without calling another lua script in uopilot it would be better. Do you think it is possible to call the image in memory using findcolor after loadimage without using --lua?
Пользователь в офлайнеDelete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения
nykep
сообщение 20.3.2024, 19:51
Сообщение #6


****

Apprentice
Сообщений: 233
Регистрация: 1.9.2012
Группа: Пользователи
Наличность: 1213
Пользователь №: 15.246
Возраст: 25



try this
Код
set %a [1] LoadImage (C:\test1.png)
set #a findcolor (0 0 1920 1080 (14085954) %arr %a[1 1])
if #a > 0
    log True
    else
        log False
end_if
set $b deleteImage (%a [1 1])
Пользователь в онлайне!Delete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения
kaltorak
сообщение 20.3.2024, 20:06
Сообщение #7


**

Neophyte
Сообщений: 21
Регистрация: 12.10.2021
Группа: Пользователи
Наличность: 6
Пользователь №: 20.106
Возраст: 30



Цитата(nykep @ 20.3.2024, 19:51) *

try this
Код
set %a [1] LoadImage (C:\test1.png)
set #a findcolor (0 0 1920 1080 (14085954) %arr %a[1 1])
if #a > 0
    log True
    else
        log False
end_if
set $b deleteImage (%a [1 1])



Dude, it worked perfectly, you're a genius, thank you very much!
I read all the findcolor documentation and would never know that it could be used this way.

I sent you a message, take a look later.

Thank you very much brother!
Пользователь в офлайнеDelete PostОтправить личное сообщение
Вернуться в начало страницы
+Ответить с цитированием данного сообщения

Ответить в эту темуОткрыть новую тему
2 чел. читают эту тему (гостей: 2, скрытых пользователей: 0)
Пользователей: 0

 

- Текстовая версия | Версия для КПК Сейчас: 27.4.2024, 13:13
Designed by Nickostyle