Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5b3b4da
capturing minimap, soon stitching diffs .. if I can get rid of noise..
ckcollab Nov 20, 2021
6f7117f
fix dep = to ==
ckcollab Nov 20, 2021
38a57d3
playing with minimap reading + stitching, saving spot at DECENT resul…
ckcollab Nov 20, 2021
296bc0f
latest attempt: stitching images real time .. sucks
ckcollab Nov 20, 2021
98b8e57
nice one-after-the-other stitching..! taking max ~600ms for full map,…
ckcollab Nov 26, 2021
700a52b
world x/y saved; pathing stubbing
ckcollab Nov 26, 2021
8efa52a
live stitching from in game working, drawing warps + removing playing…
ckcollab Nov 26, 2021
0be6a42
more live building of nodes and such
ckcollab Nov 27, 2021
25ce314
add static map node recorder
ckcollab Nov 28, 2021
3d54f2a
node recorder has interactables, draws lines between things, but fuck…
ckcollab Nov 28, 2021
3427af4
playing with thresholds, trying to hide old bad data from stitching..…
ckcollab Nov 28, 2021
e19dce9
properly saving areas from start
ckcollab Nov 29, 2021
e83e13c
play sound on bad node added, stop trying to stitch over-and-over in …
ckcollab Dec 2, 2021
ec8a2a9
node recording seems accurate, can re-start it successfully
ckcollab Dec 4, 2021
3157efc
better aligning. bgr -> HSV, finally
ckcollab Dec 4, 2021
d090d22
better saved coords n such
ckcollab Dec 4, 2021
60364a8
removing threshold makes matches have much more information to go from
ckcollab Dec 4, 2021
80d749b
pathfinding working for static maps
ckcollab Dec 5, 2021
ad1f36c
better comment
ckcollab Dec 5, 2021
418b714
we will want point pathing eventually..
ckcollab Dec 5, 2021
3a9a550
woo! area capture workin
ckcollab Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,7 @@ d2vs/ocr_training_batch_*/

# Configuration
.env
pickit.txt
pickit.txt

# mapping..
d2vs/mapping/captures/*
50 changes: 28 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ pip install d2vs
```

_NOTE: this can run via CPU, but via GPU is far superior. You must install CUDA and the appropriate python jazz
to get that working, for me with CUDA10.1:_
to get that all going. This worked for me with CUDA10.1:_

```bash
$ conda install torch torchvision cudatoolkit=10.1 -c pytorch
Expand All @@ -30,33 +30,39 @@ $ conda install torch torchvision cudatoolkit=10.1 -c pytorch


```py
>>> import numpy as np
>>> from d2vs.ocr import OCR
>>> from PIL import Image
>>>
>>> # Initiate OCR
>>> ocr = OCR()
>>>
>>> # Load an Image
>>> img = Image.open("586_gold.png")
>>>
>>> # Scan the image
>>> bounds, text, item_type = ocr.read(np.asarray(img, dtype='uint8'))
>>> print(text)
'586 Gold'
>>> print(item_type)
'Normal'
import numpy as np
from d2vs.ocr import OCR
from PIL import Image

# Initiate OCR
ocr = OCR()

# Load an image
image_rgb_data = np.asarray(Image.open("586_gold.png"), dtype='uint8')

# Scan the image
bounds, text, item_type = ocr.read(image_rgb_data)

# What do we have to work with?
print(bounds)
# ([2, 2], [158, 2], [158, 32], [2, 32])
# which are top_left, top_right, bottom_right, bottom_left

print(text)
# '586 Gold'

print(item_type)
# 'Normal'
```

# project goals

- Have fun automating single player! Not for profit
- OCR with near 100% accuracy
- Visually determine where you are in game, area level and world coordinate system
- Click from world coords to screen coords
- ~~Have fun automating single player! Not for profit~~
- ~~OCR with near 100% accuracy~~
- ~~Visually determine where you are in game and use that for navigation~~
- Path through unexplored areas to a goal
- Pick it for identified items/gambling/etc.
- Facilitate complete d2 bot from lvl 1 to 99
- Pick it

# development

Expand Down
173 changes: 173 additions & 0 deletions d2vs/mapping/OLD_pathing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
from time import sleep

from cv2 import cv2

from capture2 import map_capture, map_merge_features, map_diff


DIRECTION_NORTH_WEST = 1
DIRECTION_NORTH_EAST = 2
DIRECTION_SOUTH_EAST = 3
DIRECTION_SOUTH_WEST = 4


class Node:
def __init__(self, x, y, diff, connections=None, unwalkable=False, is_start=False, is_end=False):
# Sanity checks..
# assert not is_start and connections, "Must set at least one direction, we had to have come from " \
# "somewhere?! Unless we just started, then mark is_start = True"

assert not (is_start and is_end), "Cannot be start and end node at the same time!? or can you.. maybe!?"

# Coords
self.x = x
self.y = y

# Are we walkable? I.e., we tried to tele here and detected that tele failed.. not walkable!
self.unwalkable = unwalkable

# Setup connections to other nodes
self.connections = connections or {}

# Beginning or next to our goal?
self.is_start = is_start
self.is_end = is_end

# The image of the map difference screenshot taken at this step
self.diff = diff


def find_and_enter_warp(text, preferred_direction=DIRECTION_NORTH_WEST):
"""Flood fills area looking for warps. When a warp is found, mouse hovers over it to read
the text. If warp text matches given text, the warp is entered."""

"""
# "hidden" stop clause - not reinvoking for "c" or "b", only for "a".
if matrix[x][y] == "a":
matrix[x][y] = "c"
#recursively invoke flood fill on all surrounding cells:
if x > 0:
floodfill(matrix,x-1,y)
if x < len(matrix[y]) - 1:
floodfill(matrix,x+1,y)
if y > 0:
floodfill(matrix,x,y-1)
if y < len(matrix) - 1:
floodfill(matrix,x,y+1)
"""







"""

3. Take a picture:
a. diff happens first to calc x/y
a. Create `new_node` (`if counter == 0 then is_start = True`, skip rest)

a. Detect if we moved at all
- If no movement, `node.is_walkable = False`
- Change `preferred_direction`
a. Detect if warp is on minimap
- If so change `preferred_direction` to point to it
a. Detect if warp is on screen
- Scan mouse over area to look for it and try to click
- Mark `node.is_end = True`
- Return
a. go back to start ?
4.
"""





# pre, during_1, during_2 = map_capture()
# cv2.imshow("Result", pre)
# cv2.waitKey(0)
# exit()







# Start...
counter = 0

sleep(2)

map = map_diff(*map_capture(), is_start=True)
prev_node = Node(
10_000,
10_000,
map,
is_start=True,
)


while True:
sleep(1)


diff = map_diff(*map_capture())
map, x, y = map_merge_features(map, diff)






# TODO: Did we not move very far? If so, we should change to a new preferred_direction and go until we can't any more












new_node = Node(x, y, diff)

# if counter != 0:
# prev_node.connections[what direction were we coming from??]

counter += 1

if counter == 10:
break

prev_node = new_node

cv2.imshow("Result", map)
cv2.waitKey(0)












# can we see a warp?
# mouse over + check name
# if match: enter warp, return
# otherwise: we need to pick a direction to go and continue looking
# look based on preferred_direction
#


if __name__ == "__main__":
find_and_enter_warp("Durance of Hate Level 2", preferred_direction=DIRECTION_NORTH_EAST)
Empty file added d2vs/mapping/__init__.py
Empty file.
1 change: 1 addition & 0 deletions d2vs/mapping/areas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .harrogath import Harrogath
Empty file added d2vs/mapping/areas/base.py
Empty file.
18 changes: 18 additions & 0 deletions d2vs/mapping/areas/harrogath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from d2vs.mapping.base_maps import StaticMap
# from d2vs.mapping.pathing import StaticPather, Node


class Harrogath(StaticMap):
area_name = "Harrogath"
# pathfinder = StaticPather
# threshold = .2 # when doing map diffs TODO: use this!

def __init__(self, *args, **kwargs):
# self.nodes = [
# Node(10_000, 10_000, is_start=True)
# ]

# TODO: Defining nodes this way blows ass. do it via JSON!

super().__init__(*args, **kwargs)

Empty file.
Loading