Skip to content

Commit 5b65935

Browse files
Wovchenaeaidova
authored andcommitted
gaze_estimation_demo/cpp_gapi: explain head-pose-estimation-adas-0001 coordinate system
1 parent 27ead9c commit 5b65935

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

demos/gaze_estimation_demo/cpp_gapi/src/results_marker.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,38 @@ void ResultsMarker::mark(cv::Mat& image, const FaceInferenceResults& faceInferen
6666
auto xCenter = faceBoundingBox.x + faceBoundingBoxWidth / 2;
6767
auto yCenter = faceBoundingBox.y + faceBoundingBoxHeight / 2;
6868

69-
// center to right
70-
cv::line(image,
71-
cv::Point(xCenter, yCenter),
72-
cv::Point(static_cast<int>(xCenter + axisLength * (cosR * cosY + sinY * sinP * sinR)),
73-
static_cast<int>(yCenter + axisLength * cosP * sinR)),
74-
cv::Scalar(0, 0, 255),
75-
2);
76-
// center to top
77-
cv::line(image,
78-
cv::Point(xCenter, yCenter),
79-
cv::Point(static_cast<int>(xCenter + axisLength * (cosR * sinY * sinP + cosY * sinR)),
69+
// OX points from face center to camera
70+
// OY points from face center to right
71+
// OZ points from face center to up
72+
73+
// Rotation matrix:
74+
// Yaw Pitch Roll
75+
// [cosY -sinY 0] [ cosP 0 sinP] [1 0 0 ]
76+
// [sinY cosY 0] * [ 0 1 0 ] * [0 cosR -sinR] =
77+
// [ 0 0 1] [-sinP 0 cosP] [0 sinR cosR]
78+
79+
// [cosY*cosP cosY*sinP*sinR-sinY*cosR cosY*sinP*cosR+sinY*sinR]
80+
// = [sinY*cosP sinY*sinP*sinR+cosY*cosR sinY*sinP*cosR-cosY*sinR]
81+
// [ -cosP cosP*sinR cosP*cosR ]
82+
83+
// Multiply third row by -1 because screen drawing axis points down
84+
// Drop first row to project to a screen plane
85+
86+
// OY: center to right
87+
cv::line(image, cv::Point(xCenter, yCenter),
88+
cv::Point(static_cast<int>(xCenter + axisLength * (sinY * sinP * sinR + cosY * cosR)),
89+
static_cast<int>(yCenter - axisLength * cosP * sinR)),
90+
cv::Scalar(0, 0, 255), 2);
91+
// OZ: center to top
92+
cv::line(image, cv::Point(xCenter, yCenter),
93+
cv::Point(static_cast<int>(xCenter + axisLength * (cosR * sinY * sinP - cosY * sinR)),
8094
static_cast<int>(yCenter - axisLength * cosP * cosR)),
81-
cv::Scalar(0, 255, 0),
82-
2);
83-
// center to forward
84-
cv::line(image,
85-
cv::Point(xCenter, yCenter),
95+
cv::Scalar(0, 255, 0), 2);
96+
// OX: center to camera
97+
cv::line(image, cv::Point(xCenter, yCenter),
8698
cv::Point(static_cast<int>(xCenter + axisLength * sinY * cosP),
8799
static_cast<int>(yCenter + axisLength * sinP)),
88-
cv::Scalar(255, 0, 255),
89-
2);
100+
cv::Scalar(255, 0, 255), 2);
90101

91102
putHighlightedText(
92103
image,

0 commit comments

Comments
 (0)