Reputation: 13
I am working on a project where I need to take a photograph of a maze similar to this and find a path through it to guide a sphero robot through it (a way to find the beginning of the maze already exists). I have filtered the image such that I get the walls of the maze clear and the result is here
Simple approach would be a BFS on the pixels which works but takes too long to be practical. Another approach that I wish to do is to simplify the maze into cells and then solve it. I have successfully done so for an ideal digital image shown here and here (ideal meaning everything is straight, all walls have the same width etc.).
My question is how do I do something similar with the original filtered photo as the method used for the ideal case used the pixel width of the walls which is not a constant in real case? I am using opencv on python.
Upvotes: 1
Views: 286
Reputation: 15365
can you assume a known size grid for the maze? your maze is 10x10.
I'd go with your suggestion of simplifying the image into a schematic. assuming you know the grid size, overlay it and test every wall between a square's corners for presence/absence. take a comfortable subregion (numpy slice) from where a wall could be. test counting the pixels and checking if that's enough for a wall or very few pixels (no wall, at most noise).
if you don't know the size of the grid, you can test that. take the flat picture, sum up each row and each column of the image individually, and check for peaks that represent walls. count the peaks.
your picture is warped. make sure the board is flat. then apply a perspective transform to rectify the maze.
Upvotes: 1