This project implements object detection using a pre-trained SSD MobileNet v2 model from the TensorFlow Model Zoo. The model is loaded using OpenCV's Deep Neural Network (DNN) module, and it performs real-time object detection on images.
This project is intended for educational purposes only. The author is not responsible for any misuse.
- Loads and processes images for object detection.
- Uses a pre-trained SSD MobileNet v2 model.
- Detects multiple objects in an image and labels them with bounding boxes.
- Configurable detection threshold.
- Python 3.x
- OpenCV (
cv2
) - Matplotlib
- numpy
- os
- urllib
- zipfile
- TensorFlow Model Zoo (pre-trained models)
- Clone this repository:
git remote add origin https://github.com/konynour/TF-Object-Detection.git ```
- Navigate to the project folder:
cd ObjectDetection
- Install dependencies:
pip install opencv-python numpy matplotlib
- Download and extract the SSD MobileNet v2 model from TensorFlow Model Zoo.
- Place the
frozen_inference_graph.pb
and its configuration file.pbtxt
inside themodels/
directory.
import cv2
import os
from detect import detect_objects, display_objects
# Load an image
im = cv2.imread(os.path.join("images", "street.jpg"))
# Detect objects
objects = detect_objects(net, im)
# Display results
display_objects(im, objects)
If you want to adjust the confidence threshold, you can modify the detection function call:
im = cv2.imread(os.path.join("images", "baseball.jpg"))
objects = detect_objects(net, im)
display_objects(im, objects, threshold=0.2)