def generatePanorama(im1, im2): locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) pano_im_no_clip = imageStitching_noClip(im1, im2, H2to1) return pano_im_no_clip
def generatePanaroma(im1, im2): ''' Generate and save panorama of im1 and im2. INPUT im1 and im2 - two images for stitching OUTPUT Blends img1 and warped img2 (with no clipping) and saves the panorama image. ''' ###################################### # TO DO ... t = time.time() locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) print('Time to compute Brieflite: ' + str(time.time() - t)) t = time.time() matches = briefMatch(desc1, desc2) print('Time to compute BriefMatch: ' + str(time.time() - t)) t = time.time() H = ransacH(matches, locs1, locs2, num_iter=2000, tol=2) print('Time to compute Ransac: ' + str(time.time() - t)) np.save('../results/q6_1.npy', H) return imageStitching_noClip(im1, im2, H)
def generatePanaroma(im1, im2): ''' Generate and save panorama of im1 and im2. INPUT im1 and im2 - two images for stitching OUTPUT Blends img1 and warped img2 (with no clipping) and saves the panorama image. ''' ###################################### # TO DO ... locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) locs1[:, [0, 1]] = locs1[:, [1, 0]] locs2[:, [0, 1]] = locs2[:, [1, 0]] bestH = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) #print(bestH) output = imageStitching(im1, im2, bestH) #output=imageStitching_noClip(im1,im2,bestH) return output
def generatePanorama(im1, im2): ''' Accepts two images as input, computes keypoints and descriptors for both the images, finds putative feature correspondences by matching keypoint descriptors, estimates a homography using RANSAC and then warps one of the images with the homography so that they are aligned and then overlays them [input] * im1 - Input image 1 * im2 - Input image 2 [output] * pano_im - Output panorama image ''' # Compute keypoints and descriptors print('Computing feature descriptors for im1...') locs1, desc1 = briefLite(im1) print('Computing feature descriptors for im2...') locs2, desc2 = briefLite(im2) # Match keypoint descriptors matches = briefMatch(desc1, desc2) # Estimate homography H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) # Align and blend the images to form the panorama pano_im = imageStitching_noClip(im1, im2, H2to1) return pano_im
def generatePanorama(im1, im2): ''' Returns a panorama of im1 and im2 without cliping. ''' ###################################### # TO DO ... locs1, desc1 = briefLite(im1) print(f'No of desc1 is {desc1.shape[0]}') locs2, desc2 = briefLite(im2) print(f'No of desc2 is {desc2.shape[0]}') matches = briefMatch(desc1, desc2) print(f'No of matches is {matches.shape[0]}') H2to1 = ransacH(matches, locs1, locs2, num_iter=10000, tol=1) #Save result np.save('../results/q6_1.npy', H2to1) #pano_im = imageStitching_mask(im1, im2, H2to1) pano_im = imageStitching(im1, im2, H2to1) pano_im = imageStitching_noClip(im1, im2, H2to1) cv2.imwrite('../results/q6_3.jpg', pano_im) return pano_im
def generatePanaroma(img1, img2): im1 = cv2.imread(img1) im2 = cv2.imread(img2) locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) H2to1 = ransacH(matches, locs1, locs2, num_iter=10000, tol=2) return imageStitching_noClip(im1, im2, H2to1)
def generatePanorama(im1, im2): locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) pano_im = imageStitching_noClip(im1, im2, H2to1) cv2.imwrite('../results/q6_3.jpg', pano_im)
def generatePanorama(im1, im2): locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches, m = briefMatch(desc1, desc2) m, n = matches.shape H2to1 = ransacH(matches, m, locs1, locs2, num_iter=5000, tol=2) # To get the M - Translation and scalling matrix first_1 = np.array([[1064], [576], [1]]) first_2 = np.array([[0], [0], [1]]) first_3 = np.array([[0], [576], [1]]) first_4 = np.array([[1064], [0], [1]]) second_1 = np.matmul(H2to1, first_1) n4 = second_1[2, 0] second_1 = second_1 / n4 print(second_1) second_2 = np.matmul(H2to1, first_2) n4 = second_2[2, 0] second_2 = second_2 / n4 print(second_2) second_3 = np.matmul(H2to1, first_3) n4 = second_3[2, 0] second_3 = second_3 / n4 print(second_3) second_4 = np.matmul(H2to1, first_4) n4 = second_4[2, 0] second_4 = second_4 / n4 print(second_4) # Through geometry image_width = second_1[1] - second_4[1] image_height = second_4[0] - second_3[0] # 600 and 1500 are previously defined distances in the function (Random values taken) translation_height = image_height - 600 translation_width = 1500 - image_width # im1 = cv2.warpPerspective(im1,np.eye(3),(3000,600)) M = np.eye(3) + np.array([[.85, 0, translation_height], [0, .85, 400], [0, 0, 1]]) warp_im_1 = cv2.warpPerspective(im1, M, (1714, 815)) warp_im_2 = cv2.warpPerspective(im2, np.matmul(M, H2to1), (1714, 815)) im3 = np.maximum(warp_im_1, warp_im_2) return im3
def generatePanorama(im1, im2): ''' Returns a panorama of im1 and im2 without cliping. ''' ###################################### # TO DO ... locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) pano_im = imageStitching_noClip(im1, im2, H2to1) return pano_im
def generatePanorama(im1, im2): ''' Returns a panorama of im1 and im2 without cliping. ''' ###################################### locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) bestH = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) blended_image = imageStitching(im1, im2, bestH) panorama = imageStitching_noClip(im1, im2, bestH) cv2.imwrite('../results/q6_3.jpg', panorama) cv2.imshow('6.3p', panorama)
def generatePanorama(im1, im2): """ This is to generate the panorama given im1 and im2 by detecting and matching keypoints, calculating homography with RANSAC. Args: im1: input image1 in numpy.array with size [H, W, 3] im2: input image2 in numpy.array with size [H, W, 3] Returns: im3: stitched panorama in numpy.array. """ locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) im3 = imageStitching_noClip(im1, im2, H2to1) return im3
def main(args): im1 = cv2.imread(args.im1) im2 = cv2.imread(args.im2) # Compute BREIF descriptors locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) # Match descriptors matches = briefMatch(desc1, desc2) # Estimate best Homogrpahy H H2to1, _ = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) # Stitch images together pano_im = imageStitching_noClip(im1, im2, H2to1) # Save and show cv2.imwrite('../results/panoImg.jpg', pano_im)
def generatePanorama(im1, im2): # computes keypoints and descriptors for both the images locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) # finds putative feature correspondences by matching keypoint descriptors matches = briefMatch(desc1, desc2) # estimates a homography using RANSAC H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) # warps one of the images with the homography so that they are aligned and then overlays them. pano_im = imageStitching_noClip(im1, im2, H2to1) # save and display panaroma cv2.imwrite('../results/panoImg.jpg', pano_im) cv2.imshow('panoramas', pano_im) cv2.waitKey(0) cv2.destroyAllWindows()
def generatePanaroma(im1, im2): ''' Generate and save panorama of im1 and im2. INPUT im1 and im2 - two images for stitching OUTPUT Blends img1 and warped img2 (with no clipping) and saves the panorama image. ''' ###################################### locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) pano_im = imageStitching_noClip(im1, im2, H2to1) cv2.imwrite('../results/6_3_stitched.jpg', pano_im) return pano_im
def generatePanorama(im1, im2): locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) pano_im_no_clip = imageStitching_noClip(im1, im2, H2to1) return pano_im_no_clip if __name__ == '__main__': im1 = cv2.imread('../data/incline_L.png') im2 = cv2.imread('../data/incline_R.png') print(im1.shape) locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) # plotMatches(im1,im2,matches,locs1,locs2) H2to1 = ransacH(matches, locs1, locs2, num_iter=5000, tol=2) # pano_im = imageStitching(im1, im2, H2to1) print(H2to1) # np.save('../results/q6_1.npy', H2to1) # cv2.imwrite('../results/6_1.jpg', pano_im) # cv2.imshow('panoramas', pano_im) # cv2.waitKey(0) # cv2.destroyAllWindows() # pano_im_no_clip = imageStitching_noClip(im1, im2, H2to1) pano_im_no_clip = generatePanorama(im1, im2) cv2.imwrite('../results/q6_2_pan.jpg', pano_im_no_clip) cv2.imshow('panoramas_no_clip', pano_im_no_clip) cv2.waitKey(0) cv2.destroyAllWindows()
# im1 = cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY) # im2 = cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY) # im3 = cv2.cvtColor(im3, cv2.COLOR_BGR2GRAY) # to resize im3 is better. im3 = cv2.resize(im3, (im1.shape[1], im1.shape[0])) # im1 = cv2.resize(im1, (im3.shape[1], im3.shape[0])) locs1, desc1 = briefLite(im1) locs2, desc2 = briefLite(im2) matches = briefMatch(desc1, desc2) print(im1.shape) print(im2.shape) print(im3.shape) # plotMatches(im1,im2,matches,locs1,locs2) num_iter = 5e3 tol = 3 bestH = ransacH(matches, locs1, locs2, num_iter=num_iter, tol=tol) print('H:', bestH) final_img = compositeH(bestH, im2, im3) # final_img = cv2.warpPerspective(im3, bestH, (im2.shape[1],im2.shape[0])) res = final_img cv2.imshow("iter=%d_tol=%d" % (num_iter, tol), res) cv2.waitKey(0) cv2.destroyAllWindows()