Full Code of SanshruthR/CCTV_YOLO for AI

main 4745dbecaec6 cached
4 files
5.0 KB
1.6k tokens
2 symbols
1 requests
Download .txt
Repository: SanshruthR/CCTV_YOLO
Branch: main
Commit: 4745dbecaec6
Files: 4
Total size: 5.0 KB

Directory structure:
gitextract_f2uacro9/

├── README.md
├── app.py
├── requirements.txt
└── yolov5n6.pt

================================================
FILE CONTENTS
================================================

================================================
FILE: README.md
================================================
# Fast Real-time Object Detection with High-Res Output

![Python](https://img.shields.io/badge/Python-3.8%2B-3776AB?style=for-the-badge&logo=python&logoColor=white)
![YOLOv5](https://img.shields.io/badge/YOLOv5n6-6.1-orange?style=for-the-badge&logo=YOLO&logoColor=white)
![CUDA](https://img.shields.io/badge/CUDA-Enabled-76B900?style=for-the-badge&logo=nvidia&logoColor=white)
![OpenCV](https://img.shields.io/badge/OpenCV-3.4.2-5C3EE8?style=for-the-badge&logo=opencv&logoColor=white)
![Gradio](https://img.shields.io/badge/Gradio-3.1.4-blueviolet?style=for-the-badge&logo=gradio&logoColor=white)
[![Deployed on Hugging Face](https://img.shields.io/badge/Deployed%20on-Hugging%20Face-yellow?style=for-the-badge&logo=huggingface&logoColor=white)](https://huggingface.co/spaces/Sanshruth/CCTV_YOLO?embed=true)
![image](https://github.com/user-attachments/assets/2cbae46f-e9de-48db-96f8-d439536ad703)


## Overview

Live stream of Las Vegas sidewalk traffic cam, processed with YOLOv5n6 on low-resolution frames, with results drawn on high-resolution frames.

This project demonstrates **real-time object detection** using the YOLOv5n6 model with **low-resolution inference** for high-speed processing, while drawing the results on **high-resolution frames**. The object detection pipeline is deployed as a Gradio app and streams live data from an external camera feed.

### Features

- **YOLOv5n6 Model**: Pre-trained object detection model optimized for speed and accuracy.
- **Low-resolution Processing**: Efficiently processes frames in low resolution (320x180) while mapping results to high-res images.
- **Gradio Interface**: Interactive Gradio interface with real-time video stream processing.
- **CUDA Support**: Optimized for CUDA-enabled GPUs, ensuring fast inference times.

### Model Details

- **Model**: YOLOv5n6 (`yolov5n6.pt`)
- **Confidence Threshold**: 0.25
- **IOU Threshold**: 0.45
- **Max Detections**: 100 objects per frame

### How It Works

The pipeline processes a live video stream, detecting objects in each frame using YOLOv5n6. Bounding boxes are drawn on the high-resolution frames based on detections from the low-resolution inference.

### Usage

1. Clone the repository and install the dependencies:
    ```bash
    git clone https://github.com/SanshruthR/CCTV_YOLO.git
    cd cctv-yolo
    pip install -r requirements.txt
    ```

2. Run the script:
    ```bash
    python app.py
    ```

3. Access the Gradio interface and view the live stream processed with YOLOv5n6.

### Deployment

This project is deployed on **Hugging Face Spaces**. You can interact with the app via the following link:

[Live Demo on Hugging Face](https://huggingface.co/spaces/Sanshruth/CCTV_YOLO?embed=true)

### License

This project is licensed under the MIT License.


================================================
FILE: app.py
================================================
from ultralytics import YOLO
import cv2
import numpy as np
import gradio as gr
import torch

# Load YOLOv5n6 model
model = YOLO('yolov5n6.pt')

# Set the confidence threshold and IOU
model.conf = 0.25  # confidence threshold
model.iou = 0.45  # IOU threshold
model.agnostic = False
model.multi_label = False
model.max_det = 100  # max number of detections

# Low-resolution for inference 
#use frame_count += 3
#LOW_RES = (500, 600) 

#Faster inference but less accurate 
#LOW_RES = (320, 180) 

#Fastest inference but low accuracy, change frame_count to += 2
LOW_RES = (300, 300)

def detect_and_draw(frame):
    # Create low-res copy
    low_res_frame = cv2.resize(frame, LOW_RES)
    
    # Perform detection
    results = model(low_res_frame, verbose=False)

    # Scale bounding boxes
    scale_x = frame.shape[1] / LOW_RES[0]
    scale_y = frame.shape[0] / LOW_RES[1]

    # Draw bounding boxes on high-res frame
    for detection in results[0].boxes.data:
        x1, y1, x2, y2, conf, cls = detection
        x1, y1, x2, y2 = int(x1*scale_x), int(y1*scale_y), int(x2*scale_x), int(y2*scale_y)
        label = f"{results[0].names[int(cls)]} {conf:.2f}"
        cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
        cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)

    return frame

# Define your stream URL
stream_url = "https://edge01.london.nginx.hdontap.com/hosb5/ng_showcase-coke_bottle-street_fixed.stream/chunklist_w464099566.m3u8"

def process_stream():
    cap = cv2.VideoCapture(stream_url)
    frame_count = 0
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break

        frame_count += 2  #change to 3 for higher res
        if frame_count % 30 == 0:
            result = detect_and_draw(frame)
            result_rgb = cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
            yield result_rgb

    cap.release()

iface = gr.Interface(
    fn=process_stream,
    inputs=None,
    outputs="image",
    live=True,
    title="Fast Real-time Object Detection with High-Res Output",
    description="Live stream processed with YOLOv5n6 on low-res frames, results drawn on high-res frames."
)

if __name__ == "__main__":
    if torch.cuda.is_available():
        model.to('cuda')
    #iface.queue()
    iface.launch()


================================================
FILE: requirements.txt
================================================
ultralytics
opencv-python
gradio
torch
Download .txt
gitextract_f2uacro9/

├── README.md
├── app.py
├── requirements.txt
└── yolov5n6.pt
Download .txt
SYMBOL INDEX (2 symbols across 1 files)

FILE: app.py
  function detect_and_draw (line 27) | def detect_and_draw(frame):
  function process_stream (line 51) | def process_stream():
Condensed preview — 4 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (5K chars).
[
  {
    "path": "README.md",
    "chars": 2778,
    "preview": "# Fast Real-time Object Detection with High-Res Output\n\n![Python](https://img.shields.io/badge/Python-3.8%2B-3776AB?styl"
  },
  {
    "path": "app.py",
    "chars": 2319,
    "preview": "from ultralytics import YOLO\nimport cv2\nimport numpy as np\nimport gradio as gr\nimport torch\n\n# Load YOLOv5n6 model\nmodel"
  },
  {
    "path": "requirements.txt",
    "chars": 39,
    "preview": "ultralytics\nopencv-python\ngradio\ntorch\n"
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the SanshruthR/CCTV_YOLO GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 4 files (5.0 KB), approximately 1.6k tokens, and a symbol index with 2 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!