0% found this document useful (0 votes)
10 views31 pages

IVA Record

The document is a Bonafide Certificate template from Anna University Regional Campus - Tirunelveli, certifying practical work done by a student during the 2024-2025 academic year. It includes various programming exercises related to image processing, such as building a T-pyramid, quad tree, geometric transformations, object detection, motion analysis, facial detection, and hand gesture recognition using OpenCV and YOLO. Each section outlines the aim, algorithm, program code, and expected results for the practical work.

Uploaded by

mathan4012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views31 pages

IVA Record

The document is a Bonafide Certificate template from Anna University Regional Campus - Tirunelveli, certifying practical work done by a student during the 2024-2025 academic year. It includes various programming exercises related to image processing, such as building a T-pyramid, quad tree, geometric transformations, object detection, motion analysis, facial detection, and hand gesture recognition using OpenCV and YOLO. Each section outlines the aim, algorithm, program code, and expected results for the practical work.

Uploaded by

mathan4012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Anna University Regional Campus - Tirunelveli

Tirunelveli - 627007

BONAFIDE CERTIFICATE
NAME : ………….…………………………………………………

REGISTER NUMBER : …………………………………………………………….

PROGRAMME : ………….…………………………………………………

COURSE CODE & TITLE : ………….………………………………………………….

DEPARTMENT : ………….…………………………………………………

SEMESTER : ………….…………………………………………………

Certified that this is a Bonafide Record of Practical Work Done


by Mr. /Ms. in the
Laboratory during the Period of

2024-2025.

DATE:

SIGNATURE OF FACULTY-IN-CHARGE SIGNATURE OF HOD

Submitted for the Practical Held On …………………………………………..

INTERNAL EXAMINER EXTERNAL EXAMINER


Index
S. Staff
Date Experiment Title Page No
No Signature
T-pyramid of an image.

AIM

ALGORITHM

1
OUTPUT

2
PROGRAM

import cv2
def build_t_pyramid(image_path):
img = cv2.imread(image_path)
levels = [img] # Level 0 (original)
for i in range(4):
img = cv2.pyrDown(img)
levels.append(img)
for i, level in enumerate(levels):
cv2.imshow(f'Level {i}', level)
cv2.waitKey(0)
cv2.destroyAllWindows()
build_t_pyramid('animal.jpg')

RESULT

3
4
QUAD TREE

AIM

ALGORITHM

5
OUTPUT

6
PROGRAM

import cv2
import numpy as np
def quad_tree(image_path):
img = cv2.imread(image_path)
img_copy = img.copy()
h, w, _ = img.shape
def split(x, y, w, h):
region = img[y:y+h, x:x+w]
gray = cv2.cvtColor(region, cv2.COLOR_BGR2GRAY)
if w <= 16 or h <= 16 or np.std(gray) < 10:
cv2.rectangle(img_copy, (x, y), (x+w, y+h), (0, 255, 0), 1)
else:
split(x, y, w//2, h//2)
split(x+w//2, y, w//2, h//2)
split(x, y+h//2, w//2, h//2)
split(x+w//2, y+h//2, w//2, h//2)
split(0, 0, w, h)
cv2.imshow('Quad Tree RGB', img_copy)
cv2.waitKey(0)
cv2.destroyAllWindows()
quad_tree('computer_boy.jpg')

RESULT

7
OUTPUT

8
GEOMETRIC TRANSFORMATIONS OF AN IMAGE

AIM

ALGORITHM

9
10
PROGRAM

import cv2

import numpy as np

img = cv2.imread('animal.jpg')

h, w = img.shape[:2]

rotated = cv2.warpAffine(img, cv2.getRotationMatrix2D((w//2, h//2), 45, 1), (w, h))

scaled = cv2.resize(img, (w//2, h//2))

skewed = cv2.warpAffine(img, np.float32([[1, 0.3, 0], [0.3, 1, 0]]), (w, h))

M_affine = cv2.getAffineTransform(np.float32([[50,50],[200,50],[50,200]]),

np.float32([[10,100],[200,50],[100,250]]))

affine = cv2.warpAffine(img, M_affine, (w, h))

M_persp = cv2.getPerspectiveTransform(np.float32([[0,0],[w-1,0],[0,h-1],[w-1,h-1]]),

np.float32([[0,0],[w-50,50],[50,h-50],[w-1,h-1]]))

bilinear = cv2.warpPerspective(img, M_persp, (w, h))

cv2.imshow('Original', img)

cv2.imshow('Rotated', rotated)

cv2.imshow('Scaled', scaled)

cv2.imshow('Skewed', skewed)

cv2.imshow('Affine', affine)

cv2.imshow('Bilinear', bilinear)

cv2.waitKey(0)

cv2.destroyAllWindows()

RESULT

11
12
OBJECT DETECTION AND RECOGNITION

AIM

ALGORITHM

13
OUTPUT

14
PROGRAM

from ultralytics import YOLO


import cv2
model = YOLO('yolov8n.pt') # 'n' = nano (small and
fast model)
img = cv2.imread('things.jpg')
results = model.predict(source=img, save=False,
conf=0.5)
for r in results:
for box in r.boxes:
x1, y1, x2, y2 = map(int, box.xyxy[0])
label = model.names[int(box.cls[0])]
conf = box.conf[0]
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(img, f"{label} {conf:.2f}", (x1, y1-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imshow('YOLOv8 Detection', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

RESULT :

15
16
MOTION ANALYSIS USING MOVING EDGES

AIM

ALGORITHM
OUTPUT
PROGRAM

import cv2
cap = cv2.VideoCapture('video.mp4')
ret, prev = cap.read()
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
diff = cv2.absdiff(prev, frame)
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 30, 255, cv2.THRESH_BINARY)
contours,_=cv2.findContours(thresh,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
if cv2.contourArea(c) > 500:
x, y, w, h = cv2.boundingRect(c)
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame,"Motion",(x,y-10),
cv2.FONT_HERSHEY_SIMPLEX,0.5,(0,255,0),2)
cv2.imshow('Motion Detection', frame)
if cv2.waitKey(30) == 27:
break
prev = frame.copy()
cap.release()
cv2.destroyAllWindows()

RESULT
FACIAL DETECTION AND RECOGNITION

AIM

ALGORITHM
OUTPUT
PROGRAM

import cv2
face_cascade=cv2.CascadeClassifier(cv2.data.haarcascades +
'haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 4)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame, "Face", (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255,
0), 2)
cv2.imshow('Face Detection', frame)
if cv2.waitKey(1) == 27: # Press ESC to exit
break
cap.release()
cv2.destroyAllWindows()

RESULT
HAND GESTURE RECOGNITION

AIM

ALGORITHM
OUTPUT
PROGRAM

import cv2
cap = cv2.VideoCapture(0)
fgbg = cv2.createBackgroundSubtractorMOG2()
while True:
ret, frame = cap.read()
if not ret:
break
mask = fgbg.apply(frame)
contours,_=cv2.findContours(mask,cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
if cv2.contourArea(c) > 500:
x, y, w, h = cv2.boundingRect(c)
cv2.rectangle(frame, (x, y), (x+w, y+h), (0,255,0), 2)
cv2.imshow('Motion Detection', frame)
if cv2.waitKey(1) == 27:
break
cap.release()
cv2.destroyAllWindows()

RESULT

You might also like