Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4.  
  5. cnt=0
  6. list=[(0,0),(0,0),(0,0),(0,0)]
  7.  
  8. # mouse callback function
  9. def draw_circle(event,x,y,flags,param):
  10. if event == cv2.EVENT_LBUTTONUP:
  11. global list, cnt
  12. if cnt ==4:
  13. cnt=0
  14. cv2.circle(img_resized, (x, y), 1, (0, 255, 0), -1)
  15. list[cnt]=(x,y)
  16. cnt+=1
  17.  
  18.  
  19. img = cv2.imread('road.jpg')
  20. height, width=img.shape[:2]
  21. # resize
  22. img_resized=cv2.resize(img,None, fx=0.4,fy=0.4,interpolation=cv2.INTER_AREA)
  23. result=img_resized.copy()
  24.  
  25.  
  26. # mouse function
  27. cv2.namedWindow('before')
  28. cv2.setMouseCallback('before',draw_circle)
  29.  
  30. # height & width
  31. h,w=img_resized.shape[:2]
  32.  
  33. # before
  34.  
  35. while(1):
  36.  
  37. cv2.imshow('before', img_resized)
  38.  
  39. if cnt==4:
  40. print(list)
  41. pts1 = np.float32([list[0], list[1], list[2], list[3]])
  42. pts2 = np.float32([[0, 0], [w, 0], [0, h], [w, h]])
  43. M = cv2.getPerspectiveTransform(pts1, pts2)
  44. dst = cv2.warpPerspective(result, M, (w, h))
  45. cv2.imshow('after', dst)
  46. #zeby te kropki zielone zniknely
  47. img_resized=result.copy()
  48.  
  49. if cv2.waitKey(20) & 0xFF == 27:
  50. break
  51. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement