This Python application is designed to detect cars in video feeds using OpenCV and store the count in a PostgreSQL database. It uses Haar cascades for object detection.
- Python 3.11
- OpenCV
- PostgreSQL
- psycopg2
- Additional requirements can be found in
requirements.txt
.
- Install Dependencies: Run
pip install -r requirements.txt
to install the required Python packages. - Database Setup: Ensure PostgreSQL is installed and running. Create a database and update the
settings.json
file with your database credentials. - Haar Cascade: Place the
haarcascade_car.xml
file in the project directory. - Docker (Optional): Use the provided Dockerfile for containerization.
Edit the settings.json
file to set up your configuration. Example configuration:
{
"cascade_name": "haarcascade_car.xml",
"db_name": "your_db_name",
"db_user": "your_db_user",
"db_pass": "your_db_password",
"db_host": "localhost",
"video_link": "path_to_video_file_or_stream"
}
Execute the script using:
python application.py
application.py
: The main entry point of the application.computer_vision.py
: Contains theCarCount
class for car detection and database operations.controls.py
: Utility script to load configuration settings.requirements.txt
: Lists all Python dependencies.haarcascade_car.xml
: Haar cascade file for car detection.settings.json
: Configuration file for database and other settings.
The application will start processing the video feed specified in the configuration file. Detected cars will be displayed in a window, and the count will be stored in the PostgreSQL database.