Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- from matplotlib import pyplot as plt
- import matplotlib.lines as mlines
- points = np.array([[4,10], [7,8], [10,5], [9,9], [13,9], [15,10]], dtype=np.float32)
- def plot(points):
- plt.axis([0, 20, 0, 20])
- plt.gca().add_line(mlines.Line2D([0, 20], [10, 10]))
- plt.gca().add_line(mlines.Line2D([10, 10], [0, 20]))
- plt.gca().add_line(mlines.Line2D([0, 20], [0, 20]))
- plt.gca().add_line(mlines.Line2D([20, 0], [0, 20]))
- plt.gca().invert_yaxis()
- plt.scatter(points[:,0], points[:,1], marker='o', c='r')
- for point in points:
- plt.gca().annotate('(%d,%d)' % tuple(point) , tuple(point + (0.3,-0.3)))
- m_1 = cv2.getRotationMatrix2D((10,10), -45, 1.0)
- m_2 = cv2.getRotationMatrix2D((10,10), 45, 1.0)
- rot_1 = cv2.transform(points.reshape(-1,1,2), m_1).reshape(-1,2)
- rot_2 = cv2.transform(points.reshape(-1,1,2), m_2).reshape(-1,2)
- plt.figure(1)
- plt.subplot(131)
- plot(points)
- plt.subplot(132)
- plot(rot_1)
- plt.subplot(133)
- plot(rot_2)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement