Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from skimage import data, io;
- from riotwatcher import RiotWatcher;
- from mss import mss;
- from PIL import Image;
- import cv2;
- import re;
- import numpy;
- import ast;
- import win32gui;
- """
- Check the league game config
- Check what side the minimap is on
- Get the game resolution
- Find the league process
- """
- apiKey = "RGAPI-69947b64-02dc-4ec9-a77f-c7ece5f9238f";
- def getLeagueConfig( path ):
- config = {};
- file = open( path, "r" );
- text = file.read();
- text = re.sub(
- r"(\[\w?.*\])",
- "",
- text
- );
- text = text.replace( "\n\n", "" );
- lines = text.split( "\n" );
- for line in lines:
- split = line.split( "=" );
- if( len( split )-1 ):
- try:
- split[1] = ast.literal_eval( split[1] );
- except ValueError:
- print( split[1] );
- except SyntaxError:
- print( split[1] );
- config[split[0]] = split[1];
- return config;
- def getMinimap( capturePos ):
- return numpy.array( sct.grab( capturePos ) );
- def getMinimapCircles( minimapImg ):
- grayImg = cv2.cvtColor( minimapImg, cv2.COLOR_BGR2GRAY );
- return cv2.HoughCircles(
- grayImg,
- cv2.HOUGH_GRADIENT,
- 1,
- 20,
- param1=50,
- param2=30,
- minRadius=12,
- maxRadius=26
- );
- def drawMinimapCircles( minimapImg, minimapCircles ):
- if( minimapCircles is not None ):
- minimapCircles = numpy.uint16( numpy.around( minimapCircles ) );
- for i in minimapCircles[0,:]:
- cv2.circle( minimapImg, ( i[0], i[1] ), i[2], ( 0, 255, 0 ), -1 );
- #cv2.circle( minimapImg, ( i[0], i[1] ), 2, ( 0, 0, 255 ), 3 );
- def getSummonerID( leagueUsername, leagueRegion ):
- leagueWatcher = RiotWatcher( apiKey );
- leagueInfo = leagueWatcher.summoner.by_name( leagueRegion, leagueUsername );
- return leagueInfo["id"];
- def getCurrentMatchInfo( summonerID, leagueRegion ):
- leagueWatcher = RiotWatcher( apiKey );
- matchInfo = leagueWatcher.spectator.by_summoner( leagueRegion, summonerID );
- return matchInfo;
- def getCurrentMatchParticipants( summonerID, leagueRegion ):
- matchInfo = getCurrentMatchInfo( summonerID, leagueRegion );
- return matchInfo["participants"];
- def getCurrentMatchJunglers( summonerID, leagueRegion ):
- junglers = [];
- smiteID = 11;
- participants = getCurrentMatchParticipants( summonerID, leagueRegion );
- for participant in participants:
- spell1 = participant["spell1Id"];
- spell2 = participant["spell2Id"];
- if( spell1 == smiteID or spell2 == smiteID ):
- junglers.append( participant );
- return junglers;
- def getCurrentVersion( leagueRegion ):
- leagueWatcher = RiotWatcher( apiKey );
- return leagueWatcher.static_data.versions( leagueRegion )[0];
- def getChampionImage( championID, leagueRegion ):
- leagueWatcher = RiotWatcher( apiKey );
- version = getCurrentVersion( leagueRegion );
- print( "Version:" );
- print( version );
- print();
- '''championData = leagueWatcher.static_data.champion(
- leagueRegion,
- championID,
- tags=[
- "image"
- ]
- );
- championImageData = championData["image"];
- championSpritePath = "https://ddragon.leagueoflegends.com/cdn/" + version + "/img/sprite/" + championImageData["sprite"];
- championImage = io.imread( championSpritePath );
- championImage = cv2.cvtColor( championImage, cv2.COLOR_BGR2RGB );
- championImageData["y"]: championImageData["y"] + championImageData["h"];
- championImageData["x"]: championImageData["x"] + championImageData["w"];
- return championImage;
- '''
- def saveSpriteMap( spriteMap, filePath ):
- image = Image.fromarray( spriteMapArray );
- image.save( filePath + "/spriteMap.png" );
- #https://ddragon.leagueoflegends.com/cdn/VERSION/img/champion/champion0.png
- #summonerID = getSummonerID( "JakeFromStateCS", "na1" );
- #junglers = getCurrentMatchJunglers( summonerID, "na1" );
- #for jungler in junglers:
- # championID = jungler["championId"];
- # championImage = getChampionImage( championID );
- #print( junglers );
- sct = mss();
- #The default league minimap size
- defaultMapSize = 550;
- #Get the game config
- config = getLeagueConfig( "C:\Riot Games\League of Legends\Config\game.cfg" );
- #League width and height
- gameWidth = config["Width"];
- gameHeight = config["Height"];
- mapScale = config["MinimapScale"];
- mapFlip = config["FlipMiniMap"];
- mapSize = defaultMapSize * mapScale;
- capturePos = {
- "top": int( gameHeight - mapSize ),
- "left": int( 0 if mapFlip else gameWidth - mapSize ),
- "width": int( mapSize ),
- "height": int( mapSize)
- };
- '''
- championImage = getChampionImage( 81, "na1" );
- championImage = cv2.resize( championImage, ( 0, 0 ), fx=0.5, fy=0.5 );
- championImage = cv2.cvtColor( championImage, cv2.COLOR_BGR2GRAY );
- w, h = championImage.shape;
- greenL = numpy.array( [60, 255, 255], numpy.uint8 );
- greenU = numpy.array( [60, 255, 255], numpy.uint8 );
- while 1:
- minimapImg = getMinimap( capturePos );
- largeMinimapImg = cv2.resize( minimapImg, ( 0, 0 ), fx=2.0, fy=2.0 );
- largeMinimapMask = largeMinimapImg.copy();
- minimapCircles = getMinimapCircles( largeMinimapImg );
- drawMinimapCircles( largeMinimapMask, minimapCircles );
- largeMinimapMask = cv2.cvtColor( largeMinimapMask, cv2.COLOR_BGR2HSV );
- largeMinimapMask = cv2.inRange( largeMinimapMask, greenL, greenU );
- largeMinimapSearch = cv2.bitwise_and( largeMinimapImg, largeMinimapImg, mask=largeMinimapMask );
- grayLargeMinimapImg = cv2.cvtColor( largeMinimapSearch, cv2.COLOR_BGR2GRAY );
- result = cv2.matchTemplate( grayLargeMinimapImg, championImage, cv2.TM_SQDIFF_NORMED );
- min_val, max_val, min_loc, max_loc = cv2.minMaxLoc( result );
- top_left = min_loc;
- bottom_right = ( top_left[0] + w, top_left[1] + h );
- cv2.rectangle( largeMinimapImg, top_left, bottom_right, 255, 2 );
- minimapImg = cv2.resize( largeMinimapImg, ( 0, 0 ), fx=0.5, fy=0.5 );
- cv2.imshow( "test", largeMinimapImg );
- if( cv2.waitKey( 25 ) & 0xFF == ord("q" ) ):
- cv2.destroyAllWindows();
- break;
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement