Skip to content

This project uses the A* algorithm to find a path on a grid derived from an image. After setting start and end points by clicking on the image, the algorithm calculates the optimal route, avoiding obstacles detected from image contours and edges. The result is visualized on the image, showing the shortest path between the selected points.

Notifications You must be signed in to change notification settings

atharvad38/Astar_algorithm_implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Astar_algorithm_implementation

README: A* Pathfinding Algorithm with Image Grid

This project implements the A* pathfinding algorithm on a grid derived from an image. The user can select start and end points on the image, and the program will calculate the optimal path using the A* algorithm. The code uses computer vision techniques to create a grid representation of the image, allowing for pathfinding through this grid.

Requirements

To run this project, you will need:

  • Python 3.7 or higher
  • OpenCV
  • NumPy
  • Matplotlib

Ensure these packages are installed:

pip install opencv-python-headless numpy matplotlib

Overview

The code performs the following operations:

  1. Image Processing and Grid Creation: Loads an image, converts it to a grayscale format, and detects edges to create a grid representation. The grid indicates obstacles based on contours in the image.
  2. Point Selection: Allows the user to select start and end points on the image using mouse clicks.
  3. Pathfinding: Implements the A* algorithm to find the shortest path between the selected start and end points.
  4. Visualization: Displays the original image with the selected points and the calculated path.

Usage

  1. Set Image Path: Change the image_path variable to point to the desired image on your system.
    image_path = r"C:\path\to\your\image.jpg"
  2. Run the Code: Execute the code. A Matplotlib window will open with the image.
  3. Select Start and End Points: Click on the image to select a start point (green) and an end point (red). The code requires two points.
  4. Calculate the Path: After closing the Matplotlib window, the code will calculate the path using the A* algorithm and display the image with the path highlighted in green. If no path is found, an appropriate message is displayed.

Notes

  • The grid size can be adjusted via the grid_size variable. A smaller grid size offers finer granularity but increases computation time.
  • The image should contain distinguishable contours or edges to create the grid properly.
  • If the code does not find a path, consider adjusting the start and end points, or check if the grid correctly represents obstacles.

Troubleshooting

  • No Path Found: If no path is found, it may be due to obstacles completely blocking the way. Re-evaluate the selected start and end points or adjust the grid size.
  • Invalid Image Path: Ensure the image_path is set to a valid image file.
  • Dependencies Not Installed: Double-check that you have all the required packages installed in your Python environment.

License

This code is provided "as-is" with no warranties. Feel free to use, modify, or distribute it as needed.

About

This project uses the A* algorithm to find a path on a grid derived from an image. After setting start and end points by clicking on the image, the algorithm calculates the optimal route, avoiding obstacles detected from image contours and edges. The result is visualized on the image, showing the shortest path between the selected points.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages