• Stars
    star
    301
  • Rank 138,451 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŽจ Color recognition & classification & detection on webcam stream / on video / on single image using K-Nearest Neighbors (KNN) is trained with color histogram features by OpenCV.

COLOR RECOGNITION

This project focuses on color classifying by K-Nearest Neighbors Machine Learning Classifier which is trained by R, G, B Color Histogram. It can classify White, Black, Red, Green, Blue, Orange, Yellow and Violet. If you want to classify more color or improve the accuracy you should work on the training data or consider about other color features such as Color Moments or Color Correlogram.

You can use color_recognition_api to perform real-time color recognition in your projects. You can find a sample usage of color_recognition_api in this repo. Please contact if you need professional color recognition project with the super high accuracy!

Quick Demo

Run color_classification_webcam.py to perform real-time color recognition on a webcam stream.

Run color_classification_image.py to perform color recognition on a single image.


What does this program do?

  1. Feature Extraction: Perform feature extraction for getting the R, G, B Color Histogram values of training images
  2. Training K-Nearest Neighbors Classifier: Train KNN classifier by R, G, B Color Histogram values
  3. Classifying by Trained KNN: Read Web Cam frame by frame, perform feature extraction on each frame and then classify the mean color of it by trained KNN classifier.

TODOs:

  • "Add New Color" utility will be added.
  • New feature extractors will be added.
  • New classifiers will be added.

Theory

In this study, colors are classified by using K-Neares NeลŸghbor Machine Learning classifier algorithm. This classifier is trained by image R, G, B Color Histogram values. The general work flow is given at the below.

You should know 2 main pheomena to understand basic Object Detection/Recognition Systems of Computer Vision and Machine Learning.

1.) Feature Extraction

How to represent the interesting points we found to compare them with other interesting points (features) in the image.

2.) Classification

An algorithm that implements classification, especially in a concrete implementation, is known as a classifier. The term "classifier" sometimes also refers to the mathematical function, implemented by a classification algorithm, that maps input data to a category.

For this project;

1.) Feature Extraction = Color Histogram

Color Histogram is a representation of the distribution of colors in an image. For digital images, a color histogram represents the number of pixels that have colors in each of a fixed list of color ranges, that span the image's color space, the set of all possible colors.

2.) Classification = K-Nearest Neighbors Algorithm

K nearest neighbors is a simple algorithm that stores all available cases and classifies new cases based on a similarity measure (e.g., distance functions). KNN has been used in statistical estimation and pattern recognition already in the beginning of 1970โ€™s as a non-parametric technique.

Implementation

OpenCV was used for color histogram calculations and knn classifier. NumPy was used for matrix/n-dimensional array calculations. The program was developed on Python at Linux environment.

In the โ€œsrcโ€ folder, there are 2 Python classes which are:

In the โ€œcolor_recognition_apiโ€ folder, there are 2 Python classes which are:

1.) Explanation of โ€œfeature_extraction.py"

I can get the RGB color histogram of images by this Python class. For example, plot of RGB color histogram for one of the red images is given at the below.

I decided to use bin number of histogram which has the peak value of pixel count for R, G and B as feature so I can get the dominant R, G and B values to create feature vectors for training. For example, the dominant R, G and B values of the red image which is given at above is [254, 0, 2].

I get the dominant R, G, B values by using Color Histogram for each training image then I labelled them because KNN classifier is a supervised learner and I deploy these feature vectors in the csv file. Thus, I create my training feature vector dataset. It can be found in the file which nameโ€™s is training.data under src folder.

2.) Explanation of โ€œknn_classifier.pyโ€

This class provides these main calculations;

  1. Fetching training data
  2. Fetching test image features
  3. Calculating euclidean distance
  4. Getting k nearest neighbors
  5. Prediction of color
  6. Returning the prediction is true or false

โ€œcolor_classification_webcam.pyโ€ is the main class of my program, it provides;

  1. Calling feature_extraction.py to create training data by feature extraction
  2. Calling knn_classifier.py for classification

You can find training data in here.

You can find features are got from training data in here.

Conclusion

I think, the training data has a huge important in classification accuracy. I created my training data carefully but maybe the accuracy can be higher with more suitable training data.

Another important thing is lightning and shadows. In my test images, the images which were taken under bad lighting conditions and with shadows are classified wrong (false positives), maybe some filtering algorithm should/can be implemented before the test images send to KNN classifier Thus, accuracy can be improved.

Citation

If you use this code for your publications, please cite it as:

@ONLINE{cr,
    author = "Ahmet ร–zlรผ",
    title  = "Color Recognition",
    year   = "2018",
    url    = "https://github.com/ahmetozlu/color_recognition"
}

Author

Ahmet ร–zlรผ

License

This system is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

tensorflow_object_counting_api

๐Ÿš€ The TensorFlow Object Counting API is an open source framework built on top of TensorFlow and Keras that makes it easy to develop object counting systems!
Python
1,305
star
2

vehicle_counting_tensorflow

๐Ÿš˜ "MORE THAN VEHICLE COUNTING!" This project provides prediction for speed, color and size of the vehicles with TensorFlow Object Counting API.
Python
851
star
3

signature_extractor

A super lightweight image processing algorithm for detection and extraction of overlapped handwritten signatures on scanned documents using OpenCV and scikit-image.
Python
414
star
4

augmented_reality

๐Ÿ’Ž "Marker-less Augmented Reality" with OpenCV and OpenGL.
C++
204
star
5

defi_yield_farming

๐Ÿšœ ๐ŸŒพ A DeFi app, which provides staking & farming functions are deploy-able with a website, for yield farming.
JavaScript
142
star
6

face_recognition_crop

Multi-view face recognition, face cropping and saving the cropped faces as new images on videos to create a multi-view face recognition database.
Python
141
star
7

vehicle_counting

Vehicle detection, tracking and counting by blob detection with OpenCV on c++.
C++
116
star
8

vehicle_counting_hog_svm

Vehicle detection, tracking and counting by SVM is trained with HOG features using OpenCV on c++.
C++
96
star
9

aipa

AIPA (A.I. Personal Assistant): Speech, Vision, Machine Learning and IoT based intelligent personal assistant for Ubuntu based Linux distributions.
Python
48
star
10

real_time_circle_detection_android

Real time circle detection and tracking by Hough Circle Transform with OpenCV on Android OS.
Java
44
star
11

human_computer_interaction

Fist, palm and hand detection & tracking for intelligent human-computer interaction game character movement control with OpenCV on Java (Processing sketchbook).
Processing
44
star
12

unity_calendar_ui

This is a well defined-basic "Calendar UI" for Unity.
C#
24
star
13

arlo_traffic_analysis

Vehicle detection, tracking, counting and speed prediction on videos with OpenCV.
Python
19
star
14

nonlinear_regression_keras

Training of a neural network for nonlinear regression prediction with TensorFlow and Keras API.
Jupyter Notebook
15
star
15

tcp_socket_programming_android_client

TCP Socket Programming implementation of client side on Android.
Java
12
star
16

decentralized_banking_system

๐Ÿฆ Decentralized banking system is a DApp built on Ethereum blockchain with smart contract on solidity.
Solidity
9
star
17

object_detection_chooch

A sample project for super fast real time object detection and counting using CHOOCH AI API and OpenCV.
Python
9
star
18

smart_contract_helloworld

๐Ÿ”ฅ Smart contract hello world tutorial: write and deploy your first Ethereum smart contract!
Solidity
9
star
19

unity_camera_movements

"Main Camera" movements scripts for Unity (for Desktop and Gear VR platforms).
C#
8
star
20

tcp_socket_programming_c_server

TCP Socket Programming implementation of server side in c programming language.
C
8
star
21

the_smart_contract_burger_store

๐Ÿ” ๐ŸŸ A real life case study for developing Ethereum smart contract for businesses: Building a smart contract to manage a burger store.
JavaScript
8
star
22

tensorflow_blob_analysis

A sample project to perform blob analysis on images with TensorFlow and Keras to detect blobs and analyze their shape features such as the presence, number, area, position, length, and direction of lumps.
Python
8
star
23

family_tree_warehouse_app

Ask relation, add/delete/update person, get information of any person, print the family tree, control under 18 age marriage and more...
Python
7
star
24

EncryptedMessengerApplication

Encrypted Messenger App: Sending and receiving messages (over TCP Socket) with high security (powered by RSA and AES).
Java
5
star
25

android_power_monitor

๐Ÿ”‹ Android power monitor hardware with Arduino.
C++
4
star
26

java_native_interface

Java Native Interface to call "Java Code" from "C++ Program".
C++
3
star
27

family_tree

Ask relation, add/delete/update person, get information of any person, print the family tree, control under 18 age marriage and more...
Prolog
3
star
28

pattern_matching

Implementation and performance comparison of Boyer Moore, Horspool and Brute Force in c programming language.
C
1
star
29

ahmetozlu.github.io

1
star
30

ethereum-smart-contract-samples

๐Ÿ’ก Small smart contract examples to understand basics and some details of developing Ethereum smart contracts!
Solidity
1
star
31

SimpleShell

This program is about a simple shell. The shell accepts user commands and then executes each command in a separate process.
C
1
star
32

sample_spring_microservice_case_study

๐Ÿฆ… An inventory management project for providing a sample microservice case study which contains Spring Cloud Eureka server & client, feign client, error handling & fault tolerance, API gateway, Spring Actuator, distributed log trace with Zipkin, centralized configuration and vault integration with Spring Cloud Config.
Java
1
star