This is a computer vision project created in Python with computer vision libraries to determine the distance between two target objects in a given scene. The scenes and training images are depicted from a popular sandbox game.
Follow the steps below to run the application.
python3 -m venv venv;
pip install -r requirements.txt;
python3 modules/main.py;
This step will process training images to get an understanding of how the target block should look based on color values. The training images have (gold) target blocks shown from different angles and under different lighting situations. Once the histogram training is complete, the histogram model can be used to filter for target blocks by its most frequent colors..
For more info about Color Histograms: Color Histograms
Below are some sample images used to train the histogram model. There are roughly 50 training images used for the histogram training.
For the purpose of this walkthrough, the scene image shown below will be used.
The Canny Edge Detection algorithm is used to detect the edges in a given image.
For more info about the Canny Edge Detection Algorithm: Canny Edge Detector
Applying the Canny Edge detector to the scene image gives us this result:
The Projective Transformation technique is used to transform an image from a perspective into a 2D overhead view.
For more info about the Projective Transformations: Projective Transformations
The bounds for the Projective Transformation are determined and then highlighted in red for a visual representation.
Once the Projective Transformation is completed, the result looks like the image shown below.
K-Means Clustering will be used to find 2 points in the transformed image that correspond to the center points of each of the target blocks.
For more info about K-Means Clustering: K-Means Clustering
Setting K=2 and using the pixels in the target blocks as data points, we get two points corresponding to the centers of the target blocks, which are marked by the red dots.
The Hough Transformation is used for the last result image to count the number of horizontal and vertical lines between the two highlight points. These two values are used with the Euclidean Distance Formula to determine the distance between the two target blocks.
For more info about the Hough Transformation: Hough Transform