Skip to content

A computer vision application that searches and filters images based on specific object types and their minimum count using YOLOv11 and Streamlit.

Notifications You must be signed in to change notification settings

prakhar175/count-aware-image-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Smart Image Search - Computer Vision Based Image Finder

A powerful computer vision application that enables intelligent image searching similar to Google Photos. Search through your image collection using object detection and advanced filtering capabilities.

Python Streamlit YOLOv11

🌟 Features

Core Capabilities

  • Object Detection: Automatically detect and catalog objects in your images using state-of-the-art YOLO models
  • Smart Search: Find images based on detected objects (e.g., "apple", "person", "bus", "car")
  • Advanced Filtering:
    • OR Mode: Find images containing ANY of the selected objects.
    • AND Mode: Find images containing ALL selected objects simultaneously.
    • Count Thresholds: Filter by minimum/maximum occurrence of objects in images.
  • Visual Results: Display search results with bounding boxes and confidence scores.
  • Metadata Export: Save and load detection metadata for quick future searches.

User Interface

  • Clean, responsive web interface built with Streamlit
  • Grid view with customizable columns (2-5)
  • Hover effects and smooth animations
  • Toggle bounding boxes on/off
  • Highlight matching objects vs. all detected objects
  • Export search results as JSON

πŸ“‹ Table of Contents

πŸš€ Installation

Prerequisites

  • Python 3.11 or higher
  • uv package manager

Setup

  1. Clone the repository
git clone https://github.com/prakhar175/count-aware-image-search.git
cd count-aware-image-search
  1. Create a virtual environment (recommended)
uv venv

.venv/Scripts/activate
  1. Install dependencies
uv sync

🎯 Quick Start

1. Prepare Your Images

Organize your images in a directory:

my_photos/
β”œβ”€β”€ vacation_2024/
β”‚   β”œβ”€β”€ beach1.jpg
β”‚   β”œβ”€β”€ beach2.png
β”‚   └── sunset.jpg
└── family/
    β”œβ”€β”€ birthday.jpg
    └── picnic.png

2. Launch the Application

streamlit run main.py

3. Process Images

  1. Select "Process the new images"
  2. Enter your image directory path
  3. Enter model path (e.g., yolo11n.pt, yolo11m.pt, yolo11l.pt)
  4. Click "Start Inference"
  5. Wait for processing to complete

4. Search Your Images

  1. Select search mode (OR / AND)
  2. Choose object classes from the dropdown
  3. Optionally set count thresholds
  4. Click "Search Images"
  5. View and export results!

πŸ“– Usage Guide

Processing New Images

When you first use the application, you need to process your images:

  1. Image Directory Path: Full path to your image folder

    /path/to/your/images
    Example ->
    C:\Users\prakhar\Pictures\MyPhotos  (Windows)
    
  2. Model Selection: Choose a YOLO model based on your needs:

    • yolo11n.pt - Nano (fastest, less accurate)
    • yolo11s.pt - Small (balanced)
    • yolo11m.pt - Medium (recommended)
    • yolo11l.pt - Large (slower, more accurate)
    • yolo11x.pt - Extra Large (most accurate)
  3. Processing: The app will:

    • Scan all images in the directory
    • Detect objects using YOLO
    • Save metadata to processed/[dirname]/metadata.json

Loading Existing Metadata

Skip reprocessing by loading previously generated metadata:

  1. Select "Load existing"
  2. Enter the path to your metadata.json file
  3. Click "Load Metadata"

Search Modes

OR Mode (Any Match)

Finds images containing at least one of the selected objects.

Example: Select "person" OR "dog"

  • βœ… Image with only a person
  • βœ… Image with only a dog
  • βœ… Image with both person and dog
  • ❌ Image with neither

AND Mode (All Match)

Finds images containing all selected objects simultaneously.

Example: Select "person" AND "dog"

  • ❌ Image with only a person
  • ❌ Image with only a dog
  • βœ… Image with both person and dog
  • ❌ Image with neither

Count Thresholds

Refine searches by object occurrence:

Example: "person" with threshold "3"

  • Finds images with 1-2 people (but not 3 or more)

Use Case: "car" with threshold "5"

  • Finds parking lots with a few cars, excludes highway traffic

Display Options

  • Show Bounding Boxes: Toggle object detection boxes
  • Grid Columns: Adjust layout (2-5 columns)
  • Show Highlights:
    • ON: Only show boxes for searched objects
    • OFF: Show all detected objects

πŸ“ Project Structure

smart-image-search/
β”‚
β”œβ”€β”€ main.py                 # Main Streamlit application
β”œβ”€β”€ .python-version               
β”œβ”€β”€ pyproject.toml        # Python dependencies
β”œβ”€β”€ README.md              # This file
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ inference.py       # YOLO inference logic
β”‚   └── utils.py           # Utility functions
β”‚
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── config.py          # Configuration settings
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/              # Original images
β”‚   └── processed/        # Metadata and results
β”‚
└── yolo11m.pt            # YOLO model weights

βš™οΈ Configuration

Edit configs/config.py to customize:

# Detection confidence threshold
CONF_THRESHOLD = 0.25  # Lower = more detections, higher = more accurate

# YOLO model
YOLO_MODEL = "yolo11m.pt"

# Supported image formats
IMAGE_EXTENSION = ["*.jpg", "*.jpeg", "*.png", "*.bmp", "*.webp"]

Key Parameters

Parameter Description Default Range
CONF_THRESHOLD Minimum confidence for detections 0.25 0.0 - 1.0
YOLO_MODEL Default YOLO model yolo11m.pt n/s/m/l/x
IMAGE_EXTENSION Supported formats jpg, png, etc. -

πŸ’‘ Examples

Example 1: Find Beach Photos

Search Mode: OR
Selected Classes: ["person", "umbrella", "surfboard"]
Result: All beach and vacation photos

Example 2: Find Family Dinners

Search Mode: AND
Selected Classes: ["person", "dining table", "fork"]
Result: Photos with people eating at tables

Example 3: Find Pet Photos (Not Crowded)

Search Mode: OR
Selected Classes: ["dog", "cat"]
Thresholds: dog=3, cat=3
Result: Photos with 1-2 dogs or cats (excludes shelter/kennel photos)

Example 4: Urban Street Scenes

Search Mode: AND
Selected Classes: ["car", "traffic light", "person"]
Result: City street photographs

πŸ”§ Technical Details

Detection Metadata Structure

Each processed image generates metadata:

{
  "img_path": "/path/to/image.jpg",
  "detections": [
    {
      "class": "person",
      "conf": 0.89,
      "bbox": [100, 150, 300, 450],
      "count": 2
    }
  ],
  "total_objects": 5,
  "unique_classes": ["person", "car", "dog"],
  "class_counts": {
    "person": 2,
    "car": 2,
    "dog": 1
  }
}

If you find this project useful, please consider giving it a ⭐ on GitHub!

About

A computer vision application that searches and filters images based on specific object types and their minimum count using YOLOv11 and Streamlit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages