Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- cnt=0
- list=[(0,0),(0,0),(0,0),(0,0)]
- # mouse callback function
- def draw_circle(event,x,y,flags,param):
- if event == cv2.EVENT_LBUTTONUP:
- global list, cnt
- if cnt ==4:
- cnt=0
- cv2.circle(img_resized, (x, y), 1, (0, 255, 0), -1)
- list[cnt]=(x,y)
- cnt+=1
- img = cv2.imread('road.jpg')
- height, width=img.shape[:2]
- # resize
- img_resized=cv2.resize(img,None, fx=0.4,fy=0.4,interpolation=cv2.INTER_AREA)
- result=img_resized.copy()
- # mouse function
- cv2.namedWindow('before')
- cv2.setMouseCallback('before',draw_circle)
- # height & width
- h,w=img_resized.shape[:2]
- # before
- while(1):
- cv2.imshow('before', img_resized)
- if cnt==4:
- print(list)
- pts1 = np.float32([list[0], list[1], list[2], list[3]])
- pts2 = np.float32([[0, 0], [w, 0], [0, h], [w, h]])
- M = cv2.getPerspectiveTransform(pts1, pts2)
- dst = cv2.warpPerspective(result, M, (w, h))
- cv2.imshow('after', dst)
- #zeby te kropki zielone zniknely
- img_resized=result.copy()
- if cv2.waitKey(20) & 0xFF == 27:
- break
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement