| 1 | #include "utils.hpp" |
| 2 | |
| 3 | void draw(cv::Mat& img, |
| 4 | const std::vector<Face>& faces) { |
| 5 | |
| 6 | const int thickness = 2; |
| 7 | const cv::Scalar bbox_color = { 0, 255, 0}; |
| 8 | const cv::Scalar text_color = {255, 255, 255}; |
| 9 | const std::vector<cv::Scalar> landmarks_color = { |
| 10 | {255, 0, 0}, // right eye |
| 11 | { 0, 0, 255}, // left eye |
| 12 | { 0, 255, 0}, // nose |
| 13 | {255, 0, 255}, // mouth right |
| 14 | { 0, 255, 255} // mouth left |
| 15 | }; |
| 16 | |
| 17 | for (auto i = 0; i < faces.size(); ++i) { |
| 18 | // draw bbox |
| 19 | cv::rectangle(img, |
| 20 | cv::Rect(faces[i].bbox_tlwh), |
| 21 | bbox_color, |
| 22 | thickness); |
| 23 | // put score by the corner of bbox |
| 24 | std::string str_score = std::to_string(faces[i].score); |
| 25 | if (str_score.size() > 6) { |
| 26 | str_score.erase(6); |
| 27 | } |
| 28 | cv::putText(img, |
| 29 | str_score, |
| 30 | cv::Point(faces[i].bbox_tlwh.x, faces[i].bbox_tlwh.y + 12), |
| 31 | cv::FONT_HERSHEY_DUPLEX, |
| 32 | 0.5, // Font scale |
| 33 | text_color); |
| 34 | // draw landmarks |
| 35 | const int radius = 2; |
| 36 | cv::circle(img, cv::Point(faces[i].landmarks.right_eye), radius, landmarks_color[0], thickness); |
| 37 | cv::circle(img, cv::Point(faces[i].landmarks.left_eye), radius, landmarks_color[1], thickness); |
| 38 | cv::circle(img, cv::Point(faces[i].landmarks.nose_tip), radius, landmarks_color[2], thickness); |
| 39 | cv::circle(img, cv::Point(faces[i].landmarks.mouth_right), radius, landmarks_color[3], thickness); |
| 40 | cv::circle(img, cv::Point(faces[i].landmarks.mouth_left), radius, landmarks_color[4], thickness); |
| 41 | } |
| 42 | } |