@@ -66,27 +66,38 @@ void ResultsMarker::mark(cv::Mat& image, const FaceInferenceResults& faceInferen
66
66
auto xCenter = faceBoundingBox.x + faceBoundingBoxWidth / 2 ;
67
67
auto yCenter = faceBoundingBox.y + faceBoundingBoxHeight / 2 ;
68
68
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)),
80
94
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),
86
98
cv::Point (static_cast <int >(xCenter + axisLength * sinY * cosP),
87
99
static_cast <int >(yCenter + axisLength * sinP)),
88
- cv::Scalar (255 , 0 , 255 ),
89
- 2 );
100
+ cv::Scalar (255 , 0 , 255 ), 2 );
90
101
91
102
putHighlightedText (
92
103
image,
0 commit comments