Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. from skimage import data, io;
  2. from riotwatcher import RiotWatcher;
  3. from mss import mss;
  4. from PIL import Image;
  5. import cv2;
  6. import re;
  7. import numpy;
  8. import ast;
  9. import win32gui;
  10.  
  11. """
  12. Check the league game config
  13. Check what side the minimap is on
  14. Get the game resolution
  15. Find the league process
  16. """
  17. apiKey = "RGAPI-69947b64-02dc-4ec9-a77f-c7ece5f9238f";
  18.  
  19. def getLeagueConfig( path ):
  20. config = {};
  21. file = open( path, "r" );
  22. text = file.read();
  23. text = re.sub(
  24. r"(\[\w?.*\])",
  25. "",
  26. text
  27. );
  28. text = text.replace( "\n\n", "" );
  29. lines = text.split( "\n" );
  30. for line in lines:
  31. split = line.split( "=" );
  32. if( len( split )-1 ):
  33. try:
  34. split[1] = ast.literal_eval( split[1] );
  35. except ValueError:
  36. print( split[1] );
  37. except SyntaxError:
  38. print( split[1] );
  39. config[split[0]] = split[1];
  40.  
  41. return config;
  42.  
  43. def getMinimap( capturePos ):
  44. return numpy.array( sct.grab( capturePos ) );
  45.  
  46. def getMinimapCircles( minimapImg ):
  47. grayImg = cv2.cvtColor( minimapImg, cv2.COLOR_BGR2GRAY );
  48. return cv2.HoughCircles(
  49. grayImg,
  50. cv2.HOUGH_GRADIENT,
  51. 1,
  52. 20,
  53. param1=50,
  54. param2=30,
  55. minRadius=12,
  56. maxRadius=26
  57. );
  58.  
  59. def drawMinimapCircles( minimapImg, minimapCircles ):
  60. if( minimapCircles is not None ):
  61. minimapCircles = numpy.uint16( numpy.around( minimapCircles ) );
  62. for i in minimapCircles[0,:]:
  63. cv2.circle( minimapImg, ( i[0], i[1] ), i[2], ( 0, 255, 0 ), -1 );
  64. #cv2.circle( minimapImg, ( i[0], i[1] ), 2, ( 0, 0, 255 ), 3 );
  65.  
  66. def getSummonerID( leagueUsername, leagueRegion ):
  67. leagueWatcher = RiotWatcher( apiKey );
  68. leagueInfo = leagueWatcher.summoner.by_name( leagueRegion, leagueUsername );
  69. return leagueInfo["id"];
  70.  
  71. def getCurrentMatchInfo( summonerID, leagueRegion ):
  72. leagueWatcher = RiotWatcher( apiKey );
  73. matchInfo = leagueWatcher.spectator.by_summoner( leagueRegion, summonerID );
  74. return matchInfo;
  75.  
  76. def getCurrentMatchParticipants( summonerID, leagueRegion ):
  77. matchInfo = getCurrentMatchInfo( summonerID, leagueRegion );
  78. return matchInfo["participants"];
  79.  
  80. def getCurrentMatchJunglers( summonerID, leagueRegion ):
  81. junglers = [];
  82. smiteID = 11;
  83. participants = getCurrentMatchParticipants( summonerID, leagueRegion );
  84. for participant in participants:
  85. spell1 = participant["spell1Id"];
  86. spell2 = participant["spell2Id"];
  87. if( spell1 == smiteID or spell2 == smiteID ):
  88. junglers.append( participant );
  89. return junglers;
  90.  
  91. def getCurrentVersion( leagueRegion ):
  92. leagueWatcher = RiotWatcher( apiKey );
  93. return leagueWatcher.static_data.versions( leagueRegion )[0];
  94.  
  95. def getChampionImage( championID, leagueRegion ):
  96. leagueWatcher = RiotWatcher( apiKey );
  97. version = getCurrentVersion( leagueRegion );
  98. print( "Version:" );
  99. print( version );
  100. print();
  101. '''championData = leagueWatcher.static_data.champion(
  102. leagueRegion,
  103. championID,
  104. tags=[
  105. "image"
  106. ]
  107. );
  108. championImageData = championData["image"];
  109. championSpritePath = "https://ddragon.leagueoflegends.com/cdn/" + version + "/img/sprite/" + championImageData["sprite"];
  110. championImage = io.imread( championSpritePath );
  111. championImage = cv2.cvtColor( championImage, cv2.COLOR_BGR2RGB );
  112. championImageData["y"]: championImageData["y"] + championImageData["h"];
  113. championImageData["x"]: championImageData["x"] + championImageData["w"];
  114. return championImage;
  115. '''
  116.  
  117. def saveSpriteMap( spriteMap, filePath ):
  118. image = Image.fromarray( spriteMapArray );
  119. image.save( filePath + "/spriteMap.png" );
  120.  
  121. #https://ddragon.leagueoflegends.com/cdn/VERSION/img/champion/champion0.png
  122. #summonerID = getSummonerID( "JakeFromStateCS", "na1" );
  123. #junglers = getCurrentMatchJunglers( summonerID, "na1" );
  124. #for jungler in junglers:
  125. # championID = jungler["championId"];
  126. # championImage = getChampionImage( championID );
  127. #print( junglers );
  128.  
  129. sct = mss();
  130. #The default league minimap size
  131. defaultMapSize = 550;
  132. #Get the game config
  133. config = getLeagueConfig( "C:\Riot Games\League of Legends\Config\game.cfg" );
  134.  
  135. #League width and height
  136. gameWidth = config["Width"];
  137. gameHeight = config["Height"];
  138. mapScale = config["MinimapScale"];
  139. mapFlip = config["FlipMiniMap"];
  140. mapSize = defaultMapSize * mapScale;
  141.  
  142. capturePos = {
  143. "top": int( gameHeight - mapSize ),
  144. "left": int( 0 if mapFlip else gameWidth - mapSize ),
  145. "width": int( mapSize ),
  146. "height": int( mapSize)
  147. };
  148. '''
  149. championImage = getChampionImage( 81, "na1" );
  150. championImage = cv2.resize( championImage, ( 0, 0 ), fx=0.5, fy=0.5 );
  151. championImage = cv2.cvtColor( championImage, cv2.COLOR_BGR2GRAY );
  152. w, h = championImage.shape;
  153. greenL = numpy.array( [60, 255, 255], numpy.uint8 );
  154. greenU = numpy.array( [60, 255, 255], numpy.uint8 );
  155. while 1:
  156. minimapImg = getMinimap( capturePos );
  157. largeMinimapImg = cv2.resize( minimapImg, ( 0, 0 ), fx=2.0, fy=2.0 );
  158. largeMinimapMask = largeMinimapImg.copy();
  159. minimapCircles = getMinimapCircles( largeMinimapImg );
  160. drawMinimapCircles( largeMinimapMask, minimapCircles );
  161. largeMinimapMask = cv2.cvtColor( largeMinimapMask, cv2.COLOR_BGR2HSV );
  162. largeMinimapMask = cv2.inRange( largeMinimapMask, greenL, greenU );
  163. largeMinimapSearch = cv2.bitwise_and( largeMinimapImg, largeMinimapImg, mask=largeMinimapMask );
  164. grayLargeMinimapImg = cv2.cvtColor( largeMinimapSearch, cv2.COLOR_BGR2GRAY );
  165. result = cv2.matchTemplate( grayLargeMinimapImg, championImage, cv2.TM_SQDIFF_NORMED );
  166. min_val, max_val, min_loc, max_loc = cv2.minMaxLoc( result );
  167. top_left = min_loc;
  168. bottom_right = ( top_left[0] + w, top_left[1] + h );
  169. cv2.rectangle( largeMinimapImg, top_left, bottom_right, 255, 2 );
  170. minimapImg = cv2.resize( largeMinimapImg, ( 0, 0 ), fx=0.5, fy=0.5 );
  171. cv2.imshow( "test", largeMinimapImg );
  172. if( cv2.waitKey( 25 ) & 0xFF == ord("q" ) ):
  173. cv2.destroyAllWindows();
  174. break;
  175. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement