Git Product home page Git Product logo

maze-solver's Introduction

Maze-solver

--> sovling mazes in efficient way in python using Dijkstra’s Algorithm -->using OpenCV, a popular computer vision library for Python, to extract pixel values and show our maze images -->We can think of an image as a matrix of pixels. Each pixel (for simplicity’s sake) has an RGB value of 0,0,0 (black) or 255,255,255 (white). Our goal is to create a shortest path which starts in the white and does not cross into the black boundaries. To represent this goal we can treat each pixel as a node and draw edges between neighboring pixels with edge lengths based on RGB value differences. We will use the Euclidean squared distance formula and add 0.1 to ensure no 0-distance path lengths (a requirement for Dijkstra’s algorithm):

-->This formula makes the distance of crossing through the maze boundary prohibitively large. As we can see, the shortest path from source to destination will clearly be around the barrier, not through it. Alt Text

#implementation: We can use OpenCV, a popular computer vision library for Python, to extract pixel values and show our maze images. Let’s also identify the coordinates of our starting and ending locations by adding points to our maze

2>We create a Vertex class which will help us keep track of the coordinates. We also want to keep track of the parent node so that we can reconstruct the entire path once we find our distance values.

3>We need to create a matrix of Vertices, representing the 2D layout of pixels in an image. This will be the basis for our Dijkstra’s algorithm graph. We also maintain a min-heap priority queue to keep track of unprocessed nodes.

4>We need several helper functions to help find edges and edge lengths between vertices:

5>Now, we can implement Dijkstra’s Algorithm and assign distance (d) values to all of the pixel Vertices in the maze image:

6>We can now call our shortest path function and draw the solution on our maze:

maze-solver's People

Contributors

venky005 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.