• API
• FAQ
• Tools
• Archive
daily pastebin goal
10%
SHARE
TWEET

# Untitled

a guest Mar 21st, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import cv2
2. import numpy as np
3. import matplotlib.pyplot as plt
4.
6.
7. cv2.imshow('Original', image)
8. cv2.waitKey(0)
9.
10. # Cordinates of the 4 corners of the original image
11. points_A = np.float32([[320,15], [700,215], [85,610], [530,780]])
12.
13. # Cordinates of the 4 corners of the desired output
14. # We use a ratio of an A4 Paper 1 : 1.41
15. points_B = np.float32([[0,0], [420,0], [0,594], [420,594]])
16.
17. # Use the two sets of four points to compute
18. # the Perspective Transformation matrix, M
19. M = cv2.getPerspectiveTransform(points_A, points_B)
20.
21. warped = cv2.warpPerspective(image, M, (420,594))
22.
23. cv2.imshow('warpPerspective', warped)
24. cv2.waitKey(0)
25. cv2.destroyAllWindows()
26.
27.
28. import cv2
29. import numpy as np
30. import matplotlib.pyplot as plt
31.
33. rows,cols,ch = image.shape
34.
35. cv2.imshow('Original', image)
36. cv2.waitKey(0)
37.
38. # Cordinates of the 4 corners of the original image
39. points_A = np.float32([[320,15], [700,215], [85,610]])
40.
41. # Cordinates of the 4 corners of the desired output
42. # We use a ratio of an A4 Paper 1 : 1.41
43. points_B = np.float32([[0,0], [420,0], [0,594]])
44.
45. # Use the two sets of four points to compute
46. # the Perspective Transformation matrix, M
47. M = cv2.getAffineTransform(points_A, points_B)
48.
49. warped = cv2.warpAffine(image, M, (cols, rows))
50.
51. cv2.imshow('warpPerspective', warped)
52. cv2.waitKey(0)
53. cv2.destroyAllWindows()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top