1.
Computer Graphics Study Notes
Week7-01-0404
1.1. material
opencv24-python-tutorials-readthedocs-io-en-stable.pdf
1.2. Changing Color spaces
1.2.1. BGR Color Space
OpenCV use BGR color format. it all begins with the default BGR pixel format. It does not play well
with libraries that use the standard RGB pixel format. An RGB color is composed of three
components: Red (0-255), Green (0-255) and Blue (0-255).
1.2.2. Gray Color Space
Grayscaling is the process of converting an image from other color spaces e.g. RGB, CMYK, HSV, etc.
to shades of gray. It varies between complete black and complete white. Importance of grayscaling
Dimension reduction: For example, In RGB images there are three color channels and has three
dimensions while grayscale images are single-dimensional.
1.2.3. HSV Color Space
The HSV or Hue, Saturation and Value of a given object is the color space associated with the object
in OpenCV where Hue represents the color, Saturation represents the greyness and Value
represents the brightness and it is used to solve the problems related to computer vision because
of its better performance when compared to RGB or Red, Blue and Green color space and the Hue
range in HSV is [0,179], the Saturation range in HSV is [0,255] and the Value range in HSV is [0,255]
and to perform object detection, finding the range of HSV is necessary.
1.2.4. CMYK Color Space
The CMY and CMYK color spaces are often used in color printing. A CMY color space uses cyan,
magenta, and yellow (CMY) as its primary colors. Red, green, and blue are the secondary colors. The
CMYK color space is a variation on the CMY model. It adds black (Cyan, Magenta, Yellow, and blacK).
The CMYK color space closes the gap between theory and practice.
1.2.5. YUV, YIQ and YCbCr Colour Spaces
These are the television transmission colour spaces. YUV is used in Eu- ropean televisions, while YIQ
is used in Northern American television. The luma information of YUV, YIQ and YCbCr is stored in the
Y channel, while the colour information is stored in the U and V channels (for YUV), I and Q channels
(for YIQ) and Cb and Cr channels (for YCbCr). The YIQ is derived from the YUV colour space.
https://1library.net/article/yuv-yiq-ycbcr-colour-spaces-ycbcr-colour-spaces.z3j7987y
1.3. APIs of Changing Color-space
1.3.1. start jupyter notebook
1.3.2. read camera video
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
#Take each frame
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
#define range of blue color in HSV
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
#Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)
#Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
k = cv2.waitKey(5) & 0xFF# Convert BGR to HSV
if k == 27: #ESC to quit
break
cv2.destroyAllWindows()
1.3.3. BGR2HSV
1.4. Geometric Transformations of Images
OpenCV provides two transformation functions, cv.warpAffine and cv.warpPerspective, with
which you can perform all kinds of transformations. cv.warpAffine takes a 2x3 transformation
matrix while cv.warpPerspective takes a 3x3 transformation matrix as input.
https://docs.opencv.org/3.4/da/d6e/tutorial_py_geometric_transformations.html
1.4.1. scaling or resize
1.4.2. Translation
1.4.3. Rotation
1.4.4. Affine Transformation
1.4.5. Perspective Transformation
1.5. no homework
continued with Page58