Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Camera Classifier

A real-time image classification application built with Python, OpenCV, Tkinter, and Linear SVM.

Overview

This project is a real-time camera classification application that allows users to create a custom two-class image dataset directly from their webcam and train a machine learning model to distinguish between the two classes.

The application provides a graphical interface for capturing training images, training the classifier, making predictions, and resetting the dataset and model.

Features

  • Real-time webcam feed
  • Custom two-class dataset collection
  • Automatic image preprocessing
  • Linear SVM classification
  • Real-time prediction
  • Auto Prediction mode
  • Tkinter graphical interface
  • Dataset and model reset functionality

How It Works

The application follows a simple end-to-end computer vision and machine learning workflow:

Webcam
   │
   ▼
OpenCV Camera Capture
   │
   ▼
Capture Images for Two Classes
   │
   ▼
Grayscale Conversion
   │
   ▼
Resize to 150 × 112
   │
   ▼
Flatten into 16,800 Features
   │
   ▼
Linear SVM Training
   │
   ▼
Real-Time Prediction
   │
   ▼
Class 1 / Class 2

1. Image Collection

The application uses the computer's webcam to capture training images. Users can define two custom classes and save images for each class directly from the application.

Each captured image is converted to grayscale and resized to 150 × 112 pixels before being saved.

2. Data Preprocessing

Before training, each image is:

  • Converted to grayscale
  • Resized to 150 × 112
  • Flattened into a one-dimensional vector

This produces:

150 × 112 = 16,800 features

3. Model Training

The project uses a LinearSVC model from Scikit-learn.

The processed images from both classes are combined into a training dataset, with each image assigned its corresponding class label.

4. Real-Time Prediction

When prediction is requested, the current webcam frame goes through the same preprocessing pipeline and is passed to the trained Linear SVM model.

The predicted class is then displayed directly in the Tkinter interface.

Installation

1. Clone the Repository

git clone https://github.com/alkyramazann/Real-Time-Camera-Classifier.git
cd Real-Time-Camera-Classifier

2. Install Dependencies

pip install -r requirements.txt

3. Run the Application

python main.py

Usage

When the application starts:

  1. Enter a name for the first class.
  2. Enter a name for the second class.
  3. Use the webcam to capture training images for each class.
  4. Click Train Model to train the classifier.
  5. Click Predict to classify the current camera frame.
  6. Enable Auto Prediction for continuous classification.
  7. Use Reset to clear the collected dataset and initialize a new model.

The application creates separate folders for the two classes and stores the captured training images there.


Tech Stack

  • Python
  • OpenCV — webcam access and image processing
  • Scikit-learn — Linear Support Vector Classification
  • NumPy — numerical data processing
  • Pillow — image handling
  • Tkinter — graphical user interface

Project Structure

Real-Time-Camera-Classifier/
│
├── app.py              # Tkinter GUI and application logic
├── camera.py           # Webcam capture and frame processing
├── main.py             # Application entry point
├── model.py            # Linear SVM training and prediction
│
├── screenshots/        # Application screenshots
├── .gitignore
├── LICENSE
├── README.md
└── requirements.txt

Application Preview

Application Interface

Application Interface

Real-Time Prediction

Prediction Result

About

Real-time image classification application using OpenCV, Tkinter, and Linear SVM.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages