Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

d2r-image-0.2.6.tar.gz (89.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

d2r_image-0.2.6-py3-none-any.whl (89.8 MB view details)

Uploaded Python 3

File details

Details for the file d2r-image-0.2.6.tar.gz.

File metadata

  • Download URL: d2r-image-0.2.6.tar.gz
  • Upload date:
  • Size: 89.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for d2r-image-0.2.6.tar.gz
Algorithm Hash digest
SHA256 29df1c614d7bbb2dd1b21a8b34f058ba770bedd06fa367b98c7ae00c95896762
MD5 9d452cdee087c8c221d5edf7a2d776b2
BLAKE2b-256 dc1bf1c4fcd19daeef07968e60b8f2b727b92c6bef5758978ee6064fbc81fb14

See more details on using hashes here.

File details

Details for the file d2r_image-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: d2r_image-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 89.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for d2r_image-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c16c1a108b580bc1a8e18875b0e3ac0a945601f69753b21a1dc3f7ca41d2e691
MD5 7c804164dbf51560b4e45c2bf7458432
BLAKE2b-256 29bdc1d66d04993f2e5d1aea85e2d0a43292faa64d4202c8f2551157c360f4cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page