|
Post by AnkuLua on Dec 9, 2018 14:26:57 GMT
Current smart phones have many screen aspect ratios, from 16:10 to 21:9. How does the game handle the different aspect ratios? There are some fixed rules. We will talk one of those rules and teach you how to write scripts that running on different aspect ratios.
Basically, this type of games doesn't change the major icons on different screen ratios. For example, the Summoners War screenshots on 1280x720 and 1440x720 are You can try the games on devices or emulators with different aspect ratios. It would be easier to try it on emulators. You can just set the emulator to different aspect ratios. For these games, we can just use following script to adjust the compare dimensions. function setupDimension(height) local deviceWidth = getRealScreenSize():getX() local deviceHeight= getRealScreenSize():getY() local widthOverHeight = deviceWidth / deviceHeight if (widthOverHeight > (16/9 + 0.1)) then local newDimension = widthOverHeight * height Settings:setCompareDimension(true, newDimension) print("new dimension = " .. newDimension) end end You should call this method after setting compare dimension to the width that the script is developed on. The parameter is the height that you develop the script. For example, if the script is developed in 1280x720. You should call the method by setupDimension(720). You may need to handle some region settings. Normally, it's ok to make the regions a little larger.
|
|
zouna
Contributors
Posts: 109
|
Post by zouna on Dec 23, 2018 5:40:06 GMT
Hey AnkuLua, this would benefit all functions which use the image recognition to find the Location to click or check. I have to use some static click() function calls. If I understand this correctly, my way to click(location) would not adjust location with something like Location(x+newDimensionDifference,y+newDimensionDifference) right? But I think I could add that difference myself. Just want to make sure I'm not trying to write something that might already be supported.
|
|
|
Post by AnkuLua on Dec 23, 2018 7:45:23 GMT
Hey AnkuLua, this would benefit all functions which use the image recognition to find the Location to click or check. I have to use some static click() function calls. If I understand this correctly, my way to click(location) would not adjust location with something like Location(x+newDimensionDifference,y+newDimensionDifference) right? But I think I could add that difference myself. Just want to make sure I'm not trying to write something that might already be supported. No, this does not benefit Location().
|
|
|
Post by whatever on May 29, 2019 3:04:29 GMT
Hi Ankulua,
I followed this post to implement my code but it doesn't work. Basically, I developed on 1280x720 device & try to run the code on 1440x720 device.
all_screen = Region(0, 0, 1280, 720)
function isLayout(image)
result = regionFindAllNoFindException(all_screen, image)
for i, m in ipairs(result) do
if (m:getScore() > 0.7) then
return true, m
end
end
return false
end Settings:setScriptDimension(true, 1280)
Settings:setCompareDimension(true, 1280)
Settings:set('MinSimilarity', 0.8) setupDimension(720)
The isLayout function used to check if the input image is in the current screen or not. But it only works on 1280x720 device. Can you take a look & show me how to make it work please?
|
|
|
Post by AnkuLua on May 29, 2019 12:10:36 GMT
Hi Ankulua, I followed this post to implement my code but it doesn't work. Basically, I developed on 1280x720 device & try to run the code on 1440x720 device. all_screen = Region(0, 0, 1280, 720)
function isLayout(image)
result = regionFindAllNoFindException(all_screen, image)
for i, m in ipairs(result) do
if (m:getScore() > 0.7) then
return true, m
end
end
return false
end Settings:setScriptDimension(true, 1280)
Settings:setCompareDimension(true, 1280)
Settings:set('MinSimilarity', 0.8) setupDimension(720)
The isLayout function used to check if the input image is in the current screen or not. But it only works on 1280x720 device. Can you take a look & show me how to make it work please? As it said in the thread. Please share the screenshots of both 1280x720 and 1440x720. If the icons are the same, you can use the setupDimension() function. Otherwise, you need to observe the screenshots and find the rules.
|
|
|
Post by whatever on May 30, 2019 23:26:00 GMT
Thank man. I got it.
|
|
|
Post by bielsantoro on Dec 4, 2019 6:48:11 GMT
Is there any smart way to benefit all static functions such as Location(), Click() or should I add every time the diff between the old dimension and the new one ?
|
|
|
Post by AnkuLua on Dec 6, 2019 11:50:00 GMT
Is there any smart way to benefit all static functions such as Location(), Click() or should I add every time the diff between the old dimension and the new one ? if screen aspect ratio is the same, then you don’t need to modify any code
|
|
|
Post by AnkuLua on Dec 6, 2019 11:50:04 GMT
Is there any smart way to benefit all static functions such as Location(), Click() or should I add every time the diff between the old dimension and the new one ? if screen aspect ratio is the same, then you don’t need to modify any code
|
|
|
Post by mcb345 on Apr 27, 2021 9:11:13 GMT
Is there any smart way to benefit all static functions such as Location(), Click() or should I add every time the diff between the old dimension and the new one ? if screen aspect ratio is the same, then you don’t need to modify any code What about transparent background ? Is it possible ? for instance, inventory tab in a game, you can imagine where the inventory is like 10-30% transparent, can we compare image to this ? up to this day, I couldnt succeed the attempts
|
|
|
Post by AnkuLua on Apr 28, 2021 0:35:20 GMT
if screen aspect ratio is the same, then you don’t need to modify any code What about transparent background ? Is it possible ? for instance, inventory tab in a game, you can imagine where the inventory is like 10-30% transparent, can we compare image to this ? up to this day, I couldnt succeed the attempts You can either set the similarity or use mask() in Pattern.
|
|
|
Post by learn777 on Sept 13, 2021 2:58:31 GMT
My initial test shows that this works on my device which has a 20:9 aspect ratio. However, I found the converted region too big. It falls way beyond the area which I intended to capture. Here's the code:
Settings:setCompareDimension(true, 1280)
Settings:setScriptDimension(true, 1280)
function setupDimension(height)
local deviceWidth = getRealScreenSize():getX()
local deviceHeight= getRealScreenSize():getY()
local widthOverHeight = deviceWidth / deviceHeight
if (widthOverHeight > (16/9 + 0.1)) then
local newDimension = widthOverHeight * height
Settings:setCompareDimension(true, newDimension)
print("new dimension = " .. newDimension)
end
end
setupDimension(720)
local myreg = Region(605, 0, 315, 160)
local speak
while (true) do
if (myreg:exists("kfd_normaltest.png", 0)) then
local image = myreg:getLastMatch()
local reg = Region(image:getX(), image:getY(), image:getW(), image:getH())
speak = region_to_string(myreg)
myreg:highlight()
toast("Con Region: " .. speak )
reg:highlight(5)
myreg:highlightOff()
end
wait(0.20)
end
I captured a screenshot of the actual converted region on the widescreen device and it became 1135, 0, 590, 300. The height almost doubled. My actual screen resolution is 2400 x 1080. How can I make it more accurate to the region I intended to capture?
|
|
|
Post by Exilereven on Sept 13, 2021 12:01:47 GMT
i feel like you got a couple things fishy right off the bat. your script is setup with 1280x720 16:9 ratio, and your phone is 20:9 using 2400x1080.
when you adjust your regions, your over adjusting them using the wrong calculations for region.
i would try setting up your new dimension as 1080 instead of 720, but use the same images you have been.
my first guess would be:
setupDimension(720)
if your gonna do this then make sure your phones resolution is also the same. You said at the bottom you ran 1080, try using
setupDimension(1080)?
does your game run in landscape or portrait mode when playing? i have the exact same resolution device, maybe i can help figure it out.
|
|
|
Post by learn777 on Sept 14, 2021 6:30:33 GMT
The script is made and is based on a 1280 x 720 resolution in LDPlayer. Now my mobile device's resolution is 2400 x 1080, 20:9 aspect ratio. I'd like to make the script written in LDPlayer to work with my device. Image detected works so far but declared regions are "off" the intended region. I'll try 1080 and see if it works.
|
|
|
Post by Exilereven on Sept 14, 2021 12:00:14 GMT
if you have access to the source code I could show you how to make it work for a 2400x1080 phone.(i have a xaiomi note 9, 2400x1080)
you say image matching works right?
whats the game? and are you the owner of the script?(edit source code)
|
|