Guest User

Untitled

a guest
Jan 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. import random
  4. import math
  5. from scipy import linalg
  6.  
  7. no_of_images = 0
  8. t1_y = 10
  9. t2_y = 10
  10. for t1_x in range(30,315,1000): #30
  11. for top_size in range(200,355,1000):
  12. t2_x = t1_x + top_size
  13. b1_x = t1_x
  14. b2_x = t2_x
  15. for b_y in range(205,385,1000): #205,305
  16. b1_y = b_y
  17. b2_y = b_y
  18. no_of_images+=1
  19. image_name="road"
  20. location1 = "/path/to/image/"+image_name+".jpg"
  21. # Read source image.
  22. im_src = cv2.imread(location1)
  23. # Four corners in source image
  24. 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)]])
  25. location2 = "/path/to/dest/image/after homography.jpg"
  26. im_dst = cv2.imread(location2)
  27. # Four corners in destination image.
  28. for x in range(0,500,1):
  29. pts_dst = np.array([[500.0, 168.0],[640.0, 358.0],[0.0, 358.0],[500.0-x, 168.0]]) #150
  30.  
  31. # Calculate Homography
  32. h, status = cv2.findHomography(pts_src, pts_dst)
  33. print "h = ", h
  34.  
  35. # Warp source image to destination based on homography
  36. im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))
  37.  
  38. [[ 2.46712622e+00 -5.07091356e-03 -7.29742493e+01]
  39. [ 3.54718152e-16 5.63521116e-01 1.60487917e+02]
  40. [ 1.34873822e-18 -1.11718564e-03 1.00000000e+00]]
Add Comment
Please, Sign In to add comment