Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 28464472cc |
@@ -140,6 +140,7 @@ def find_town_center_in_map():
|
||||
for y in range(886, height, 1):
|
||||
r,g,b = image.getpixel((x,y))
|
||||
if is_white(r,g,b):
|
||||
print(f"Found white pixel ({x}/{y})")
|
||||
top = find_top(image, x, y, is_white)
|
||||
bottom = find_bottom(image, x, y, is_white)
|
||||
left = find_left(image, x, y, is_white)
|
||||
@@ -155,7 +156,6 @@ def scale_to_minimap_size(pixels):
|
||||
return int(pixels / (INFO.data["mapsize"] / (MAPSIZES["MITTEL"])))
|
||||
|
||||
def initial_scout_trace():
|
||||
walk_further_out = 3
|
||||
outer_circle = [(1730, 1072), (1570,986),(1730, 898), (1890, 984), (1730, 1072)]
|
||||
mid_circle = [(1730, 1047), (1610,986),(1730, 920), (1840, 984), (1730, 1035)]
|
||||
inner_circle = [(1730, 1020), (1650, 980), (1730, 940), (1790, 980), (1730, 1000) ]
|
||||
@@ -216,6 +216,24 @@ def initial_scout_trace():
|
||||
print(f"scout_trace: {scout_trace}")
|
||||
return scout_trace + center + inner_circle + mid_circle + outer_circle
|
||||
|
||||
def image_files_in_folder(folder):
|
||||
return [os.path.join(folder, f) for f in os.listdir(folder) if re.match(r'.*\.(jpg|jpeg|png)', f, flags=re.I)]
|
||||
|
||||
def dummy_ocr_big_numbers(region):
|
||||
numbers = {}
|
||||
for img_path in image_files_in_folder(os.path.join("images", "numbers")):
|
||||
matches = list(pyautogui.locateAllOnScreen(img_path, confidence=0.8, region=region, grayscale=False))
|
||||
for m in matches:
|
||||
numbers[m[0]] = img_path.split("\\")[-1].rstrip(".png")
|
||||
order = list(numbers.keys())
|
||||
order.sort()
|
||||
out = ""
|
||||
for pos in order:
|
||||
out += numbers[pos]
|
||||
return out
|
||||
|
||||
|
||||
|
||||
RESOURCES_LOCATIONS = {
|
||||
#'villager_wood': (28,39,20,10),
|
||||
'wood': (50,20,50,20),
|
||||
@@ -224,19 +242,26 @@ RESOURCES_LOCATIONS = {
|
||||
#'villager_gold': (228,39,20,10),
|
||||
'gold': (250,20,50,20),
|
||||
#'villager_stone': (330,39,20,10),
|
||||
'stone': (350,20,50,20)#,
|
||||
#'villager_houses': (450, 20, 70, 20),
|
||||
#'free_villagers': (543,32,11,11)
|
||||
'stone': (350,20,50,20),
|
||||
'villager_houses': (450, 20, 70, 20),
|
||||
'free_villagers': (533,32,21,11)
|
||||
}
|
||||
|
||||
def read_resources():
|
||||
res = {}
|
||||
for topic in RESOURCES_LOCATIONS.keys():
|
||||
img = pyautogui.screenshot(region=RESOURCES_LOCATIONS[topic])
|
||||
txt = aoe_recognition_ocr.recognize_number(img)
|
||||
print(topic, txt)
|
||||
txt = dummy_ocr_big_numbers(RESOURCES_LOCATIONS[topic])
|
||||
#print(topic, txt)
|
||||
#img.save(f"{topic}.png")
|
||||
if txt == "":
|
||||
txt = 0
|
||||
res[topic] = int(txt)
|
||||
return res
|
||||
|
||||
|
||||
if topic != "villager_houses":
|
||||
if txt == "":
|
||||
txt = "0"
|
||||
res[topic] = int(txt)
|
||||
elif "_" in txt:
|
||||
res["population"] = txt.split("_")[0]
|
||||
res["houses"] = txt.split("_")[-1]
|
||||
print(res)
|
||||
return res
|
||||
|
||||
|
||||
@@ -57,4 +57,4 @@ def recognize_number(img_pil):
|
||||
out_below = pytesseract.image_to_string(img, config=tesseract_config)
|
||||
out_below = out_below.strip()
|
||||
#print("OCR OUTPUT:", out_below)
|
||||
return out_below
|
||||
return out_below
|
||||
|
||||
BIN
images/numbers/0.png
Normal file
|
After Width: | Height: | Size: 291 B |
BIN
images/numbers/1.png
Normal file
|
After Width: | Height: | Size: 228 B |
BIN
images/numbers/2.png
Normal file
|
After Width: | Height: | Size: 308 B |
BIN
images/numbers/3.png
Normal file
|
After Width: | Height: | Size: 289 B |
BIN
images/numbers/4.png
Normal file
|
After Width: | Height: | Size: 268 B |
BIN
images/numbers/5.png
Normal file
|
After Width: | Height: | Size: 273 B |
BIN
images/numbers/6.png
Normal file
|
After Width: | Height: | Size: 303 B |
BIN
images/numbers/7.png
Normal file
|
After Width: | Height: | Size: 297 B |
BIN
images/numbers/8.png
Normal file
|
After Width: | Height: | Size: 273 B |
BIN
images/numbers/9.png
Normal file
|
After Width: | Height: | Size: 305 B |
BIN
images/numbers/_.png
Normal file
|
After Width: | Height: | Size: 291 B |