Package: d2r-image
D2R ImageD2R 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) -> D2ItemListget_health(image: np.ndarray) -> floatget_mana(image: np.ndarray) -> floatget_stamina(image: np.ndarray) -> float (TODO)get_stamina(image: np.ndarray) -> float (TODO)get_merc_health(image: np.ndarray) -> floatget_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)classGroundItem:BoundingBox:dict# x, y, w, hName:str# e.g., Hand Axe, 1015 GOLD, Ormus' RobesQuality:str# e.g., gray, normal, magic, rare, set, unique, runeword, runeText:str# raw OCR text e.g., HAND AXEBaseItem:dictItem:Union[dict,None]NTIPAliasType:intNTIPAliasClassID:intNTIPAliasClass:Union[int,None]NTIPAliasQuality:intNTIPAliasFlag:dictclassGroundItemList:items:list[Union[GroundItem,None]]HoveredItemclassHoveredItem:Name:str# e.g., DAGGER, SPIRIT, CHILLING GRAND CHARM OF VITAQuality:str# e.g., gray, normal, magic, rare, set, unique, runeword, runeText:strBaseItem:dictItem:Union[dict,None]NTIPAliasType:intNTIPAliasClassID:intNTIPAliasClass:Union[int,None]NTIPAliasQuality:intNTIPAliasStat:Union[dict,None]NTIPAliasFlag:dictInstallIMPORTANTPre-requisite: Prior to pip installing be sure to install tesserocr from conda-forge:conda install -c conda-forge tesserocrthen runpip install d2r-imageMicrosoft Visual Studio C++ Build Tools may be required for tesserocr installUsageIMPORTANTIt'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:importcv2fromPILimportImagefromd2r_imageimportprocessing# Grab an input imageimage=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 callitems=processing.get_ground_loot(image_data)# Draw the itemsforiteminitems: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 callshealth=processing.get_health(image_data)mana=processing.get_mana(image_data)print(f'HP:{health}MP:{mana}')Demod2r-image comes with a demo.py file for previewing the output of different use cases within the game. These can be ran as follows:fromd2r_imageimportdemodemo.get_ground_loot()demo.get_health_mana()Screenshots