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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for d2r_image-0.2.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a87c2447042bb66ee055b11f477319d13e9af09b6b3b422ab706590129a77d1 |
|
MD5 | 4f710644a6b6d0f560719a2d7e89ae82 |
|
BLAKE2b-256 | 31d8a0a30f0c0b72bcc582ab078d38c1f82d66011c5e5a2be3ba1c682f9b9d90 |