Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import random
- import math
- from scipy import linalg
- no_of_images = 0
- t1_y = 10
- t2_y = 10
- for t1_x in range(30,315,1000): #30
- for top_size in range(200,355,1000):
- t2_x = t1_x + top_size
- b1_x = t1_x
- b2_x = t2_x
- for b_y in range(205,385,1000): #205,305
- b1_y = b_y
- b2_y = b_y
- no_of_images+=1
- image_name="road"
- location1 = "/path/to/image/"+image_name+".jpg"
- # Read source image.
- im_src = cv2.imread(location1)
- # Four corners in source image
- pts_src = np.array([[float(t2_x), float(t2_y)], [float(b2_x), float(b2_y)], [float(b1_x), float(b1_y)], [float(t1_x), float(t1_y)]])
- location2 = "/path/to/dest/image/after homography.jpg"
- im_dst = cv2.imread(location2)
- # Four corners in destination image.
- for x in range(0,500,1):
- pts_dst = np.array([[500.0, 168.0],[640.0, 358.0],[0.0, 358.0],[500.0-x, 168.0]]) #150
- # Calculate Homography
- h, status = cv2.findHomography(pts_src, pts_dst)
- print "h = ", h
- # Warp source image to destination based on homography
- im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))
- [[ 2.46712622e+00 -5.07091356e-03 -7.29742493e+01]
- [ 3.54718152e-16 5.63521116e-01 1.60487917e+02]
- [ 1.34873822e-18 -1.11718564e-03 1.00000000e+00]]
Add Comment
Please, Sign In to add comment