Post by AnkuLua on Sept 10, 2016 15:06:28 GMT
During the script development, it's nature to have some common libraries.
If you studied the script from us, you will find the file "commonLib.lua" under lib folder.
"commonLib.lua" is the collection of all common functions.
For common library, you are welcome to prvide any opinions.
If you have any function to add the library, please tell us.
Note: The library always changing. The library here may be different from the released scripts.
Download link
There are many function inside the common library.
Let's first talk about autoResize()
autoResize(target, defaultDimension, immersive, region)
Usage:
This function is used to help setting compareDimension. We know that compareDimension is always a headache.
With value from up and low 15% of defaultDimension, it will try to find the value making target most match, with highest score.
If region given, it will only search inside the region. That make searching faster.
It's very possible that the devices running your script is very different from the one that you develop scripts on. Run this function before other image recognization is always a good idea.
Parameter:
target: The target image, it should be Pattern object.
defaultDimension: The default (most possible) value of compareDimension. It's better that the value is the same as the value for your script.
immersive: The game is immersive (true) or not (false).
region: The region that the target is expected to be found.
Return value: The value with best match. If not found, return -1.
Explanation:
Part 1:
Default value matching
Lines 3~6: initialize and set region (if given).
Lines 7~11: If default value works, return it. Otherwise, set to use the same captured screen for following operations. It's faster without capturing screenshot for every recognization.
Lines 13~18: Reverse immersive and compares. Return the value if matching.
Part 2:
coarse searching
Lines 20~21: Set immersive to default value and set similar to 0.8.
Lines 22 ~32: Grain coarse searching: from -15% to +15%, do a recognization every 10. It the score decrease then remeber the dimesion with highest score.
Part 3:
fine searching
Line 34~47: Fine search: From -9 to +9 around value from coarse searching, do a searching for each value. Find the value with highest score.
Part 4:
Return the found value or -1 if not found.
For speeding the process, we make an assumption that there is only one peak.
Example:
To save the time for following execution, the value is save and restore with preferencePutNumber and preferenceGetNumber.
If you studied the script from us, you will find the file "commonLib.lua" under lib folder.
"commonLib.lua" is the collection of all common functions.
For common library, you are welcome to prvide any opinions.
If you have any function to add the library, please tell us.
Note: The library always changing. The library here may be different from the released scripts.
Download link
There are many function inside the common library.
Let's first talk about autoResize()
autoResize(target, defaultDimension, immersive, region)
Usage:
This function is used to help setting compareDimension. We know that compareDimension is always a headache.
With value from up and low 15% of defaultDimension, it will try to find the value making target most match, with highest score.
If region given, it will only search inside the region. That make searching faster.
It's very possible that the devices running your script is very different from the one that you develop scripts on. Run this function before other image recognization is always a good idea.
Parameter:
target: The target image, it should be Pattern object.
defaultDimension: The default (most possible) value of compareDimension. It's better that the value is the same as the value for your script.
immersive: The game is immersive (true) or not (false).
region: The region that the target is expected to be found.
Return value: The value with best match. If not found, return -1.
Explanation:
Part 1:
Default value matching
Lines 3~6: initialize and set region (if given).
Lines 7~11: If default value works, return it. Otherwise, set to use the same captured screen for following operations. It's faster without capturing screenshot for every recognization.
Lines 13~18: Reverse immersive and compares. Return the value if matching.
Part 2:
coarse searching
Lines 20~21: Set immersive to default value and set similar to 0.8.
Lines 22 ~32: Grain coarse searching: from -15% to +15%, do a recognization every 10. It the score decrease then remeber the dimesion with highest score.
Part 3:
fine searching
Line 34~47: Fine search: From -9 to +9 around value from coarse searching, do a searching for each value. Find the value with highest score.
Part 4:
Return the found value or -1 if not found.
For speeding the process, we make an assumption that there is only one peak.
Example:
-- ========== Settings ================
Settings:setCompareDimension(true, 1280)
Settings:setScriptDimension(true, 1280)
Settings:set("MinSimilarity", 0.8)
localPath = scriptPath()
dofile(localPath.."lib/commonLib.lua")
setImmersiveMode(true)
width = 1280
defaultDimension = preferenceGetNumber("defaultDimension", width)
--print("defaultDim = "..defaultDimension)
dimension = autoResize(Pattern("target.png"):similar(0.9), defaultDimension, true, centerRighterRegion)
if (dimension < 0 and defaultDimension ~= width) then
dimension = autoResize(Pattern("target.png"):similar(0.85), width, true, centerRighterRegion)
end
if (dimension < 0) then
scriptExit("Error: Can't find correct comparing dimension")
return
end
toast (""..dimension)
preferencePutNumber("defaultDimension", dimension)
To save the time for following execution, the value is save and restore with preferencePutNumber and preferenceGetNumber.