Haha, I'm working on the same project as you were last year. Did you find out a way to get the correct orientation?
edit: i used some opencv code to detect the orientation
def getOrientation(pts):
## [pca]
sz = len(pts)
data_pts = np.empty((sz, 2), dtype=np.float64)
for i in range(data_pts.shape[0]):
data_pts[i,0] = pts[i,0,0]
data_pts[i,1] = pts[i,0,1]
# Perform PCA analysis
mean = np.empty((0))
mean, eigenvectors = cv.PCACompute(data_pts, mean)
# Store the center of the object
cntr = (int(mean[0,0]), int(mean[0,1]))
angle = atan2(eigenvectors[0,1], eigenvectors[0,0]) # orientation in radians
angle = -int(np.rad2deg(angle)) - 90
return angle
def findAngle(img):
# Convert image to binary
_, bw = cv.threshold(img, 50, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
# Find all the contours in the thresholded image
_, contours, _ = cv.findContours(bw, cv.RETR_LIST, cv.CHAIN_APPROX_NONE)
for i, c in enumerate(contours):
# Calculate the area of each contour
area = cv.contourArea(c)
# Ignore contours that are too small or too large
if area < 3700 or 1000000 < area:
continue
# Find the orientation of each shape
return getOrientation(c, img)