Posts

Object Tracking In Motion

Drive Link:   https://drive.google.com/drive/folders/1USa7N0JCIeGGhZhkKP18-QuziOzh8riX?usp=share_link Code for Single object Tracking: import cv2 import imutils TrDict = { 'csrt' : cv2 .TrackerCSRT_create,           'kcf' : cv2 .TrackerKCF_create,           'boosting' : cv2 .TrackerBoosting_create,           'mil' : cv2 .TrackerMIL_create,           'tld' : cv2 .TrackerTLD_create,           'medianflow' : cv2 .TrackerMedianFlow_create,           'mosse' : cv2 .TrackerMOSSE_create} tracker = TrDict [ 'csrt' ]() #tracker = cv2.TrackerCSRT_create() v = cv2.VideoCapture(r'mot.mp4') ret , frame = v .read() #frame = imutils .resize( frame , width = 600 ) cv2 .imshow( 'Frame' , frame ) bb = cv2 .selectROI( 'Frame' , frame ) tracker .init( frame , bb ) while True :     ret , frame = v .read()     if not r...

E material for reference for TA 2 Exam

 Link: E material for reference for TA 2 Exam

YOLO - You Look Only Once

Drive Link =  https://drive.google.com/drive/u/0/folders/1USa7N0JCIeGGhZhkKP18-QuziOzh8riX   Code:  import cv2 import matplotlib.pyplot as plt import numpy as np import cvlib as cv # pip install cvlib from cvlib.object_detection import draw_bbox im = cv2.imread( r 'p2.jpeg' ) plt.imshow(im[:,:,::- 1 ]) bbox , conf = cv.detect_face(im) bbox conf labels = [] for i in range ( len (conf)):     labels.append( 'person' ) im2 = draw_bbox(im,bbox,labels,conf) plt.imshow(im2[:,:,::- 1 ]) im = cv2.imread( r 'a.jpg' ) bbox , labels, conf = cv.detect_common_objects(im) im2 = draw_bbox(im,bbox,labels,conf) plt.imshow(im2[:,:,::- 1 ]) labels

Assignment 5: Hough transform Line and Circle

Image Link:  https://drive.google.com/drive/folders/1USa7N0JCIeGGhZhkKP18-QuziOzh8riX?usp=share_link Code Line:  import cv2 import numpy as np img = cv2.imread('sudoku.png') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 50, 150, apertureSize=3) lines = cv2.HoughLines(edges, 1, np.pi / 180, 200) for line in lines:     rho,theta = line[0]     a = np.cos(theta)     b = np.sin(theta)     x0 = a * rho     y0 = b * rho     # x1 stores the rounded off value of (r * cos(theta) - 1000 * sin(theta))     x1 = int(x0 + 1000 * (-b))     # y1 stores the rounded off value of (r * sin(theta)+ 1000 * cos(theta))     y1 = int(y0 + 1000 * (a))     # x2 stores the rounded off value of (r * cos(theta)+ 1000 * sin(theta))     x2 = int(x0 - 1000 * (-b))     # y2 stores the rounded off value of (r * sin(theta)- 1000 * cos(theta))     y2 = int(y0 - 10...

Assignment 4: Canny Edge Detection

Image
Image Link:  https://drive.google.com/drive/folders/1USa7N0JCIeGGhZhkKP18-QuziOzh8riX?usp=share_link Canny Edge Detection Algorithm Basic Code: import cv2 import matplotlib.pyplot as plt import numpy as np imPth = r ' c m.jpg' img = plt.imread(imPth) plt.imshow(img, cmap = 'gray' ) E = cv2.Canny(img, 150 , 250 ) plt.subplot( 121 ) plt.imshow(img, cmap = 'gray' ) plt.axis( 'off' ) plt.subplot( 122 ) plt.imshow(E, cmap = 'gray' ) plt.axis( 'off' ) plt.show() Gaussian filter x = 0 y = - 1 sigma = 1 v = ( 1 /( 2 *np.pi*(sigma** 2 )))*np.exp(-(x** 2 + y** 2 )/( 2 *(sigma** 2 ))) v def f_getGaussianFilter ( s , sigma ):     maxX = s// 2     minX = -maxX     minY = minX     maxY = maxX     G = np.zeros((s,s))     for x in range (minX,maxX+ 1 ):         for y in range (minY,maxY+ 1 ):             v = ( 1 /( 2 *np.pi*(sigma** 2 )))*np.exp(-(x** 2 + y** 2 )/( 2 *(sigma** ...

Assignment 3: Blurring, Edge, Sharpening

 Image Link:  https://drive.google.com/drive/folders/1I_W9sVXhkm1Ofipu2-GelMfyrp3jViu-?usp=share_link Blurring, Edge, Sharpening Code: import numpy as np import matplotlib.pyplot as plt import cv2 from scipy import signal im = plt.imread( r ' bird.png' )[:,:,: 3 ] imGray = cv2.cvtColor(im,cv2.COLOR_RGB2GRAY) smoothingMask = np.ones(( 15 , 15 ))/ 225 imBlurred = signal.convolve2d(imGray,smoothingMask, boundary = 'symm' , mode = 'same' ) fig,(ax1,ax2) = plt.subplots( 1 , 2 , figsize =( 10 , 15 )) ax1.imshow(imGray, cmap = 'gray' ) ax2.imshow(imBlurred, cmap = 'gray' ) # Edge: xMask = np.array([[- 1 , 0 , 1 ],[- 1 , 0 , 1 ],[- 1 , 0 , 1 ]]) yMask = xMask.T.copy() fx = signal.convolve2d(imGray,xMask, boundary = 'symm' , mode = 'same' ) fy = signal.convolve2d(imGray,yMask, boundary = 'symm' , mode = 'same' ) fx.shape imGray.shape Gm = (fx** 2 + fy** 2 )** 0.5 plt.imshow(Gm, cmap = 'gray' ) th = Gm.max()...

Assignment 1.2 - Transformation

Images:  https://drive.google.com/drive/folders/1yCfFEXnEinsWBNejbDgEsziCHdESol1D?usp=share_link Code import numpy as np import matplotlib.pyplot as plt import cv2 grayImage = r'albert-einstein_gray.jpg' colourImage = r'tulips.jpg' I_gray = cv2.imread(grayImage,cv2.IMREAD_GRAYSCALE) I_BGR = cv2.imread(colourImage) plt.imshow(I_gray,cmap='gray') plt.imshow(I_BGR[:,:,::-1]) #scaling I_gray_resized = cv2.resize(src=I_gray,fx=2,fy=2,dsize=None) plt.imshow(I_gray_resized,cmap='gray') # plt.xticks([]) # plt.yticks([]) I_gray_resized.shape I_gray.shape I_BGR_resized = cv2.resize(src=I_BGR,fx=0.5,fy=2,dsize=None) plt.imshow(I_BGR_resized[:,:,::-1]) #Rotation  image = cv2.rotate(I_gray , cv2.ROTATE_90_CLOCKWISE) plt.imshow(I_gray_rot,cmap='gray') # access height and width of the image height, width = I_gray.shape # define center of rotation cr = (width/2,height/2) # get the rotation matrix M = cv2.getRotationMatrix2D(cr,30,1) # apply warpAffine() method t...