From a43674bcf7ebcf0ad9bbbff453616cadc110591b Mon Sep 17 00:00:00 2001 From: fe-art Date: Mon, 21 Oct 2024 19:54:53 +0200 Subject: [PATCH] add new images to detect screens + dimension scaling from screens.py to real screenshot size (to prevent misinterpretation) --- .../detectors/screen_detector.py | 13 ++++++++++--- clashroyalebuildabot/emulator/emulator.py | 3 ++- .../images/screen/in_game.jpg | Bin 951 -> 4933 bytes clashroyalebuildabot/images/screen/lobby.jpg | Bin 1142 -> 6867 bytes clashroyalebuildabot/namespaces/screens.py | 9 +++++---- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/clashroyalebuildabot/detectors/screen_detector.py b/clashroyalebuildabot/detectors/screen_detector.py index 8082135..723e886 100644 --- a/clashroyalebuildabot/detectors/screen_detector.py +++ b/clashroyalebuildabot/detectors/screen_detector.py @@ -5,6 +5,7 @@ from clashroyalebuildabot.constants import IMAGES_DIR from clashroyalebuildabot.namespaces import Screens +from clashroyalebuildabot.namespaces.screens import Screen class ScreenDetector: @@ -30,15 +31,21 @@ def _calculate_screen_hashes(self): screen_hashes[screen] = self._image_hash(image) return screen_hashes - def run(self, image): + def run(self, image: Image) -> Screen: current_screen = Screens.UNKNOWN best_diff = self.threshold for screen in Screens.__dict__.values(): if screen.ltrb is None: continue - - hash_ = self._image_hash(image.crop(screen.ltrb)) + # screen.ltb are dimensions scaled to 720x1280 so we scale them : + treated_ltrb = ( + int(screen.ltrb[0] * image.size[0] / 720), + int(screen.ltrb[1] * image.size[1] / 1280), + int(screen.ltrb[2] * image.size[0] / 720), + int(screen.ltrb[3] * image.size[1] / 1280), + ) + hash_ = self._image_hash(image.crop(treated_ltrb)) target_hash = self.screen_hashes[screen] diff = np.mean(np.abs(hash_ - target_hash)) diff --git a/clashroyalebuildabot/emulator/emulator.py b/clashroyalebuildabot/emulator/emulator.py index e402056..8502729 100644 --- a/clashroyalebuildabot/emulator/emulator.py +++ b/clashroyalebuildabot/emulator/emulator.py @@ -10,6 +10,7 @@ import av from loguru import logger +from PIL.Image import Image import requests from tqdm import tqdm @@ -237,7 +238,7 @@ def start_game(self): def click(self, x, y): self._run_command(["shell", "input", "tap", str(x), str(y)]) - def take_screenshot(self): + def take_screenshot(self) -> Image: logger.debug("Starting to take screenshot...") while self.frame is None: time.sleep(0.01) diff --git a/clashroyalebuildabot/images/screen/in_game.jpg b/clashroyalebuildabot/images/screen/in_game.jpg index e5e2cd829ee6d0ba82c7fc3022839e9d4281e538..c69911eaacbcf8929c7ec943e08849fea78b23c5 100644 GIT binary patch literal 4933 zcmeHLe{3699sizxG-={A=hRuVrm)McLmhDT-Pum!)4ViIn$~FE(!^sejJ5a6&aFP5 zdv~eRXcJU|Re~{^wG*rql6D(ZVjwD}7HNo;F~t7Z#t>*r83H=SkFkpJLm*H!%=evt zBt_{Ef0JjQ?{n{cKcDw~pZA{S=jvkhS3rMgEHefaMZr#dLG==RWBZJe2gqdJ53K;u z0$r3JC`9DiNCmySg1EPi??t?&9^*qSP(J9uyN#EKID+?2;AI>Mc--TNNx|;C=f-_U zCOgiEQGt)f2a(B(2}$53QDB6WB*vxq07g>_OSuq@>ZQ<&Q?6TtNV4AQS^dQO0#c2{S3<(TAIBpndP(P5q-+oIcw{av$yBe+5Kut zV~1{KZkds0%(AJwGBaZqOO7;?W<7BUF{zHRj2GhWPqVu*?Gek?nM5=ZvYO(XqM$KBd`us+CG5T8T$3yATsnsZ@*?W1`4m1m_$ox$+EGa&BxWjOvbR8)et9 zN(@ny6>Hi}v)F$vF|(Y_HicL8z%)s=UbN$GKZxXabIi#dD(kTc-La-^Ro{M4FS$21 z=$hK(mZ$BaHvmnI=|$bdFb5qMnq86EY(|p-7YwuPG0@p&6yj#kipi6%afH&SrB0Jh zGNWmhC`p>78k$stNg@Tu6w#z+>k9^@tDawu38%hU&~RKTt;i2dgXy|!hWwh@ls1Ozs}SZ-xj%c=vb4y-z`>cFZ4s}B7C zIk0pz(M$L%r-BEM>g&F5W=2N#j!)b%mbq;^p34Ay3q{p*0$Tyh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(PF6}rMnOeST|r4lSw=>~TvNxu(8R<c1}I=;VrF4wW9Q)H;sz?% zD!{d!pzFb!U9xX3zTPI5o8roG<0MW4oqZMDikqloVbuf*=gfJ(V&YTRE(2~ znmD<{#3dx9RMpfqG__1j&CD$#!{UeQ+oQsEet40^Ez=%4Pm{<0nGAcFV#UiF zp|$Q0v%FVD-@57j&EnzZOOHN2JJVjNBEaxV{?vvo^E)nQ{K{+1%ujpranctq9Uzj%O6&n-0rnI^*v}y)4z}Nzx&+|Gm$(je!kAY@ZKi(zBjjzPMfvo zT2;@rX&WcYuK6C9|GwJH-|_M%(dZ*}*71S|(~B#YX=R1|6!KYPW|gjGcwPBVwtlkQ z5sM?Q_QXGw&eaaywE5Dzq{?+pO1Hhu-$!=Z8=RM}SSR<$Qg>ZyQ|N6KzrbU~O?2j=%GA(;9(AZXY-c&M~SyZ1>yRuYKgQ$F&bz1dKQKsns48na61RW4VTk L%cU3f|8D{S`igG_ diff --git a/clashroyalebuildabot/images/screen/lobby.jpg b/clashroyalebuildabot/images/screen/lobby.jpg index 75e2246eac0eadf3a3baeb5c576eed3206d8a0d8..9d61cd2ac0049c7d9ed62c0b9a2a11d9c552bb70 100644 GIT binary patch literal 6867 zcmeHLcUV(N*PkQ=kRl09QIQZ3K@Fqb`Wg%x{9JGR&ZS#SkUEFQS;6XMW63+_j}&IUnjYDes|`aGjo1(&fHA2x3mud zX-WV;0N`*q5ClI!+XfE$CrQKr@cCnaAppPtnBxcl2N8A+!x4400OH|&I2K~(J{dg3 z3>+Sq!de9{Cd8Jo{uy49G(DZ}7KpI|htoax*Ma#2X1*h$+P@xpIE8CS$gY+dZsnCW>B<6+t1@u{f zPhQl%sU{{Sx+bz*6{=`A2A9iqqch!@Od6D+sTa#NND@u1cIda@hpL4tiBcm`$SIgb zM4*V*cv0c_y%UouLqY}&f0qN944bV^TCMRKqUW-B2kigJNpPIAdTaY&8d@F^8iiGNn!fGCLpz@qo~GCyxycJ>>Z* zgz?xQd_ONLW{D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