A real-time image classification application built with Python, OpenCV, Tkinter, and Linear SVM.
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.
- 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
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
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.
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
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.
When prediction is requested, the current webcam frame goes through the same preprocessing pipeline and is passed to the trained Linear SVM model.
git clone https://github.com/alkyramazann/Real-Time-Camera-Classifier.git
cd Real-Time-Camera-Classifierpip install -r requirements.txtpython main.pyWhen the application starts:
- Enter a name for the first class.
- Enter a name for the second class.
- Use the webcam to capture training images for each class.
- Click Train Model to train the classifier.
- Click Predict to classify the current camera frame.
- Enable Auto Prediction for continuous classification.
- 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.
- Python
- OpenCV — webcam access and image processing
- Scikit-learn — Linear Support Vector Classification
- NumPy — numerical data processing
- Pillow — image handling
- Tkinter — graphical user interface
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

