Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

HAIDER ALI: 70067920

TASK 1: DETECT COLOR (RED, GREEN, BLUE) THROUGH


WEBCAME IN PYTHON USING OPEN CV.

What is Color Detection?


ANS: Color 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.

PROCEDURE:-

-Py modules
cv2.VideoCapture (0) method.
cv2.imshow () method.
read () method.

-ever average has the greatest value, display that color

TASK 2: FIND THECOLOR NAME AND R-G-B VALUE OF EVERY


COLOR FROM THE IMAGE

Inputs
The feature "Color Name Finder" provides the most common names of a color. It
finds color names for 3 types of input:
 Color name from an image or a photo
 Color name from a hex or an RGB code
 Color name from a color picker
Uploading Image
To find the name of a color in an image, the cloud icon can be used to upload or
take a photo.
Once the image is loaded, clicking on the image areas will initiate the color name
identification. You can use the left mouse click to toggle between fixating and
releasing the target.
HAIDER ALI: 70067920
Since lighting conditions strongly affect the colors in an image, it is recommended
to take pictures in natural light to obtain the most representative color names.
Color Codes
The ArtyClick Color Name Finder can be used to find color names from hex or
RGB codes. The following color codes are supported:
 Hex (e.g. "#FF0000" or "#FFF")
 RGB (e.g. "RGB(255,0,0)")
The supported RGB codes correspond to the 24-bit system where each component
ranges between 0 and 255 (8-bit encoding)
Color Hue
Each color belongs to one of the 8 basic hues:
 Red
 Orange
 Yellow
 Green
 Cyan (turquoise or aqua)
 Blue
 Purple (violet)
 Magenta (bright pink)
More complex hues can be described as a composition of two hues, with one being
the primary and the other one the secondary hue.
Color Intensity
The color intensity is described using one of 7 the levels (ordered from the most to
the least saturated):
 Vibrant
 Moderate
 Medium
 Pastel
 Pale
 Almost none
 None
The intensity is inversely proportional to the amount of grey in a color. Vibrant
colors are pure and only exhibit limited amounts of grey, while pastel and pale
colors are diluted with grey and are less poppy. Vibrant colors are usually used for
setting accents, while pastel and pale colors often appear in the background or in
unprocessed photos.
HAIDER ALI: 70067920

TASK 3: REMOVE (GREEN AND YELLOW )COLOR FROM


THE IMAGE
I just want to detect only green objects from an image which captured in natural
environment. How to define it? Because in here I want to pass the threshold value
let's say 'x', by using this x I want to get only green colour objects in to one
color(white) others are must appear in another colour(black).
1. Convert to HSV color-space,
2. Use cv2.inRange(hsv, hsv_lower, hsv_higher) to get the green mask.
We use the range (in hsv): (36,0,0) ~ (86,255,255) for this sunflower.
TASK 4: DETECT SKIN COLOR FROM IMAGE IN PYTHON
Skin Detection Using Open-CV Python

What is Skin Detection?

 Process of finding skin-colored pixels and regions in an image or a video.


 Often used as a cue for detecting, localizing and observing targets containing
skin(like faces and hands in an image)
 Plays an important role in human motion analysis and face detection.
HAIDER ALI: 70067920
(A skin classifier defines a decision boundary of the skin color class in the color
space based on a training database of skin-colored pixels)

Human Skin

 The color of human skin is created by a combination of blood (red) and


melanin (yellow, brown).
 Skin colors lie between these two extreme hues and are somewhat saturated.
 The human skin is a fraction of the actual color cube, about 0.25 % of the
total colors
 Except for extremely hairy subjects, which are rare, skin has only low-
amplitude texture

Skin detection techniques


 Involves the formulation of an efficient mathematical model to represent the
skin color distribution.
 Range based
o transform a given pixel into an appropriate color space
o skin classifier to label the pixel whether it is a skin or non skin pixel.
 Histogram backprojection
o histogram is a spectrum of intensity repartition. A list that contains the
number of pixels for each possible value of pixel.

YCrCb Color Space

 Encoded nonlinear RGB signal, commonly used in video coding and image
compression work.
 constructed as a weighted sum of the RGB values, and two color difference
values Cr and Cb that are formed by subtracting luma from RGB red and
blue components
 16 to 235 for Y, 16 to 240 for Cb and Cr
 Skin pixels form a compact cluster in the Cb-Cr plane.

\displaystyle Y = 0.299R + 0.587G + 0.114BY=0.299R+0.587G+0.114B


\displaystyle C_r = R - YCr=R−Y

\displaystyle C_b = B- YCb=B−Y


HAIDER ALI: 70067920
Transformation simplicity and explicit separation of luminance and chrominance
components makes this colorspace attractive for skin color modelling

TASK 5: FACE DETECTION IN PYTHON FROM IMAGE


Let’s break down the actual code, which you can download from the repo. Grab
the face_detect.py script, the abba.png pic, and
the haarcascade_frontalface_default.xml.

# Get user supplied values


imagePath = sys.argv[1]
cascPath = sys.argv[2]
You first pass in the image and cascade names as command-line arguments. We’ll
use the ABBA image as well as the default cascade for detecting faces provided by
OpenCV.

# Create the haar cascade


faceCascade = cv2.CascadeClassifier(cascPath)
Now we create the cascade and initialize it with our face cascade. This loads the
face cascade into memory so it’s ready for use. Remember, the cascade is just an
XML file that contains the data to detect faces.

# Read the image


image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Here we read the image and convert it to grayscale. Many operations in OpenCV
are done in grayscale.

You might also like