|
Post by learn777 on Apr 21, 2021 0:42:03 GMT
How do I highlight the region reg and the matched object during debug. As much as possible, I wouldn't want to stray away too far from the form/style below. I'm thinking of finding a way to capture reg:exists through a function so that whenever I call reg:exists() the region details will be captured and highlighted and do the same with click(reg:getLastMatch) but I can't figure a way to do it. Any idea would be appreciated.
local reg = Region(x, y, w, h)
if (reg:exists("image.png", 0) then click(reg:getLastMatch()) end
|
|
ikk
New Member
Discord: Oof#2074
Posts: 16
|
Post by ikk on Apr 21, 2021 4:53:03 GMT
This is the function I've created. May not be the /best/ way to do it, but this is how I do it.
Paramaters Explained: image = image / object you're looking for searchRegion = area on the screen you're searching for object maxAttempts = maximum attempts / number of screenshots it will re-take if didn't find upon first look minSimilarity = way to modify how close to the image before confirming it found it 0.0 - 1.0
function getRegionFromImage(image, searchRegion, maxAttempts, minSimilarity) Settings:set("MinSimilarity", minSimilarity) local timesChecked = 0 while (timesChecked < maxAttempts) do snapshot() if (searchRegion:exists(image, 0)) then local reg = searchRegion:getLastMatch() reg:highlight(0.5) if (reg ~= nil) then usePreviousSnap(false) return reg end end timesChecked = timesChecked + 1 usePreviousSnap(false) end usePreviousSnap(false) return nil end
|
|
|
Post by learn777 on Apr 21, 2021 7:38:17 GMT
Thanks for the input but I think your function works the same way as regionWaitMulti() which I wouldn't want to use if there's another more direct way of doing it. I think what I would like to understand is how the Region is passed to the exists() function whenever reg:exists() is called. I need something which can intercept the Region:exists(), analyze it and do something about the data gathered, such as highlighting the region while in debug mode.
|
|
|
Post by AnkuLua on Apr 22, 2021 0:24:42 GMT
Thanks for the input but I think your function works the same way as regionWaitMulti() which I wouldn't want to use if there's another more direct way of doing it. I think what I would like to understand is how the Region is passed to the exists() function whenever reg:exists() is called. I need something which can intercept the Region:exists(), analyze it and do something about the data gathered, such as highlighting the region while in debug mode. Region is an object and exists() is its function. To achieve what you want, you need to inherent and overwrite the Region object. Then overwrite the exists() function. orgRegion = Region
function Region(x, y, w, h) return myRegion:new(x, y, w, h) end
myRegion = {} function myRegion:new (x, y, w, h) local o = {reg = orgRegion(x, y, w, h)} setmetatable(o, self) self.__index = self return o end function myRegion:exists(target, seconds) seconds = seconds or 3.0 local match = self.reg:exists(target, seconds) if (match and debug) then match:highlight(1) end return match end function myRegion:printf(value) self.reg:highlight(value) end -- https://stackoverflow.com/questions/28016133/lua-metatable-how-to-forward-undefined-functions local handle = { __index = function(myRegion, name) myRegion[name] = function(...) __arg = {...} local s = string.format("return __arg[1].reg:%s(", name) if (#__arg >= 2) then s = s .. "__arg[2]" end for i = 3, #__arg do s = s .. string.format(", __arg[%d]", i) end s = s .. ")" return loadstring(s)() end return rawget(myRegion, name) end } setmetatable(myRegion, handle)
|
|
|
Post by learn777 on Apr 22, 2021 4:37:52 GMT
Thank you so much.. This is exactly what I'm looking for. Tested it and it highlights the matched image.. I guess it only needs a bit of tweaking to make it highlight the region where the image is being searched. What's good about this is there'll be no need to add extra functions inside the game scripts when debugging. I saved it on a lua file called debugger and then
if (debug) then dofile(localPath .. "lib/debugger.lua") end
doMain()
Thank you!!!
|
|
|
Post by learn777 on Apr 22, 2021 4:49:36 GMT
function myRegion:exists(target, seconds)
seconds = seconds or 3.0
local match = self.reg:exists(target, seconds)
if debug then self.reg:highlight(1.0) end
if (match and debug) then
match:highlight(1)
end
return match
end
|
|
|
Post by Exilereven on Apr 22, 2021 12:27:08 GMT
|
|
|
Post by learn777 on May 6, 2021 4:15:03 GMT
I haven't but I already looked at it.. It looks a bit too much for what I need, though. In case I need something more in-depth, I'll make sure I will try it.
|
|
|
Post by Exilereven on May 6, 2021 4:44:28 GMT
literally
your code
reg:exists('image.png')
Implementing new debug
Image:reg:exists('image.png')
then you can gain access to image highlight,humanoid click region, and boundary of actual image match by doing nothing but adding a dofile at the beginning of your script, and Image to the front of your image calls.
|
|
|
Post by learn777 on Jun 15, 2021 2:38:38 GMT
I just found out that this method is causing errors in OCR. It throws some error when in debug mode... I tried to figure out what can be changed in the code to make it work with OCR to no avail. I ended up making a work around which is to not run all OCRs when in debug mode. But of course it would mean that OCR can't be debugged. Any idea what can be changed in the code to make it work with OCR?
|
|