Python Forum

Full Version: open cv ->pygame: turn image into location
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]
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.