Skip to content

Instantly share code, notes, and snippets.

@khalidmeister
Created September 5, 2021 03:31
Show Gist options
  • Save khalidmeister/9c05b6e38e6571fa0f0c3894d78eaf22 to your computer and use it in GitHub Desktop.
Save khalidmeister/9c05b6e38e6571fa0f0c3894d78eaf22 to your computer and use it in GitHub Desktop.
# Get the y rotation degree
x = angles[0] * 360
y = angles[1] * 360
# print(y)
# See where the user's head tilting
if y < -10:
text = "Looking Left"
elif y > 10:
text = "Looking Right"
elif x < -10:
text = "Looking Down"
else:
text = "Forward"
# Add the text on the image
cv2.putText(image, text, (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
# Display the nose direction
nose_3d_projection, jacobian = cv2.projectPoints(nose_3d, rot_vec, trans_vec, cam_matrix, dist_matrix)
p1 = (int(nose_2d[0]), int(nose_2d[1]))
p2 = (int(nose_3d_projection[0][0][0]), int(nose_3d_projection[0][0][1]))
cv2.line(image, p1, p2, (255, 0, 0), 2)
cv2.imshow('Head Pose Estimation', image)
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment