def ablation(opts, cv_cover, cv_desk): sigmas = np.arange(0.1, 1.0, 0.1) ratios = np.arange(0.1, 1.0, 0.1) for s in sigmas: for r in ratios: opts.ratio = r opts.sigma = s print("Using ratio {:.2f}, sigma {:.2f}".format(r, s)) cvc = cv_cover.copy() cvd = cv_desk.copy() matches, locs1, locs2 = matchPics(cvc, cvd, opts) plotMatches(cv_cover, cv_desk, matches, locs1, locs2, opts)
from helper import plotMatches from opts import get_opts # Q2.1.6 opts = get_opts() # Read the image and convert to grayscale, if necessary cover = cv2.imread('../data/cv_cover.jpg') histogram = [] choice = [1, 17, 35] for i in range(36): # Rotate Image cover_rotate = scipy.ndimage.rotate(cover, i * 10, reshape=False) # Compute features, descriptors and Match features matches, locs1, locs2 = matchPics(cover, cover_rotate, opts) if i in choice: plotMatches(cover, cover_rotate, matches, locs1, locs2) # Update histogram histogram.append(matches.shape[0]) # Display histogram chosen_histogram = [histogram[1]] + [histogram[17]] + [histogram[35]] plt.bar(np.arange(3), chosen_histogram) plt.xlabel('Rotation Degrees') plt.ylabel('Matches Count') plt.xticks(np.arange(3), choice * 10) plt.title('Number of Matches for BRIEF Rotation') plt.show()
import cv2 from matchPics import matchPics from helper import plotMatches from opts import get_opts opts = get_opts() cv_cover = cv2.imread('../data/cv_cover.jpg') cv_desk = cv2.imread('../data/cv_desk.png') matches, locs1, locs2 = matchPics(cv_cover, cv_desk, opts) #display matched features plotMatches(cv_cover, cv_desk, matches, locs1, locs2)
opts = get_opts() #Q2.1.6 #Read the image and convert to grayscale, if necessary cv_cover = cv2.imread('../data/cv_cover.jpg') matchesnumber = np.zeros((36)) for i in range(36): #Rotate Image cv_cover_rot = scipy.ndimage.rotate(cv_cover, 10 * i) #Compute features, descriptors and Match features matches, locs1, locs2 = matchPics(cv_cover, cv_cover_rot, opts) #Update histogram matchesnumber[i] = np.size(matches, axis=0) if (i == 3): plotMatches(cv_cover, cv_cover_rot, matches, locs1, locs2) if (i == 15): plotMatches(cv_cover, cv_cover_rot, matches, locs1, locs2) if (i == 30): plotMatches(cv_cover, cv_cover_rot, matches, locs1, locs2) #Display histogram # plt.hist(matchesnumber, bins = 36) # plt.show() # x = np.arange(36) # plt.xlabel("Rotation iteration") # plt.ylabel("No. of matches") # plt.bar(x,matchesnumber)
from matplotlib import pyplot as plt opts = get_opts() #Write script for Q4.2x pano_left = cv2.imread('../IMG-7543.jpg') pano_right = cv2.imread('../IMG-7544.jpg') H1 = np.size(pano_left, axis = 0) W1 = np.size(pano_left, axis = 1) H2 = np.size(pano_right, axis = 0) W2 = np.size(pano_right, axis = 1) matches, locs1, locs2 = matchPics(pano_left, pano_right, opts) plotMatches(pano_left, pano_right, matches, locs1, locs2) locs1 = locs1[matches[:,0]] locs2 = locs2[matches[:,1]] locs1[:,[1,0]] = locs1[:,[0,1]] locs2[:,[1,0]] = locs2[:,[0,1]] H2to1, inliers = computeH_ransac(locs1, locs2, opts) corners_right = np.array([[0,0,W2-1,W2-1],[0,H2-1,H2-1,0],[1,1,1,1]]) corners_left_pred = H2to1 @ corners_right corners_left_pred = (corners_left_pred/corners_left_pred[-1,:]).round().astype(int) Hmax = np.amax([H1,np.amax(corners_left_pred[1,:])])
from opts import get_opts opts = get_opts() cv_cover = cv2.imread('../data/cv_cover.jpg') matches_hist = list() for i in range(36): #Rotate Image rotated_img = rotate(cv_cover, 10 * (i)) #Compute features, descriptors and Match features matches, locs1, locs2 = matchPics(cv_cover, rotated_img, opts) #Update histogram matches_hist.append(len(matches)) if (i % 11 == 0): plotMatches(cv_cover, rotated_img, matches, locs1, locs2) print(matches_hist) #Display histogram m_hist = np.asarray(matches_hist) ang = np.asarray([i for i in range(0, 360, 10)]).T y = np.arange(len(ang)) plt.bar(y, m_hist.T, align='center') plt.xticks(y, ang) plt.ylabel('matches')
import numpy as np import cv2 import skimage.io import skimage.color from opts import get_opts #Import necessary functions from matchPics import matchPics from planarH import computeH_ransac from helper import plotMatches #Write script for Q2.2.4 opts = get_opts() # Read cv_cover.jpg, cv_desk.png and hp_cover.jpg img1 = cv2.imread('D:/Academic/CMU/Course/2020Fall/CV/Homework/HW2_Handout/HW2_Handout/data\cv_cover.jpg',1) img2 = cv2.imread('D:/Academic/CMU/Course/2020Fall/CV/Homework/HW2_Handout/HW2_Handout/data\cv_desk.png',1) img3 = cv2.imread('D:/Academic/CMU/Course/2020Fall/CV/Homework/HW2_Handout/HW2_Handout/data\hp_cover.jpg',1) matches, locs1, locs2 = matchPics(img1,img1, opts) locs1 = locs1[matches[:,0],:] locs2 = locs2[matches[:,1],:] plotMatches(img1, img2, matches, locs1, locs2) result = computeH_ransac(locs2, locs1, opts)
import numpy as np import cv2 from matchPics import matchPics from helper import plotMatches from opts import get_opts from briefRotTest import rotTest from planarH import computeH_norm ## COLLABORATORS: CORINNE ALINI, HUSAM WADI, DANIEL BRONSTEIN, LIU JINKUN, JONATHAN SCHWARTZ opts = get_opts() ''' cv_cover = cv2.imread('../data/cv_cover.jpg') cv_desk = cv2.imread('../data/cv_desk.png') matches, locs1, locs2 = matchPics(cv_cover, cv_desk, opts) # display matched features plotMatches(cv_cover, cv_desk, matches, locs1, locs2) # Q2.1.6 RotTest rotTest() #Q2.2.2 for debug ''' x1 = np.array([[1, 2], [3,4], [5,6], [7,8]]) x2 = np.array([[10,20],