Python Forum
open cv ->pygame: turn image into location - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: open cv ->pygame: turn image into location (/thread-23849.html)



open cv ->pygame: turn image into location - Gamedeveloper - Jan-20-2020

Hi.

I have built a physical maze (black background, white walls) and want to make it digital.
I have used edge detection in open cv and it detects all walls.
Now I want to make an AI (A* search) walk through the maze.
However, I do not know how to go from this image to a (pygame) grid with walls so an AI can walk through.
Does anyone know how to do this?
Should I use line or color detection instead?
Thanks a lot in advance.

Edit: the image link below shows the maze and working edge detection.

[Image: VqBXuEj]


RE: open cv ->pygame: turn image into location - michael1789 - Jan-20-2020

I think the route to take is certainly with a tile-map. You can use a program like "Tiled" to draw it, or more simply if you prefer, use a .txt file where each character represents a square, and each square can be open floor or a sprite. The AI sprite can easily be made not to pass through wall sprites.

I don't know how to convert that specific image into a working map, but you can replicate and change it as a text file with great ease.

What kind of image file is it? It would seem possible to use map itself as a pygame sprite's image, and use a mask and pixel-perfect collision. If you want or need to use that image, that's the only way I can think of. In the end is amounts to "color detection", just a strange approach. I'm probably over complicating things. It's a habit. lol

But in the end, tilemaps are a very standard way of making a map for something to walk around in.