import numpy as np from PIL import Image from computeH import computeH import matplotlib.pyplot as plt from warpImage import warpImage t1 = np.load('cc1.npy').transpose() t2 = np.load ('cc2.npy').transpose() H = computeH(t1, t2) inputIm = np.array(Image.open('crop1.jpg')) refIm = np.array(Image.open('crop2.jpg')) warpIm, mergeIm = warpImage(inputIm, refIm, H) plt.figure(1) plt.imshow(mergeIm) plt.figure(2) plt.imshow(warpIm) #%% import scipy.io as sio #t1 = sio.loadmat('points1.mat').transpose() #t2 = sio.loadmat('points2.mat').transpose() #t1 = [[90.16377295896746, 206.3963834707542, 156.9975240032448, 119.2219255869141, 239.3289564490938, 214.14522417154, 246.1091920622813, 323.5975990701392, 338.1266753841126, 369.1220381872556, 278.0731599530227, 355.5615669608804], # [178.0639945273812, 117.0418740086932, 160.6291029506132, 204.2163318925333, 137.3825808482559, 191.6244657537563, 286.5477643383822, 227.4628539948906, 167.4093385638008, 244.8977455716586, 82.17209085515719, 131.5709503226665]] #t2 = [1,2] l1 =[[
for point in new_point_list: x = point[0] / point[2] y = point[1] / point[2] x = x / 2 * image2.shape[0] y = y / 2 * image2.shape[1] resulting_points.append((x, y)) #display the points crops = image2.copy() for i in range(len(t2_copy)): cv2.circle(crops, (int(t2_copy[i, 0]), int(t2_copy[i, 1])), 10, (255, 0, 0), 2) for point in resulting_points: cv2.circle(crops, (int(point[1][0]), int(point[0][0])), 3, (0, 0, 255), -1) cv2.imshow("crop 2", crops) cv2.waitKey() cv2.destroyAllWindows() cv2.imwrite("Kendal_1_verify_homography.jpg", crops) #================================================================================================================ #test warp image #test the warp image function from warpImage import warpImage image1 = cv2.imread('kendal1.jpg') image2 = cv2.imread('kendal2.jpg') result, merged = warpImage(image1, image2, h_2) cv2.imwrite("kendal_result.jpg", result) cv2.imwrite("merged_kendal.jpg", merged)
new_point = np.dot(h_2,point) new_point_list.append(new_point) #convert from h result to x,y and return to correct scale resulting_points = [] for point in new_point_list: x = point[0]/point[2] y = point[1]/point[2] x = x/2*image2.shape[0] y = y/2*image2.shape[1] resulting_points.append((x,y)) #display the points crops = image2.copy() for i in range(len(cc2)): cv2.circle(crops,(int(cc2_copy[i,0]),int(cc2_copy[i,1])),10,(255,0,0),2) for point in resulting_points: cv2.circle(crops,(int(point[1][0]),int(point[0][0])),3,(0,0,255),-1) cv2.imshow("crop 2", crops) cv2.waitKey() cv2.destroyAllWindows() #================================================================================================================ #test warp image #test the warp image function from warpImage import warpImage result,failures = warpImage(image1,image2,h_2) cv2.imwrite("crop_result_1.jpg", result) cv2.imwrite("merged_crops.jpg", failures)
for point in new_point_list: x = point[0]/point[2] y = point[1]/point[2] x = x/2*image2.shape[0] y = y/2*image2.shape[1] resulting_points.append((x,y)) #display the points crops = image2.copy() for i in range(len(cc2)): cv2.circle(crops,(int(cc2_copy[i,0]),int(cc2_copy[i,1])),10,(255,0,0),2) for point in resulting_points: cv2.circle(crops,(int(point[1][0]),int(point[0][0])),3,(0,0,255),-1) cv2.imshow("crop 2", crops) cv2.waitKey() cv2.destroyAllWindows() cv2.imwrite("ORB_wdc_verify.jpg",crops) #================================================================================================================ #test warp image #test the warp image function from warpImage import warpImage image1 = cv2.imread('wdc1.jpg') image2 = cv2.imread('wdc2.jpg') result,large = warpImage(image1,image2,h_2) cv2.imwrite("wdc_result_ORB_Features.jpg", result) cv2.imwrite("wdc_merged_ORB_features.jpg", large)
points1 = np.load('./cc1.npy') points2 = np.load('./cc2.npy') H = computeH(points1.transpose(), points2.transpose()) # verify homography matrix # blue dot: original points on image # red dot: transformed points from another image plt.imshow(ref) plt.plot(points2.transpose()[0], points2.transpose()[1], "bo") homogeneous = np.concatenate( (points1.transpose(), [np.ones(points1.shape[0])])) transformed = np.matmul(H, homogeneous) plt.plot(transformed[0] / transformed[2], transformed[1] / transformed[2], "ro") plt.show() warpIm, mergeIm = warpImage(input, ref, H) plt.imshow(warpIm) plt.show() plt.imshow(mergeIm) plt.show() # wdc input = mpimg.imread('./wdc1.jpg') ref = mpimg.imread('./wdc2.jpg') points = np.load('./points.npy') points1 = points[:, 0] points2 = points[:, 1] # selected points plt.imshow(input) plt.plot(points1[0], points1[1], "bo") plt.show()
for i in range(len(cc1)): cc1_rev[i, 0] = cc1[i, 1] cc1_rev[i, 1] = cc1[i, 0] return cc1_rev t1 = np.load('points1.npy') t2 = np.load('points2.npy') img1 = cv2.imread('wdc1.jpg') img2 = cv2.imread('wdc2.jpg') t1, t2 = scale_down_2(t1, t2) t1 = scale_down(t1.T, img1) t2 = scale_down(t2.T, img2) t1 = reverse(t1.T) t2 = reverse(t2.T) t1 = t1.T t2 = t2.T h = computeH(t1, t2) final, merged = warpImage(img1, img2, h) cv2.imshow("final", final) cv2.waitKey() cv2.imshow("merged", merged) cv2.waitKey() cv2.destroyAllWindows()
from computeH import computeH from warpImage import warpImage import numpy as np import matplotlib.pyplot as plt import PIL fig, axis = plt.subplots(4, 2, figsize=(12, 12)) fig.suptitle('Images') images = [] Hcrop = computeH("cc1.npy", "cc2.npy") warpImageCrop, mergedImageCrop = warpImage("crop1.jpg", "crop2.jpg", Hcrop) images.append(axis[0, 0].imshow(warpImageCrop)) axis[0, 0].set_title('Warped Crop Circle') images.append(axis[0, 1].imshow(mergedImageCrop)) axis[0, 1].set_title('Merged Crop Circle') Hbuilding = computeH("wdc1.npy", "wdc2.npy") warpImageBuilding, mergedImageBuilding = warpImage("wdc1.jpg", "wdc2.jpg", Hbuilding) images.append(axis[1, 0].imshow(warpImageBuilding)) axis[1, 0].set_title('Warped WDC') images.append(axis[1, 1].imshow(mergedImageBuilding)) axis[1, 1].set_title('Merged WDC') Hmine = computeH("left.npy", "right.npy") warpImageMine, mergedImageMine = warpImage("left.jpg", "right.jpg", Hmine) images.append(axis[2, 0].imshow(warpImageMine)) axis[2, 0].set_title('Warped My Graphic')
for i in range(len(t2[0])): cv2.circle(crops, (t2[1][i], t2[0][i]), 10, (255, 0, 0), 2) for point in resulting_points: cv2.circle(crops, (int(point[1][0]), int(point[0][0])), 3, (0, 0, 255), -1) cv2.imshow("crop 2", crops) cv2.waitKey() cv2.destroyAllWindows() #============================================================================================================= #test the warp image function from warpImage import warpImage inputimg = cv2.imread('crop1.jpg') refImg = cv2.imread('crop2.jpg') result, failures = warpImage(inputimg, refImg, h) import cv2 cv2.imwrite("crop_result.jpg", result) #============================================================================================================= #test the warp image function from warpImage2 import warpImage2 inputimg = cv2.imread('crop1.jpg') refImg = cv2.imread('crop2.jpg') result = warpImage2(inputimg, refImg, h) #======================================================== #troubleshooting #start with 4 points inputIm = inputimg H = h output = refImg
points1 = points[0][:][:].T points2 = points[1][:][:].T except: onclick.listControl = True cursor = Cursor(ax[0], horizOn=True, vertOn=True, useblit=False, color='white', linewidth=1) cursor1 = Cursor(ax[1], horizOn=True, vertOn=True, useblit=False, color='white', linewidth=1) cid = fig.canvas.mpl_connect('button_release_event', onclick) plt.show() points = np.asarray([points1.T, points2.T]) np.save(sys.argv[1] + sys.argv[4], points) if len(points1) == len(points2) and len(points1) > 3: H = cp.computeH(points1, points2) (warpIm, mergeIm) = wi.warpImage(img1, img2, H) plt.imsave(sys.argv[1] + 'warped.jpg', warpIm) plt.imsave(sys.argv[1] + 'merged.jpg', mergeIm) ax[0].imshow(warpIm) ax[1].imshow(mergeIm) plt.show()