Add additional debug options to color checker (#83)

This commit is contained in:
aeon0
2021-11-22 20:10:30 +01:00
committed by GitHub
parent fd883077e0
commit be12f8dcd5
7 changed files with 28 additions and 11 deletions

View File

@@ -31,8 +31,8 @@ Download the a prebuilt release [here](https://github.com/aeon0/botty/releases).
## Color Test Mode
To check if you graphic settings are good and if the bot would pick up items there is a **Color Test Mode** built in. Start botty and press F10 (Default key). This will open up a (mostly black) window. Start a game in D2R and throw some items of different type on the ground. If you now bring forward the debug window all items should show up with their names while the background is black. If you throw an item on the ground that should be picked up, it will have a red circle.</br>
<img src="assets/docs/color_checker.png" width="400">
To check if you graphic settings are good and if the bot would pick up items there is a **Graphic Debugger Mode** built in. Start botty and press F10 (Default key). This will open up a (mostly black) window. Start a game in D2R and go to A5. You should see some templates with blue circles detected and scores printed out to the console. E.g. for 720p you should see scores higher 0.8 for the templates. To check item finding, throw some items of different types on the ground. The debug window should show the item names with black background. If you throw an item on the ground that should be picked up, it will have a red circle. The console will print out the scores for each item that would be picked up. Scores should be well above 0.9 for these items.</br>
<img src="assets/docs/graphic_debugger.png" width="900">
## Development
Check out the [development.md](development.md) docu for infos on how to build from source and details of the project structure and code.
@@ -60,7 +60,7 @@ min_game_length_s | Games must have at least this length, will wait in hero sele
max_game_length_s | Botty will attempt to stop whatever its doing and try to restart a new game. Note if this fails, botty will attempt to shut down D2R and Bnet
exit_key | Pressing this key (anywhere), will force botty to shut down
resume_key | After starting the exe botty will wait for this keypress to atually start botting away
color_checker_key | Pressing this key will start a debug mode to check if the color filtering works with your settings. It also includes the item search and marks items it would pick up with red circles
graphic_debugger_key | Pressing this key will start a debug mode to check if the color filtering works with your settings. It also includes the item search and marks items it would pick up with red circles
logger_lvl | Can be any of [info, debug] and determines how much output you see on the command line
randomize_runs | If 0, the order will always be pindle -> eldritch/shenk. If 1 the order will be random.
difficulty | Set to `normal` `nightmare` or `hell` for game difficulty

Binary file not shown.

Before

Width:  |  Height:  |  Size: 930 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

View File

@@ -9,7 +9,7 @@ max_game_length_s=320
resume_key=f11
exit_key=f12
auto_settings_key=f9
color_checker_key=f10
graphic_debugger_key=f10
template_threshold=0.68
logg_lvl=info
randomize_runs=0

View File

@@ -35,7 +35,7 @@ class Config:
"exit_key": self._select_val("general", "exit_key"),
"resume_key": self._select_val("general", "resume_key"),
"auto_settings_key": self._select_val("general", "auto_settings_key"),
"color_checker_key": self._select_val("general", "color_checker_key"),
"graphic_debugger_key": self._select_val("general", "graphic_debugger_key"),
"template_threshold": float(self._select_val("general", "template_threshold")),
"logg_lvl": self._select_val("general", "logg_lvl"),
"randomize_runs": bool(int(self._select_val("general", "randomize_runs"))),

View File

@@ -4,7 +4,7 @@ from logger import Logger
import keyboard
import os
from config import Config
from utils.color_checker import run_color_checker
from utils.graphic_debugger import run_graphic_debugger
from version import __version__
from utils.auto_settings import adjust_settings
from utils.misc import kill_thread, send_discord
@@ -63,7 +63,7 @@ if __name__ == "__main__":
print("\nFor gettings started and documentation\nplease read https://github.com/aeon0/botty\n")
table = BeautifulTable()
table.rows.append([config.general['auto_settings_key'], "Adjust D2R settings"])
table.rows.append([config.general['color_checker_key'], "Color test mode "])
table.rows.append([config.general['graphic_debugger_key'], "Color test mode "])
table.rows.append([config.general['resume_key'], "Start / Pause Botty"])
table.rows.append([config.general['exit_key'], "Stop bot"])
table.columns.header = ["hotkey", "action"]
@@ -76,8 +76,8 @@ if __name__ == "__main__":
break
if keyboard.is_pressed(config.general['auto_settings_key']):
adjust_settings()
elif keyboard.is_pressed(config.general['color_checker_key']):
run_color_checker()
elif keyboard.is_pressed(config.general['graphic_debugger_key']):
run_graphic_debugger()
break
time.sleep(0.02)

View File

@@ -4,14 +4,18 @@ from utils.misc import color_filter
from screen import Screen
from item_finder import ItemFinder
from config import Config
from template_finder import TemplateFinder
def run_color_checker():
def run_graphic_debugger():
config = Config()
screen = Screen(config.general["monitor"])
item_finder = ItemFinder()
template_finder = TemplateFinder(screen)
search_templates = ["A5_TOWN_0", "A5_TOWN_1", "A5_TOWN_2", "A5_TOWN_3"]
while 1:
img = screen.grab()
# Show item detections
combined_img = np.zeros(img.shape, dtype="uint8")
for key in config.colors:
_, filterd_img = color_filter(img, config.colors[key])
@@ -20,6 +24,19 @@ def run_color_checker():
for item in item_list:
cv2.circle(combined_img, item.center, 7, (0, 0, 255), 4)
cv2.putText(combined_img, item.name, item.center, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1, cv2.LINE_AA)
if len(item_list) > 0:
print(item_list)
# Show Town A5 template matches
scores = {}
for template_name in search_templates:
success, pos = template_finder.search(template_name, img, threshold=0.65)
if success:
scores[template_name] = template_finder.last_score
cv2.putText(combined_img, str(template_name), pos, cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.circle(combined_img, pos, 7, (255, 0, 0), thickness=5)
if len(scores) > 0:
print(scores)
# Show img
combined_img = cv2.resize(combined_img, None, fx=0.5, fy=0.5)
cv2.imshow("debug img", combined_img)
cv2.setWindowProperty("debug img", cv2.WND_PROP_TOPMOST, 1)
@@ -27,4 +44,4 @@ def run_color_checker():
if __name__ == "__main__":
run_color_checker()
run_graphic_debugger()