This project is a real-time computer vision system built with OpenCV to: - Detect yellow-colored objects in a video stream - Label them with unique IDs - Estimate and display the distance between the objects in centimeters - Provide a visual overlay including bounding boxes, centers, and measured distances
It uses HSV color filtering, contour detection, and basic geometric calculations to determine spatial relationships between detected objects.
cv2)numpy)math)git clone https://github.com/your-username/real-time-object-distance-estimator.git
cd real-time-object-distance-estimator
Ensure you have Python 3 installed. Then install the required libraries:
pip install opencv-python numpy
This project uses camera index
10incv2.VideoCapture(10).
⚠️ Important: Make sure your desired camera is mapped to index 10, or change this value accordingly.
To find your working camera index:
cv2.VideoCapture(0) # Try different indexes if 0 doesn't work
Simply run the script:
python object_distance_estimator.py
q to quit the program safely.The system uses the HSV color space to isolate yellow objects:
lower_yellow = np.array([20, 100, 100])
upper_yellow = np.array([30, 255, 255])
Contours are detected from the mask and filtered based on area (> 500px) to avoid noise.
Each detected object is labeled using alphabet characters (A, B, C...).
distance_threshold = 0.06912) to convert to centimeters.Here's what you see in the final output window:
distance_threshold = 0.06912is a hardcoded value that maps pixel distance to centimeters.
To improve accuracy: - Use a known reference object size in frame - Calibrate using real-world measurements
On pressing q, the script:
- Breaks out of the loop
- Releases the camera feed
- Destroys all OpenCV windows
cv2.destroyAllWindows()
Contributions are welcome!
To contribute:
git checkout -b feature-name) This project is licensed under the MIT License.
Feel free to use, modify, and distribute.
Have suggestions, feedback, or collaboration ideas?
Abhijeet Singh
📧 abhijeet8800434205@gmail.com
—
$ claude mcp add distance_calculator \
-- python -m otcore.mcp_server <graph>