|
Post by Varchuu on Dec 8, 2019 17:00:41 GMT
Fairly certain this is just me being somewhat of a beginner with this, but I'm having trouble with recognizing an image. First, let me explain the situation:
I wish to check the marked regions here and compare them to a collection of images like these two. To do that, I'm using the function posted here. Code looks like this:
function ankuluaUtils.existsMultiMax(target, region) local maxScore = 0 local maxIndex = 0 local match
for i, t in ipairs(target) do if (region:exists(t, 0)) then -- check once local score = getLastMatch():getScore() if (score > maxScore) then maxScore = score maxIndex = i match = getLastMatch() end end end
if (maxScore == 0) then return -1 end return maxIndex, match end
-- Search the given region for a number. If 0 it is always 100, else it's number x 10. If no number, then no crit. getCardCrit = function(region) local targetArray = { SharedImagePath .. "Crit1.png", SharedImagePath .. "Crit2.png", SharedImagePath .. "Crit3.png", SharedImagePath .. "Crit4.png", SharedImagePath .. "Crit5.png", SharedImagePath .. "Crit6.png", SharedImagePath .. "Crit7.png", SharedImagePath .. "Crit8.png", SharedImagePath .. "Crit9.png", SharedImagePath .. "Crit0.png" }
local index, match = _ankuluaUtils.existsMultiMax(targetArray, region)
if (index == -1) then return CARD_CRIT.ZERO else return CARD_CRIT[index + 1] end
end
CARD_CRIT is simply an enum that returns a value from 1.0 to 2.0.
My issue now is that the region:exists() fails and as a result it never enters the score comparison. Again, fairly certain I'm just stupid and am missing something basic. Would appreciate any help.
|
|
|
Post by AnkuLua on Dec 8, 2019 23:59:28 GMT
1. Make sure that you have set the correct comparing and script dimensions. ankulua.boards.net/thread/7/settings#setCompareDimension2. Start with basic exists function. You can highlight region to make sure the region set correctly. For example, Settings:setScriptDimension(true, 1280) Settings:setCompareDimension(true, 1280) reg = Region(20, 30, 40, 50) reg:highlight(1) if (reg:exists("target.png")) then print("It works!") else print("Not found") end
|
|
|
Post by Varchuu on Dec 9, 2019 1:53:37 GMT
Alright, I've made a test script with the bare minimum as you recommended. Only difference is that I've put the dimensions to 1920, as that's my phone's default. I can confirm that the region is in the correct spot. Sadly, still no match. Here's the code:
local reg = Region(123, 530, 37, 70) local target = "Crit1.png" reg:highlight(1) if (reg:exists(target)) then print("It works!") else print("Not found") end I do believe this means it's probably an issue with the images. Any specific conventions I need to keep for them? I've simply cut them out of a screenshot and removed the background.
|
|
|
Post by AnkuLua on Dec 9, 2019 2:18:02 GMT
Make sure that the original image with background works. If still with problem, please share the screenshot and images.
|
|
|
Post by Varchuu on Dec 9, 2019 2:31:37 GMT
Sadly, still no luck.
1. Base Image, as seen on screen. Focus is on the first 1, to the left. 2. Cut Number, only containing the 1. Straight from the screenshot. 3. Stripped Number, from another picture, background cut for transparency and cropped. In case it matters, the numbers are moving slightly, top-bottom. Hence why I made the region bigger to account for that.
|
|
|
Post by AnkuLua on Dec 9, 2019 5:52:09 GMT
Try the cut number, it should work. As for the stripped number, it's bigger than the original one. Maybe something wrong when you editing. You can cut the background to black. It should work.
|
|
|
Post by Varchuu on Dec 9, 2019 6:24:54 GMT
I'm afraid it's still not working. By cut to black I assume like this? Sadly it's getting late here, so I think I'm going to clear my head by sleeping. Maybe I'll find a solution tomorrow.
Either way, thanks a lot for the help, I'm really not sure what's going wrong here. Is there perhaps a way to take the snapshot of the region and save it somewhere? I'd like to compare what is being used with my pattern.
|
|
|
Post by AnkuLua on Dec 9, 2019 7:46:31 GMT
I'm afraid it's still not working. By cut to black I assume like this? Sadly it's getting late here, so I think I'm going to clear my head by sleeping. Maybe I'll find a solution tomorrow.
Either way, thanks a lot for the help, I'm really not sure what's going wrong here. Is there perhaps a way to take the snapshot of the region and save it somewhere? I'd like to compare what is being used with my pattern.
Try lowering the similarity. You can crop the image with this ankulua.boards.net/thread/531/tool-snapyourscript
|
|