0% found this document useful (0 votes)
164 views

Project Documentation Color Detection

This document summarizes a project report on color detection using Python. It includes sections on the abstract, literature review, problem formulation, dataset of colors, calculating distance, required tools, output, and feasibility analysis. The project aims to detect colors in an image using Python code, an image for testing, and a CSV file containing a dataset of colors. It will calculate the minimum distance between colors in the image and colors in the dataset to identify the closest matching color name.

Uploaded by

Muhammad Noman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views

Project Documentation Color Detection

This document summarizes a project report on color detection using Python. It includes sections on the abstract, literature review, problem formulation, dataset of colors, calculating distance, required tools, output, and feasibility analysis. The project aims to detect colors in an image using Python code, an image for testing, and a CSV file containing a dataset of colors. It will calculate the minimum distance between colors in the image and colors in the dataset to identify the closest matching color name.

Uploaded by

Muhammad Noman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

A Project Report

On

Colour Detection using Python

Registration Admission Degree /


Roll number Student Name Sem
No Number Branch
38 2020gu0263@ Nill Hasnain Abbas BSIT(evng) VI

Under the Supervision of

MAM SAIMA

GHAZI UNIVERISTY DERA GHZI KHAN


CANDIDATE’S DECLARATION

We hereby certify that the work which is being presented in the project,
entitled “COLOR DETECTION USING OPENCV” in partial
fulfilment of the requirements for the award of the BSIT submitted in
the Ghazi university dera ghazi khan is an original work carried out
during the period of 2020-24, under the supervision of Mam saima
Department of Computer Science and Engineering, Ghazi university
Dera Ghazi khan

The matter presented in the project has not been submitted by us for the
award of any other degree of this or any other places.

Hasnain Abbas 2020gu0263

Supervisor Name
CERTIFICATE

The Final Project Viva-Voice examination of Hasnain abbas

[email protected] has been held on 6TH SEMESTER

Evening and their work is recommended for the award of BSIT in

Computer Science Engineering.

Signature of Examiner(s) Signature of Supervisor(s)

Signature of Project Coordinator Signature of Dean

Date : Jun 17, 2023


Place : Dera Ghazi Khan

TABLE OF CONTENTS

S.No Particulars Page No

1 Abstract 3

2 Literature Reviews/Comparative study 4

3 Problem Formulation 5

4 Dataset of Colors 6

5 Calculating Distance 7

6 Required tools 8

7 Output 9

8 Feasibility Analysis 14
9 References 15

Abstract

Color detection is necessary to recognize objects, it is also used as a tool

in various image editing and drawing apps. It is the process of detecting

the name of any color. Well, for humans this is an extremely easy task

but for computers, it is not straightforward. Human eyes and brains work

together to translate light into color. Light receptors that are present in

our eyes transmit the signal to the brain. Our brain then recognizes the

color. Hence the problem that arises in front of us is how to make a

computer understand or recognize colors , so we are going to solve this

problem. So basically in this project using python we need 3 different

parts to be used. Python code which will be recognizing color, Image

that will be used for testing the color recognition, a .csv file that will be

containing the colors


as dataset. Hence the above 3 modules will help us in achieving our aim

that is detecting the colors in an image using python.

Literature Review

[1] Color can be identified from the sensory optic nerves of the eyes.

Color can only be seen or identified when a source of light is applied to

an object. Color blindness can be termed as inability of the

differentiation between colors. It is incurable disease that can be termed

as lifelong disease. Edges can be very helpful in color differentiation

boundary.

[2] Color detection model can be used in mixing of colors especially in

paints, dyes and color pigments. It can be also very helpful in to

differentiating colors that are used in robotics and in other medical

fields. It can also be used in Graphic Arts Industry. Other

implementations can
also be used in agricultural industry like especially detection of quality

of soil.

[3] Color Detection can be used in agriculture industry to find the weeds

the along with the crops. Via color detection weeds can be identified and

destroyed and the crops can be saved. It can be also used in medical

industries to detect the disease and other disorders especially in face and

other internal diseases like cancers.

[4] The main aim of computer vision is to analyze the behavior of

human eye and the reduction of human effort. Through computer vision

various task can be done that is done by human eye, whether to detect

the object or identify its color. By this method it is very helpful to detect

the symptoms of the disease and the other applications in other

industries like agriculture.

Due to its powerful learning ability and advantages in dealing with

occlusion, scale transformation and background switches, deep learning

based object detection has been a research hotspot in recent years. This
paper provides a detailed review on deep learning based object detection

frameworks which handle different subproblems, such as occlusion,

clutter and low resolution, with different degrees of modifications on R-

CNN. The review starts on generic object detection pipelines which

provide base architectures for other related tasks.

Then, three other common tasks, namely salient object detection, face

detection and pedestrian detection, are also briefly reviewed. Finally, we

propose several promising future directions to gain a thorough

understanding of the object detection landscape.

This review is also meaningful for the developments in neural networks

and related learning systems, which provides valuable insights and

guidelines for future progress.


colour detection is the process of detecting the name of any color.

Simple isn’t it? Well, for humans this is an extremely easy task but

for computers, it is not straightforward.

Human eyes and brains work together to translate light into color.

Light receptors that are present in our eyes transmit the signal to

the brain. Our brain then recognizes the color.

Since childhood, we have mapped certain lights with their color

names. We will be using the somewhat same strategy to detect

color names.
Problem Formulation

“It is said that a problem well defined is a problem half solved.”

So here we are talking about a very common disease we come across

nowadays “Color Blindness”.

This is a genetic disease and cannot be easily cured. In this disease the

person suffering with it cannot differentiate between colors. So with the

help of technology .

we can help the person suffering from Color Blindness without

physically operating or doing anything to the person’s eyes.


Now let us formulate it.

 Import the modules necessary in solving the problem.

 Take the image path of which you want to find the colors in.

 Read the csv file in the hex code of colors is stored.

 Now calculate the minimum distance from all the color and get the

most matching color using the get_color_name function.

 Make a function to get the x, y coordinates of the click point of

mouse.

 Display image on the window with a pointer to select any point on

image.
 Display the color name of the point along with the R, G, B values

Dataset of colors

Colors are made up of 3 primary colors; red, green, and blue. In

computers, we define each color value within a range of 0 to 255.

So in how many ways we can define a color? The answer is

256*256*256 = 16,581,375.

There are approximately 16.5 million different ways to represent a

color. In our dataset, we need to map each color’s values with

their corresponding names. But don’t worry, we don’t need to

map all the values.


We will be using a dataset that contains RGB values with their

corresponding names. The CSV file for our dataset has been taken

from this link:


The above dataset contains 865 colors along with their R, G, B values

we will be using this dataset only to get the colors for the mouse clicks.

Calculating Distance

Now as we have already shown in the screenshot that we have the R, G,

B values of the colors that we have attached in the dataset.

Explanation of Code:

 Camera Settings: In order to perform runtime operations, the


device’s web-camera is used. To capture a video, we need to
create a VideoCapture object. Its argument can be either the
device index or the name of a video file. The device index is
just the number to specify which camera. Normally one camera
will be connected, so we simply pass 0. You can select the
second camera by passing 1 and so on. After that, you can
capture frame-by-frame. But in the end, don’t forget to release
the capture. Moreover, if anyone wants to apply this colour
detection technique on any image it can be done with little
modifications in the code which I’ll discuss later.

 Capturing frames: The infinite loop is used so that the web


camera captures the frames in every instance and is open
during the entire course of the program.
After capturing the live stream frame by frame we are
converting each frame in BGR color space(the default one) to
HSV color space. There are more than 150 color-space
conversion methods available in OpenCV. But we will look
into only two which are most widely used ones, BGR to Gray
and BGR to HSV. For color conversion, we use the function
cv2.cvtColor(input_image, flag) where flag determines the
type of conversion. For BGR to HSV, we use the flag
cv2.COLOR_BGR2HSV. Now we know how to convert BGR
images to HSV, we can use this to extract a colored object. In
HSV, it is more easier to represent a color than RGB color-
space.
In specifying the range , we have specified the range of blue
color. Whereas you can enter the range of any colour you wish.

 Masking technique: The mask is basically creating some


specific region of the image following certain rules. Here we
are creating a mask that comprises of an object in blue color.
After that, I have used a bitwise_and on the input image and
the threshold image so that only the blue coloured objects are
highlighted and stored in res.
We then display the frame, res, and mask on 3 separate
windows using imshow function.

 Display the frame: As imshow() is a function of HighGui it is


required to call waitKey regularly, in order to process its event
loop.
The function waitKey() waits for key event for a “delay” (here,
5 milliseconds). If you don’t call waitKey, HighGui cannot
process windows events like redraw, resizing, input event etc.
So just call it, even with a 1ms delay .

 Summarizing the process:


1. Take each frame of the video.
2. Convert each frame from BGR to HSV color-space.
3. Threshold the HSV image for a range of blue color.

We need a function in the program that is going to return the color of the

point where the mouse is clicked. And as we know for getting the color

we need to get the distance and then compare it with the dataset.

Calculating the distance is done by the formulae given below :-


D= abs (Red-ithRedColor) + abs (Green-ithGreenColor) + abs (Blue-

ithBlueColor)

( ithRedColor, ithGreenColor, ithBlueColor are the colors R,G,B

values from the dataset )

Required tools

OpenCV:

OpenCV (Open Source Computer Vision) library aims at real time

Computer Vision. It is mainly used to do all the operations related

to images.

Pandas:
Pandas is Python Package which stands for Python and data

analysis. This library helps in data manipulation and analysis.

Image Processing:

Image Processing technique is used to perform some certain

operations on an image, in order to get an enhanced image as an

output or to extract some useful information from the image.

It acts as a type signal processing in which input is an image and

output may be an image or characteristics/features associated with

that image (we have used it for resizing the image) .


Output
Feasibility Analysis

Technical Feasibility:

The software is offline and totally based on python so it doesn’t requires

any kind of internet and there can’t be any issue regarding component

not working correctly.

It is compatible for Windows, Linux and Mac.

Resource and Time feasibility:

Resources that are required for the project,

 Programming Device

 Programming Tool (freely available)

 Programming individuals

So this project has the following required resource.


References

 Color Blindness

https://www.sciencedirect.com/science/article/abs/pii/S003335069

8005903

 Pandas documentation

https://pandas.pydata.org/docs/

 OpenCv Documentation

https://opencv.org/

You might also like