GithubHelp home page GithubHelp logo

d2r_image's Introduction

D2R Image

D2R Image is a package aimed to help in providing an API for answering common questions when looking at a Dablo II: Resurrected image:

  • get_ground_loot(image: np.ndarray) -> D2ItemList
  • get_health(image: np.ndarray) -> float
  • get_mana(image: np.ndarray) -> float
  • get_stamina(image: np.ndarray) -> float (TODO)
  • get_stamina(image: np.ndarray) -> float (TODO)
  • get_merc_health(image: np.ndarray) -> float
  • get_hovered_item(image: np.ndarray) -> tuple[HoveredItem, ItemText]

GroundItem (List)


D2Item is one of the core data models returned by the d2r-image library. It aims to represent a Diablo II item that's on the ground, being hovered, or detected by an image reference (e.g., equipped green Shako)

class GroundItem:
    BoundingBox: dict # x, y, w, h
    Name: str # e.g., Hand Axe, 1015 GOLD, Ormus' Robes
    Quality: str # e.g., gray, normal, magic, rare, set, unique, runeword, rune
    Text: str # raw OCR text e.g., HAND AXE
    BaseItem: dict
    Item: Union[dict, None]
    NTIPAliasType: int
    NTIPAliasClassID: int
    NTIPAliasClass: Union[int, None]
    NTIPAliasQuality: int
    NTIPAliasFlag: dict
class GroundItemList:
    items: list[Union[GroundItem, None]]

HoveredItem

class HoveredItem:
    Name: str # e.g., DAGGER, SPIRIT, CHILLING GRAND CHARM OF VITA
    Quality: str # e.g., gray, normal, magic, rare, set, unique, runeword, rune
    Text: str
    BaseItem: dict
    Item: Union[dict, None]
    NTIPAliasType: int
    NTIPAliasClassID: int
    NTIPAliasClass: Union[int, None]
    NTIPAliasQuality: int
    NTIPAliasStat: Union[dict, None]
    NTIPAliasFlag: dict

Install


IMPORTANT

Pre-requisite: Prior to pip installing be sure to install tesserocr from conda-forge:

conda install -c conda-forge tesserocr

then run

pip install d2r-image

Microsoft Visual Studio C++ Build Tools may be required for tesserocr install

Usage


IMPORTANT

It's very important that when using this library your Diablo II: Resurrected screenshots adhere to the following settings, otherwise results may vary:

{
    "Gamma": 155,
    "GammaHD": 3024,
    "PaperWhiteNits": 200,
    "MaxLuminance": 600,
    "HDRContrast": 200,
    "Contrast": 100,
    "Screen Resolution (Windowed)": "1280x720",
    "Resolution Scale": 100,
    "Sharpening": 6,
    "Game Resolution": 1,
    "Light Quality": 2,
    "Blended Shadows": 0,
    "Perspective": 0,
    "VSync": 1,
    "Framerate Cap": 60,
    "Framerate Target": 0,
    "Window Mode": 0,
    "Graphic Presets": 4,
    "Texture Quality": 4,
    "Texture Anisotropy": 0,
    "Ambient Occlusion Quality": 0,
    "Character Detail": 2,
    "Environment Detail": 2,
    "Atmospherics Quality": 2,
    "Transparency Quality": 3,
    "Shadow Quality": 1,
    "Anti Aliasing": 0,
    "Dynamic Resolution Scaling": 0,
    "Vfx Lighting Quality": 0,
    "Safe Screen Percent": 100,
    "Graphics Mode": 0,
    "NVIDIA DLSS": 0,
    "Chat Font Size": 0,
    "Combat Feedback": 0,
    "Camera Shake": 0,
    "Low Vision Mode": 1,
    "Color Blind Mode": 0,
    "Color Blind Strength": 100,
    "Show Clock": 1,
    "Auto Gold Enabled": 0,
    "Chat Gem Mode": 1,
    "Item Name Display": 1,
    "Chat Background": 0,
    "Always Run": 1,
    "Quick Cast Enabled": 0,
    "Display Active Skill Bindings": 0,
    "Lobby Wide Item Drop Enabled": 1,
    "Item Tooltip Hotkey Appender": 1
}

Python Example:

import cv2
from PIL import Image
from d2r_image import processing

# Grab an input image
image = Image.open('test_image.png')
# Convert color to BGR for cv2 (should this be in processing?)
image_data = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
# d2r_image get_ground_loot() API call
items = processing.get_ground_loot(image_data)
# Draw the items
for item in items:
    x, y, w, h = item.boundingBox.values()
    cv2.rectangle(
        image_data,
        (x, y),
        (x+w, y+h),
        debug_line_map[item.quality],
        1)
cv2.imshow('test_image', image)
cv2.waitKey()
# d2r_image get_health() and get_mana() API calls
health = processing.get_health(image_data)
mana = processing.get_mana(image_data)
print(f'HP: {health}    MP: {mana}')

Demo


d2r-image comes with a demo.py file for previewing the output of different use cases within the game. These can be ran as follows:

from d2r_image import demo

demo.get_ground_loot()
demo.get_health_mana()

Screenshots


random_items sets_and_uniques consumables get_belt baal trav

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.