Python Forum
open cv ->pygame: turn image into location
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
open cv ->pygame: turn image into location
#1
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]
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pygame Zero - no actor image toiling_away 2 1,757 Oct-14-2022, 12:16 AM
Last Post: toiling_away
  How to make an image move in relation to another in PYGAME CompleteNewb 1 2,280 Nov-10-2021, 03:38 PM
Last Post: metulburr
  cant make a door automatically close a few seconds after i open it in pygame cooImanreebro 2 2,215 Dec-15-2020, 08:40 PM
Last Post: michael1789
  [PyGame] Error: Couldn't open image DotGuy 2 7,115 May-18-2020, 06:19 PM
Last Post: DotGuy
  [PyGame] pygame image loading error BlueClaw 6 6,325 Dec-10-2019, 08:50 PM
Last Post: BlueClaw
  pygame uploading image from opengameart fatimabttt 3 2,950 Apr-16-2019, 08:50 PM
Last Post: nilamo
  Finding the brightness of an image using pygame Zman350x 2 3,378 Feb-21-2019, 12:20 PM
Last Post: Zman350x
  [pyGame] Load Image, Problem Found ! JamieVanCadsand 2 8,687 Sep-29-2017, 06:26 PM
Last Post: metulburr
  How to find the location of an object and object at a given location? hsunteik 19 15,261 Feb-08-2017, 09:15 AM
Last Post: hsunteik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020