Skip to content

Instantly share code, notes, and snippets.

@bezero
Created June 11, 2019 09:45
Show Gist options
  • Save bezero/5e02381a7db601ed1b3a97e6a9d0100e to your computer and use it in GitHub Desktop.
Save bezero/5e02381a7db601ed1b3a97e6a9d0100e to your computer and use it in GitHub Desktop.
PCA using opencv
import cv2
import numpy as np
points = np.array([[0, 20], [980, 1020], [1020, 980], [20, 0]], dtype=np.float)
mean, eigenvectors = cv2.PCACompute(data=points, mean=None, maxComponents=1)
print(points)
print(eigenvectors)
theta = np.arctan((eigenvectors[0, 1])/(eigenvectors[0, 0]))
print('theta: ', theta)
print('theta deg: ', theta*180/np.pi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment