Code Monkey home page Code Monkey logo

apexreader's Introduction

ApexReader

Analyze screenshots Apex Legends game summaries using Google's Tesseract OCR

Details

Uses Google's Tesseract OCR in conjuction with template matching via the opencv-python library. Parsing a screenshot follows this general pattern:

  1. Image is loaded from filepath via the cv2 module and converted to grayscale
  2. Loaded image undergoes thresholding to aid in parsing
  3. When a specific attribute is requested to be parsed, the appropriate template image is selected
  4. The selected template is found on screen using template matching, returning coordinates of the template image
  5. The location of the template is used to determine the region onscreen of the desired attribute information
  6. A cropped image containing the attribute information is finally passed to the OCR module
  7. The result of the OCR processing is saved for the attribute

Additionally, it's worth noting that attributed aren't calculated until requested. This allows for the ApexReader module to feel more responsive, as the entire image isn't parsed upon loading an image. This is done by using the @property decorator to allow properties to be calculated on their first use, instead of on initialization.

Example usage:

Let's extract the information from the following screenshot

We can do this simply with the following script

from ApexReader import ApexReader
from pprint import pprint

ar = ApexReader()
ar.load(r'.\test_imgs\img4.png') # Or whatever screenshot you want to analyze

pprint(ar.game_data)

Which returns the output

{'num_players': 3,
 'placement': '1',
 'players': {'player0': {'damage': '2250',
                         'kills': '12',
                         'name': 'lfegirltocapture',
                         'respawns': '0',
                         'revives': '1',
                         'survival_time': '16:55'},
             'player1': {'damage': '2799',
                         'kills': '10',
                         'name': 'OGRealStimJimmy',
                         'respawns': '1',
                         'revives': '1',
                         'survival_time': '16:55'},
             'player2': {'damage': '982',
                         'kills': '4',
                         'name': 'syuraponda 4',
                         'respawns': '0',
                         'revives': '0',
                         'survival_time': '1855'}},
 'squad_kills': '26'}
>>> 

We can see the screenshot isn't read perfectly but it is very close, too which we can thank Google's Tesseract OCR.

apexreader's People

Contributors

cubrink avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.