From 1ddaaf685a3c5febca32305fc588f982b5e4cdaa Mon Sep 17 00:00:00 2001 From: natanielruiz <nataniel777@hotmail.com> Date: 星期四, 28 九月 2017 06:21:15 +0800 Subject: [PATCH] Final code before submission --- code/utils.py | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/code/utils.py b/code/utils.py index 96c447b..b75d51f 100644 --- a/code/utils.py +++ b/code/utils.py @@ -82,3 +82,36 @@ cv2.line(img, (int(x3), int(y3)), (int(x3+x2-face_x),int(y3+y2-face_y)),(0,255,0),2) return img + +def draw_axis(img, yaw, pitch, roll, tdx=None, tdy=None, size = 100): + + pitch = pitch * np.pi / 180 + yaw = -(yaw * np.pi / 180) + roll = roll * np.pi / 180 + + if tdx != None and tdy != None: + tdx = tdx + tdy = tdy + else: + height, width = img.shape[:2] + tdx = width / 2 + tdy = height / 2 + + # X-Axis pointing to right. drawn in red + x1 = size * (cos(yaw) * cos(roll)) + tdx + y1 = size * (cos(pitch) * sin(roll) + cos(roll) * sin(pitch) * sin(yaw)) + tdy + + # Y-Axis | drawn in green + # v + x2 = size * (-cos(yaw) * sin(roll)) + tdx + y2 = size * (cos(pitch) * cos(roll) - sin(pitch) * sin(yaw) * sin(roll)) + tdy + + # Z-Axis (out of the screen) drawn in blue + x3 = size * (sin(yaw)) + tdx + y3 = size * (-cos(yaw) * sin(pitch)) + tdy + + cv2.line(img, (int(tdx), int(tdy)), (int(x1),int(y1)),(0,0,255),3) + cv2.line(img, (int(tdx), int(tdy)), (int(x2),int(y2)),(0,255,0),3) + cv2.line(img, (int(tdx), int(tdy)), (int(x3),int(y3)),(255,0,0),2) + + return img -- Gitblit v1.8.0