AI For CV Labmanual
AI For CV Labmanual
Lab Manual
AD 701
AI for Computer Vision
9 Pose Estimation
pg.
Prestige Institute of Engineering Research & Management
Experiment No.
01 Aim :- OpenCV Installation and working with
Python
Experiment setup :- Install necessary Libraries OpenCV and numpy using pip
import cv2
Output:-
# Load an image
image = cv2.imread('bird.jpg')
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 02
Aim :- Write a Python script using OpenCV for Basic Image Processing , loading
images, Cropping, Resizing, Thresholding, Contour analysis, Bolb detection.
CODE:-
import cv2
import numpy as
np # Load an
image
image = cv2.imread('bird.jpg')
# Crop a region of interest (ROI)
x, y, w, h = 100, 50, 200, 150 # coordinates of the ROI
roi = image[y:y+h, x:x+w] # image crop to the specified ROI
# Applying thresholding
_, thresholded_image = cv2.threshold(gray_image, 127,
255, cv2.THRESH_BINARY)
# Blob detection
params =
cv2.SimpleBlobDetector_Params()
params.filterByArea = True
params.minArea = 100
params.filterByCircularity =
True params.minCircularity =
0.7
pg.
Prestige Institute of Engineering Research & Management
detector =
cv2.SimpleBlobDetector_create(params)
keypoints =
detector.detect(thresholded_image)
blob_image = cv2.drawKeypoints(image, keypoints, np.array([]), (0,
0,
pg.
Prestige Institute of Engineering Research & Management
255),
cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
Output:-
pg.
Prestige Institute of Engineering Research & Management
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 03
Aim :- Write a python script using OpenCV for Image Annotation – Drawing
lines, text circle, rectangle, ellipse on images
Code:-
import cv2
Output:-
import numpy as np
# Load an image
image = cv2.imread('bird.jpg')
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 04
Aim :- Write a Python script using OpenCV library for Image Enhancement,
Understanding Color spaces, color space conversion, Histogram equialization,
Convolution, Image smoothing, Gradients, Edge Detection
Code :-
import cv2
import numpy as np
# Load an image
image = cv2.imread('bird.jpg')
pg.
Prestige Institute of Engineering Research & Management
cv2.imshow('Convolution (Smoothing)',
smoothed_image) cv2.imshow('Gaussian Blur',
blurred_image)
cv2.imshow('Gradient Magnitude',
gradient_magnitude) cv2.imshow('Canny Edge
Detection', edges)
Output :-
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 05
Aim :- Write a python script using OpenCV library for Image Features and Image
Alignment – Image transforms – Fourier, Hough, Extract ORB Image features, Feature
matching and cloning
Code :-
import cv2
import numpy as np
# Perform Fourier
Transform f1 =
np.fft.fft2(image1)
fshift1 = np.fft.fftshift(f1)
magnitude_spectrum1 = np.log(np.abs(fshift1))
f2 = np.fft.fft2(image2)
fshift2 = np.fft.fftshift(f2)
magnitude_spectrum2 = np.log(np.abs(fshift2))
pg.
Prestige Institute of Engineering Research & Management
pg.
Prestige Institute of Engineering Research & Management
cv2.waitKey(0)
Output:-
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 06
Aim :- Write Python script using OpenCV library for Feature matching based image
alignment.
Code:-
import cv2
import numpy as np
pg.
Prestige Institute of Engineering Research & Management
Output:-
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 07
Aim :- Write Python script using OpenCV library for Image segmentation using
Graphcut / Grabcut.
Code:-
import cv2
import numpy as np
# Load an image
image = cv2.imread('bird.jpg')
pg.
Prestige Institute of Engineering Research & Management
Output :-
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 8
Aim :- Write Python script using OpenCV library for Camera Calibration with circular
grid.
Code:-
import numpy as
np import cv2
# Arrays to store object points and image points from all the
images obj_points = [] # 3D points in the real world
img_points = [] # 2D points in image plane
pg.
Prestige Institute of Engineering Research & Management
Output:-
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 9
Aim :- Write Python script using OpenCV library for Pose Estimation
Code:-
Output:-
pg.
Prestige Institute of Engineering Research & Management
Experiment No. 10
Aim :- Write Python script using OpenCV library for 3D Reconstruction – Creating
Depth map from stereo images
Code:-
Output:-
import numpy as
np import cv2
from matplotlib import pyplot as plt
pg.