(An Autonomous Institution, Affiliated Anna University, Chennai)
Pullipalayam, Morur(Po.), Sankari(Tk.), Salem(Dt.) -637304.
DEPARTMENT OF
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
RECORD NOTEBOOK
CCS349-IMAGE AND VIDEO ANALYTICS LABORATORY
EVEN SEMESTER: 2023-2024
REGULATION-2021
STUDENT NAME:
REGISTER NO :
YEAR /SEM :
(An Autonomous Institution, Affiliated Anna University, Chennai)
Pullipalayam, Morur(Po.), Sankari(Tk.), Salem(Dt.) -637304.
CERTIFICATE
REG NO.
Certified that this is a bonafide record of Practical work done by
Mr/Ms………………………..........ofthe………………semester……………………………Bran
ch during the Academic year ……………………………in the CCS349-IMAGE AND VIDEO
ANALYTICS LABORATORY.
Submitted for the Practical Examination held on……………….
SIGNATURE OF FACULTY-IN-CHARGE SIGNATURE OF HEAD OF THE DEPARTMENT
Internal Examiner External Examiner
DEPARTMENT OF ARTIFICIAL INATELLIEGNCE AND DATA SCIENCE
Vision and Mission of the Institute
VISION
Our founding ethos remains at the core of the Institution’s vision. To be an institute of repute in
all fields of education by implementing the best practices akin to global standards for fostering
domain knowledge and developing research attitude among students to make them globally
competent.
MISSION
✓ Achieving excellence in Teaching & Learning process using state-of-the-art resources.
✓ Extending opportunity to upgrade faculty knowledge and skills.
✓ Implementing the best student training practices for requirement so find us trial scenario
of the state.
✓ Motivating faculty and students in research activity for real time application.
Vision of the Department:
To create the holistic environment for the development of Computer Science and
Engineering Graduates employable at the global level and to mould them through comprehensive
educational programs and quality research for developing their competency and innovation with
moral values.
Mission of the Department
1. Ensuring the academic growth by way of establishing centers of excellence and promoting
collaborative learning
2. Promoting research based projects in the emerging areas of technology convergence for the
benefit of students and faculty
3. Motivating the students to be successful, ethical and suitable for in dusty ready
PROGRAM OUTCOMES (POs)
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering
sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health and
safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods including
design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid
conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and
IT tools including prediction and modeling to complex engineering activities with an understanding of the
limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering
practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in societal
and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams,
and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and design
documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage projects
and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and
life-long learning in the broadest context of technological change.
PROGRAM SPECIFIC OBJECTIVES (PSOs)
PSO1: Programming Logic: Ability to identify, design and apply domain knowledge and computational skills to
intelligent solutions for Artificial Intelligence and Data Science related processes in our ecosystem.
PSO2: Software Design: Ability to critique the role of Artificial Intelligence and Data Science in multi-
disciplinary areas to transform thoughts into products through research and innovative careers.
PROGRAM EDUCATIONAL OBJECTIVES (PEOs)
PEO 1: Basic Skills – Graduates will be able to demonstrate their technical skills and competency in various
applications by providing creative and novel technological solutions.
PEO 2: Technical knowledge– Graduates will be able to ensure the effective contribution to the society through
critical thinking, innovations and research with the broad spectrum of skills in frontline technologies.
PEO 3: Managerial skills– Graduates will be equipped with multidisciplinary initiatives and visions towards the
growth of society with respect to ethical and lifelong learning.
CONTENTS
SL. PAGE
DATE NAME OF THE EXPERIMENT MARKS SIGNATURE
NO. NO.
Write a program that computes the T-pyramid
1 of an image
Write a program that derives the quad tree
2 representation of an image using the
homogeneity criterion of equal intensity.
Develop programs for the following geometric
3 transforms: (a) Rotation (b) Change of scale (c)
Skewing (d) Affine transform calculated from
three pairs of corresponding points (e) Bilinear
transform calculated from four pairs of
corresponding points.
Develop a Program to implement Object
4
Detection and Recognition
Develop a program for Facial Detection and
5 Recognition
Write a program to analyse the facial attributes
6 using Deep Face library.
AI Face Body and Hand Pose Estimation With
7 Media Pipe.
Exp No:1
Write a program that computes the T-pyramid of an image
Date:
Aim:
To write a program that computes the T-pyramid of an image
Algorithm:
Step 1: Import the necessary libraries: cv2 for image processing and [Link] for visualization.
Step 2: Read the input image using [Link].
Step 3: Convert the image to grayscale if needed (optional).
Step 4: Apply a contrast enhancement algorithm, such as histogram equalization or contrast stretching.
Step 5: Display the original and enhanced images using [Link].
Program:
Import cv2
Import numpy as np
from [Link] import cv2_imshow
def compute_t_pyramid(image_path, levels):
img = [Link](image_path, cv2.IMREAD_GRAYSCALE)
if img is None:
print(f"Error: Unable to load image from {image_path}")
return
cv2_imshow(img)
pyramid = [img]
for i in range(levels - 1):
img = [Link](img)
[Link](img)
cv2_imshow(img)
return pyramid
# Example usage
image_path = ' /content/[Link]'
pyramid_levels = 6
result_t_pyramid = compute_t_pyramid(image_path, pyramid_levels)
Output:
Result:
Thus the program that computes the T-pyramid of an image has been executed and verified successfully.
Exp No:2
Write a program that derives the quad tree representation of an image using the
Date: homogeneity criterion of equal intensity.
Aim:
To write a program that derives the quad tree representation of an image using the Homogeneity criterion
of equal intensity.
Algorithm:
Step 1: Read and Split the Image
Step 2: Concatenate the Quadrants
Step 3: Check Image Uniformity and Construct Quad tree
Step 4: Calculate Mean Colors
Step 5: Create and Display Quad tree
Step 6: End of Algorithm
Program:
import [Link] as plt
import [Link] as mpimg
import numpy as np
img = [Link]('/content/scenery_1.jpg')
[Link]
from operator import add
from functools import reduce
def split4(image):
half_split = np.array_split(image, 2)
res = map(lambda x: np.array_split(x, 2, axis=1), half_split)
return reduce(add, res)
split_img = split4(img)
split_img[0].shape
def concatenate4(north_west, north_east, south_west, south_east):
top = [Link]((north_west, north_east), axis=1)
bottom = [Link]((south_west, south_east), axis=1)
return [Link]((top, bottom), axis=0)
full_img = concatenate4(split_img[0], split_img[1], split_img[2], split_img[3])
[Link](full_img)
[Link]()
def checkEqual(myList):
first=myList[0]
return all((x==first).all() for x in myList)
class QuadTree:
def insert(self, img, level = 0):
[Link] = level
[Link] = calculate_mean(img).astype(int)
[Link] = ([Link][0], [Link][1])
[Link] = True
if not checkEqual(img):
split_img = split4(img)
[Link] = False
self.north_west = QuadTree().insert(split_img[0], level + 1)
self.north_east = QuadTree().insert(split_img[1], level + 1)
self.south_west = QuadTree().insert(split_img[2], level + 1)
self.south_east = QuadTree().insert(split_img[3], level + 1)
return self
def get_image(self, level):
if([Link] or [Link] == level):
return [Link]([Link], ([Link][0], [Link][1], 1))
return concatenate4(
self.north_west.get_image(level),
self.north_east.get_image(level),
self.south_west.get_image(level),
self.south_east.get_image(level))
def calculate_mean(img):
return [Link](img, axis=(0, 1))
means = [Link](list(map(lambda x: calculate_mean(x), split_img))).astype(int).reshape(2,2,3)
print(means)
[Link](means)
[Link]()
quadtree = QuadTree().insert(img)
[Link](quadtree.get_image(1))
[Link]()
[Link](quadtree.get_image(3))
[Link]()
[Link](quadtree.get_image(7))
[Link]()
[Link](quadtree.get_image(10))
[Link]()
Output:
Result:
Thus the program that derives the quad tree representation of an image using the homogeneity criterion
of equal intensity has been executed and verified successfully.
Exp No: 03 Develop programs for the following geometric transforms: (a) Rotation (b)
Change of scale (c) Skewing (d) Affine transform calculated from three pairs
Date: of corresponding points (e) Bilinear transform calculated from four pairs of
corresponding points.
Aim:
To write the python program for the geometric transforms: (a) Rotation (b) Change of scale (c)
Skewing (d) Affine transform calculated from three pairs of corresponding points (e) Bilinear transform
calculated from four pairs of corresponding points.
Algorithm:
Step 1: Import the necessary libraries: cv2 for image processing and [Link] for visualization.
Step 2: Read the input image using [Link].
Step 3: Convert the image to grayscale if needed (optional).
Step 4: Apply a contrast enhancement algorithm, such as histogram equalization or contrast stretching.
Step 5: Display the original and enhanced images using [Link].
Program:
a) Rotation
import cv2 as cv
import numpy as np
import [Link] as plt
image = [Link]("/content/[Link]")
h, w = [Link][:2]
rotation_matrix = cv.getRotationMatrix2D((w/2,h/2), -180, 0.5)
rotated_image = [Link](image, rotation_matrix, (w, h))
[Link]([Link](rotated_image, cv.COLOR_BGR2RGB))
[Link]("Rotation")
[Link]()
Output:
b) Change of scale
img = [Link]('/con
tent/[Link]')
res = [Link](img,None,fx=0.5, fy=0.5, interpolation = cv2.INTER_CUBIC)
cv2_imshow(res)
[Link]
Output:
c) Skewing
import cv2 as cv
import numpy as np
import [Link] as plt
image = [Link]("/content/[Link]")
fig, ax = [Link](1, 3, figsize=(16, 8))
# image size being 0.15 times of it's original size
image_scaled_3 = [Link](image, (200, 400), interpolation=cv.INTER_AREA)
ax[2].imshow([Link](image_scaled_3, cv.COLOR_BGR2RGB))
ax[2].set_title("Skewed Interpolation Scale")
Output:
d) Affine transformation
import cv2
import numpy as np
from [Link] import cv2_imshow
img = [Link]('/content/[Link]')
res = [Link](img,None,fx=0.5, fy=0.5, interpolation = cv2.INTER_CUBIC
rows,cols,ch = [Link]
pts1 = np.float32([[50,50],[200,50],[50,200]])
pts2 = np.float32([[10,100],[200,50],[100,250]])
M = [Link](pts1,pts2)
dst = [Link](img,M,(cols,rows))
cv2_imshow(dst)
[Link](0)
[Link]()
Output:
e) Bilinear transform
import numpy as np import cv2
from [Link] import cv2_imshow
def bilinear_transform(src_points, dest_points, img):
# Calculate the bilinear transform matrix using four pairs of corresponding points M =
[Link](src_points, dest_points)
# Apply the bilinear transform to the image
warped_img = [Link](img, M, ([Link][1], [Link][0])) return warped_img
# Load an example image
img = [Link]('/content/[Link]')
# Example corresponding points
src_points = np.float32([[0, 0], [[Link][1]-1, 0], [[Link][1]-1, [Link][0]-1], [0, [Link][0]-1]])
dest_points = np.float32([[0, 0], [300, 0], [300, 300], [0, 300]])
# Perform bilinear transform
Output:
Result:
Thus the programs for the following geometric transforms: (a) Rotation (b) Change of scale
(c) Skewing (d) Affine transform calculated from three pairs of corresponding points (e) Bilinear transform
calculated from four pairs of corresponding points has been executed and verified successfully.
Exp No: 04
Develop a program to implement Object Detection and Recognition
Date:
Aim:
To develop a program to implement Object Detection and Recognition.
Algorithm:
Step 1: Install Required Libraries: Ensure necessary libraries like OpenCV, TensorFlow, or PyTorch
are installed.
Step 2: Load Pre-trained Model: Utilize a pre-trained model (e.g., YOLO, SSD, or Faster R-CNN) for
objectdetection.
Step 3: Capture or Load Image/Video: Obtain input by capturing from a camera or loading an
image/videofile.
Step 4: Object Detection: Use the pre-trained model to detect objects in the input.
Step 5: Display Results: Show the original input alongside the detected objects, possibly with labeled
classnames and confidence scores.
Program:
from [Link] import
drive
[Link]('/content/gdriv
e')
%cd /content/gdrive/MyDrive/YOLOv9
!git clone [Link]
%cd yolov9
! pip install -r [Link]
!wget -P /mydrive/yolov9 [Link]
!wget -P /mydrive/yolov9 [Link]
!python [Link] --weights /mydrive/yolov9/[Link] –source
/content/gdrive/MyDrive/YOLOv9/yolov9/[Link] --device 0
!python [Link] --weights /mydrive/yolov9/[Link] --source
/content/gdrive/MyDrive/YOLOv9/yolov9/[Link] --
device 0from [Link] import Image
Image(filename=f"/content/gdrive/MyDrive/YOLOv9/yolov9/runs/detect/exp2/man-
[Link]",width=1000) from [Link] import Image
age(filename=f"/content/gdrive/MyDrive/YOLOv9/yolov9/runs/detect/exp3/[Link]",
width=1000)
Output:
Result:
Thus the develop a program to implement Object Detection and Recognition has been executed
successfully.
Exp No: 05 Develop a program for Facial Detection and Recognition
Date:
Aim:
To develop a program for Facial Detection and Recognition
Algorithm:
Step 1 : Import necessary libraries: face_recognition, numpy, [Link], [Link], and
[Link].
Step 2: Load sample images of known individuals and learn their face encodings.
Step 3: Create arrays of known face encodings and their corresponding names.
Step 4: Load an image with unknown faces.
Step 5: Find all the faces and face encodings in the unknown image using
face_recognition.face_locations.
Step 6: Compare the unknown face encodings with the known face encodings to identify matches.
Step 7: Draw bounding boxes around the identified faces and display the result using the
[Link]
Program:
from PIL import Image,
ImageDraw from [Link]
import display
# The program we will be finding faces on the example
below pil_im = [Link]('/content/Bezos and Elon
[Link]') display(pil_im)
!pip install
face_recognitionimport
face_recognition import
numpy as np
from PIL import Image,
ImageDraw from [Link]
import display
# This is example of running face recognition on a single imge.
obama_image = face_recognition.load_image_file("/content/[Link]")
obama_face_encoding =
face_recognition.face_encodings(obama_image)[0]
# Load a second sample picture and learn how to recognize it.
biden_image = face_recognition.load_image_file("/content/Elon
[Link]")biden_face_encoding =
face_recognition.face_encodings(biden_image)[0]
[
obama_face_encoding
,biden_face_encoding
]
known_face_names = [
"Bezos",
"Elon Musk"
]
print('Learned encoding for', len(known_face_encodings), 'images.')
len(face_recognition.face_encodings(biden_image)[0])
# Load an image with an unknown face
unknown_image = face_recognition.load_image_file("/content/Bezos and Elon [Link]")
# Find all the faces and face encodings in the unknown image
face_locations = face_recognition.face_locations(unknown_image)
face_encodings = face_recognition.face_encodings(unknown_image, face_locations)
# Convert the image to a PIL-format image so that we can draw on top of it with the Pillow library
# See [Link] for more about PIL/Pillow
pil_image = [Link](unknown_image)
# Create a Pillow ImageDraw Draw instance to draw with
draw = [Link](pil_image)
# Loop through each face found in the unknown image
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"
# Or instead, use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = [Link](face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
# Draw a box around the face using the Pillow module
[Link](((left, top), (right, bottom)), outline=(0, 0, 255))
# Draw a label with a name below the face
text_width, text_height = [Link](name)
[Link](((left, bottom - text_height - 10), (right, bottom)), fill=(0, 0, 255), outline=(0, 0, 255))
[Link]((left + 6, bottom - text_height - 5), name, fill=(255, 255, 255, 255))
# Remove the drawing library from memory as per the Pillow docs
del draw
# Display the resulting image
display(pil_image)
Output:
Result:
Thus the program develop a program for Facial Detection and Recognition has been executed
successfully.
Exp no: 06 Write a program to analyse the facial attributes using Deep Face library.
Date:
Aim :
To Write a program to analyse the facial attributes using Deep Face library.
Algorithm:
Step 1: The algorithm first detects faces in the image using a cascade of deep neural networks.
Step 2: It then aligns the facial features within the image using a 3D model to normalize for the pose
Step 3:After alignment, the algorithm computes a compact representation of the face using a deep
Step 4: The analyze() method will return a dictionary containing the analyzed facial attributes.
Step 5: Finally, it compares the representation to a database of known faces to find a match.
Program:
from [Link] import drive
[Link]('/content/drive')
%cd /content/drive/MyDrive/IVA-LAB/DeepFace
!pip install deepface
!git clone [Link]
%cd deepface
!pip install -e .
from deepface import DeepFace
faceAttr_Abdul = [Link](img_path = "/content/Abdul [Link] ", enforce_detection=False,
actions = ['age', 'gender', 'race', 'emotion'] )
OUT PUT:
[{'age': 52,
'region': {'x': 135,
'y': 46,
'w': 133,
'h': 133,
'left_eye': None,
'right_eye': None},
'face_confidence': 0.96,
'gender': {'Woman': 1.9691430032253265, 'Man': 98.03085327148438},
'dominant_gender': 'Man',
'race': {'asian': 1.686880350186783,
'indian': 10.921709427629777,
'black': 3.614285529937085,
'white': 27.970963362340527,
'middle eastern': 26.9416717360411,
'latino hispanic': 28.864484564723423},
'dominant_race': 'latino hispanic',
'emotion': {'angry': 8.648440541492164e-06,
'disgust': 2.127483611502612e-06,
'fear': 0.0008822305062494706,
'happy': 99.46964979171753,
'sad': 0.0001983363972613006,
'surprise': 0.0007296155217773048,
'neutral': 0.5285312421619892},
'dominant_emotion': 'happy'}]
Result:
Thus, the program to analyse the facial attributes using Deep Face library.
Exp no: 07 AI Face Body and Hand Pose Estimation with Media Pipe
Date:
Aim:
To write a program AI Face Body and Hand Pose Estimation With MediaPipe.
Algorithm:
Step 1: Set up the MediaPipe Holistic model with the desired confidence levels for detection and tracking.
Step 2: Use OpenCV to capture the video feed from the webcam.
Step 3: Convert the frame from BGR to RGB color space as MediaPipe requires.
Step 4: Process the frame with the Holistic model to get the landmarks.
Step 5: Use the drawing utilities provided by MediaPipe to draw the landmarks on the frame.
Step 6: Show the frame with the drawn landmarks in a window
Step 7: Allow the user to exit the loop and close the application by pressing a specific key (e.g., ‘q’)
Program:
1. Face Landmarks.
import cv2
import mediapipe as mp
from [Link] import cv2_imshow
# Initialize MediaPipe Face Mesh
mp_face_mesh = [Link].face_mesh
face_mesh = mp_face_mesh.FaceMesh(static_image_mode=True)
# Initialize MediaPipe Drawing
mp_drawing = [Link].drawing_utils
mp_drawing_styles = [Link].drawing_styles
# Define specific landmarks for eyes, nose, and mouth
# Use the correct landmark constants from mp_face_mesh
FACIAL_LANDMARKS = [
mp_face_mesh.FACEMESH_LEFT_EYE,
mp_face_mesh.FACEMESH_RIGHT_EYE,
mp_face_mesh.FACEMESH_LIPS,
mp_face_mesh.FACEMESH_NOSE
]
# Load the image
image = [Link]('/content/[Link]')
rgb_image = [Link](image, cv2.COLOR_BGR2RGB)
# Process the image and get face landmarks
results = face_mesh.process(rgb_image)
# Draw the specific face landmarks on the image
if results.multi_face_landmarks:
for face_landmarks in results.multi_face_landmarks:
for landmark_set in FACIAL_LANDMARKS:
mp_drawing.draw_landmarks(
image,
face_landmarks,
landmark_set,
landmark_drawing_spec=mp_drawing.DrawingSpec(color=(0, 255, 0), thickness=1,
circle_radius=1)
)
# Display the image
cv2_imshow(image)
[Link](0)
[Link]()
Output:
1. face landmarks
2. Pose Detections
Program:
import cv2
import mediapipe as mp
from [Link] import cv2_imshow
# Initialize MediaPipe solutions
mp_face_mesh = [Link].face_mesh
mp_pose = [Link]
mp_hands = [Link]
face_mesh = mp_face_mesh.FaceMesh(static_image_mode=True)
pose = mp_pose.Pose(static_image_mode=True)
hands = mp_hands.Hands(static_image_mode=True)
# Initialize MediaPipe Drawing
mp_drawing = [Link].drawing_utils
# Load the image
image = [Link]('/content/[Link]')
rgb_image = [Link](image, cv2.COLOR_BGR2RGB)
# Process the image and get face, body, and hand landmarks
face_results = face_mesh.process(rgb_image)
pose_results = [Link](rgb_image)
hand_results = [Link](rgb_image)
# Draw face landmarks
if face_results.multi_face_landmarks:
for face_landmarks in face_results.multi_face_landmarks:
mp_drawing.draw_landmarks(image, face_landmarks, mp_face_mesh.FACEMESH_CONTOURS)
# Draw pose landmarks
if pose_results.pose_landmarks:
mp_drawing.draw_landmarks(image, pose_results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
# Draw hand landmarks
if hand_results.multi_hand_landmarks:
for hand_landmarks in hand_results.multi_hand_landmarks:
mp_drawing.draw_landmarks(image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
# Display the image
cv2_imshow(image)
[Link](0)
[Link]()
Output:
Result:
Thus the program AI Face Body and Hand Pose Estimation With Media Pipe has been executedsuccessfully.