IVA Record
IVA Record
Tirunelveli - 627007
BONAFIDE CERTIFICATE
NAME : ………….…………………………………………………
PROGRAMME : ………….…………………………………………………
DEPARTMENT : ………….…………………………………………………
SEMESTER : ………….…………………………………………………
2024-2025.
DATE:
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]
M_affine = cv2.getAffineTransform(np.float32([[50,50],[200,50],[50,200]]),
np.float32([[10,100],[200,50],[100,250]]))
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]]))
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
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