Skip to content

A versatile Python Flask web app for live webcam streaming. It dynamically integrates basic video, real-time object detection, and age detection, all controllable via a user-friendly web interface. Features include snapshot capture and full-screen viewing. Requires specific pre-trained deep learning models for AI functionalities.

Notifications You must be signed in to change notification settings

meetpotdar777/IP-Webcam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IP Webcam Stream Projects: A Journey Through Computer Vision 📸

This document outlines the various stages and features developed for the IP Webcam Stream application, demonstrating a progression from a basic stream to advanced real-time computer vision capabilities. Each project phase built upon the last, culminating in a versatile multi-feature application.

Project Overview & Evolution 📈

Phase 1: Basic IP Webcam Stream

Purpose: The foundational project. Establishes a Flask web server to stream live video from your local webcam to a web browser. It provides a simple, low-latency video feed.

Key Features: Live MJPEG streaming, snapshot capture, full-screen viewing.

Phase 2: Object Counting (Initial Iteration - Deprecated)

Purpose: An early attempt to add computer vision by counting specific, static objects.

Status: This specific iteration was superseded by more robust real-time object detection due to limitations in simple counting methods for complex scenes.

Phase 3: Real-time Object Detection

Purpose: Enhanced the stream with dynamic, real-time object detection using a pre-trained deep learning model (MobileNet-SSD). This allows the application to identify and label multiple objects in motion or static within the video frame.

Key Features: Real-time bounding boxes and labels for detected objects (e.g., bottles, books, persons, cars).

Phase 4: Real-time Age Detection

Purpose: Shifted focus to human-centric computer vision, specifically detecting faces and estimating age ranges. This involves a two-step process: first, detecting faces, and then, analyzing those facial regions for age prediction.

Key Features: Real-time face bounding boxes with predicted age ranges displayed on the stream.

Phase 5: Multi-Feature IP Webcam Stream (Current Version) ✨

Purpose: The culmination of all previous efforts, this application integrates the basic streaming, real-time object detection, and real-time age detection into a single, user-selectable interface. Users can choose their desired mode directly from the web page.

Key Features:

Selectable Modes: Switch between Basic Stream (No AI), Object Detection, and Age Detection.

Snapshot Functionality: Capture and download still images from any active stream.

Full Screen Mode: View the webcam feed in full-screen.

Dynamic UI Updates: Status messages and feature information update based on the selected mode and model loading status.

Webcam Offline Placeholder: Displays a clear "WEBCAM OFFLINE" message if the camera is not accessible.

Responsive Design: Styled with Tailwind CSS for basic adaptability.

Technologies Used 💻

Python 3.x

Flask: A micro web framework for handling web requests and serving the video stream.

OpenCV-Python: The primary library for all computer vision tasks (webcam access, image processing, DNN inference).

NumPy: Essential for numerical operations within OpenCV.

HTML5, CSS3, JavaScript: For the interactive web interface.

Tailwind CSS: For streamlined UI styling.

Pre-trained Deep Learning Models:

MobileNet-SSD (Caffe model for Object Detection)

Caffe-based Face Detector (for Age Detection prerequisite)

Caffe-based Age Predictor Model

Prerequisites ✅ Before running the application, ensure you have:

Python 3.x installed.

pip (Python package installer) for library management.

Install the necessary Python libraries:

pip install opencv-python flask numpy

!!! CRITICAL STEP: Download All Required AI Models !!! ⚠️

To enable the Object Detection and Age Detection features, you MUST DOWNLOAD several pre-trained deep learning model files and place them in the SAME DIRECTORY as your Python script (ip_webcam_combined.py or whatever you have named it).

If these files are missing or corrupted, the respective AI features will be disabled, and you will see "Model Error" warnings in the console and on the web interface.

Required Model Files (Total 7 Files):

A) For Object Detection (3 files):

MobileNetSSD_deploy.prototxt (Model Architecture)

Direct Download: https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/dnn/MobileNetSSD_deploy.prototxt

How to Download: Click the link. When the plain text content loads, right-click anywhere on the page and select "Save As..." (or press Ctrl+S). Save the file as MobileNetSSD_deploy.prototxt.

MobileNetSSD_deploy.caffemodel (Model Weights)

Direct Download (SourceForge - generally reliable): https://sourceforge.net/projects/ip-cameras-for-vlc/files/MobileNetSSD_deploy.caffemodel/download

How to Download: Clicking this link should directly trigger the download (approx. 23MB).

coco.names (Class Labels)

How to Create: Open a plain text editor (like Notepad). Copy and paste the following content into it:

background aeroplane bicycle bird boat bottle bus car cat chair cow diningtable dog horse motorbike person pottedplant sheep sofa train tvmonitor

Save the file as coco.names in the same directory.

B) For Age Detection (4 files):

deploy.prototxt (Face Detector Architecture)

Direct Download: https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt

How to Download: Click the link, then right-click and "Save As...". Save it as deploy.prototxt.

res10_300x300_ssd_iter_140000.caffemodel (Face Detector Weights)

Direct Download: https://github.com/opencv/opencv_extra/raw/master/testdata/dnn/res10_300x300_ssd_iter_140000.caffemodel

How to Download: Clicking this link should directly trigger the download (approx. 10MB).

age_deploy.prototxt (Age Predictor Architecture)

Direct Download: https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/dnn/age_deploy.prototxt

How to Download: Click the link, then right-click and "Save As...". Save it as age_deploy.prototxt.

age_net.caffemodel (Age Predictor Weights)

Direct Download: https://github.com/opencv/opencv_extra/raw/master/testdata/dnn/age_net.caffemodel

How to Download: Clicking this link should directly trigger the download (approx. 40MB).

Ensure ALL SEVEN downloaded files are in the SAME FOLDER as your Python script!

How to Run the Multi-Feature Application ▶️

Save the Python Script:

Save the provided Python code (from the ip_webcam_combined Canvas) as ip_webcam_combined.py (or any .py name) in a directory of your choice.

Place Model Files:

As detailed in the "CRITICAL STEP" section above, download and place all seven .prototxt, .caffemodel, and .names files in the same directory as your Python script.

Run the Script:

Open a terminal or command prompt, navigate to the directory where you saved the script, and run it using:

python ip_webcam_combined.py

(Replace ip_webcam_combined.py with your script's actual filename if it's different).

Access the Web Stream:

Once the script starts, it will print messages in the console, including the URL where the Flask server is running (e.g., http://127.0.0.1:5000 or http://your_ip_address:5000). Open this URL in your web browser.

Select Mode:

On the web page, use the dropdown menu to select your desired stream mode (Basic, Object Detection, or Age Detection) and click "Start Stream."

Troubleshooting 🔍

"Model Error" Messages (in console or on web stream): This is the most frequent issue. It indicates that one or more of the required AI model files are missing, misnamed, corrupted, or not in the correct directory. Please meticulously re-verify that all seven files are downloaded correctly and placed in the same folder as your Python script. Refer to the "CRITICAL STEP" section for links and instructions.

"Error initializing camera: Cannot open webcam." / cv2.error: Unknown C++ exception from OpenCV code:

Ensure no other application (e.g., Zoom, Skype, a different camera app) is currently using your webcam. Close them and retry.

Check your webcam's physical connection.

Try restarting your computer.

If you have multiple webcams, you might need to try a different index (e.g., change cv2.VideoCapture(0) to cv2.VideoCapture(1) or (2) in the Python code).

On some operating systems, you might need to grant explicit camera access permissions to your terminal or Python.

Web page shows "Connecting..." indefinitely but no stream:

Check your Python console for any error messages.

Ensure your webcam is functioning correctly (test with a built-in camera app).

Verify the Flask server is running on the correct port and is accessible from your browser.

SyntaxError: unterminated triple-quoted string literal: This error means there's a problem with how the multi-line HTML template string is defined in the Python code. Ensure you've copied the entire Python code block from the Canvas accurately. This has been a recurring issue and should be resolved in the latest code provided.

Security Warning ⚠️

This application is a basic demonstration intended for local use or within a secure, private network only. It does NOT implement robust security measures like authentication or HTTPS encryption. DO NOT expose this webcam stream to the public internet without implementing proper security protocols, as it could pose a significant privacy and security risk.

About

A versatile Python Flask web app for live webcam streaming. It dynamically integrates basic video, real-time object detection, and age detection, all controllable via a user-friendly web interface. Features include snapshot capture and full-screen viewing. Requires specific pre-trained deep learning models for AI functionalities.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages