This is the code for this video on youtube by @sirajology .Path planning is a technique used for find the shortest path between a source and destination. Path planning ensures that navigation is done in least time and in most optimized way, saving energy and providing a optimized way of the doing task.
We have a set of test images, each containing
The squares are identified by the coordinate (x,y) where x is the column and y is the row to which the square belongs. Each square can be empty or have an Obstacle or have an Object.
The program returns 2 major findings:
The coordinates of occupied grid:
The code returns a python list having ānā python tuples, where ānā denotes number of occupied grid in test image. Grid is to be considered occupied if either grid has an Obstacle or an Object. Each tuple has two elements, first element is the x-coordinate of an Obstacle/Object and second element is the y-coordinate of the Obstacle.
The minimum path:
For each object in the test images, a matching object which is nearest to it is found using compare_ssim
function from scikit-image
. Object is said to be nearest to another Object, if length of path traversed between two objects is smallest. Traversal is done by moving either horizontally or vertically. The length of the path is determined by the number of moves made during traversal. A* search is used to find this shortest path.
The code return a python dictionary. Format for creating dictionary is as follows:
Install OpenCV for Python
Install skimage (or scikit-image)
Open command prompt and type in:
pip install scikit-image
Install numpy
Open command prompt and type in:
pip install numpy
Run main.py
to check the results.
You can edit the test image from main.py to see different results.
The process_image.py
contains the major code.
Check that script to see the main functionality.
Follow the comments to undertand the code better.
astarsearch.py
contains the implemenatation of A* search algo.
traversal.py
contains the script to traverse through the image to find objects/min path.
The credits for this code go to Annirudha i've merely created a wrapper to get people started.