drawLandmarks.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef _renderFace_H_
  2. #define _renderFace_H_
  3. using namespace cv;
  4. using namespace std;
  5. #define COLOR Scalar(255, 200,0)
  6. // drawPolyLine draws a poly line by joining
  7. // successive points between the start and end indices.
  8. void drawPolyline
  9. (
  10. Mat &im,
  11. const vector<Point2f> &landmarks,
  12. const int start,
  13. const int end,
  14. bool isClosed = false
  15. )
  16. {
  17. // Gather all points between the start and end indices
  18. vector <Point> points;
  19. for (int i = start; i <= end; i++)
  20. {
  21. points.push_back(cv::Point(landmarks[i].x, landmarks[i].y));
  22. }
  23. // Draw polylines.
  24. polylines(im, points, isClosed, COLOR, 2, 16);
  25. }
  26. void drawLandmarks(Mat &im, vector<Point2f> &landmarks)
  27. {
  28. // Draw face for the 68-point model.
  29. if (landmarks.size() == 68)
  30. {
  31. drawPolyline(im, landmarks, 0, 16); // Jaw line
  32. drawPolyline(im, landmarks, 17, 21); // Left eyebrow
  33. drawPolyline(im, landmarks, 22, 26); // Right eyebrow
  34. drawPolyline(im, landmarks, 27, 30); // Nose bridge
  35. drawPolyline(im, landmarks, 30, 35, true); // Lower nose
  36. drawPolyline(im, landmarks, 36, 41, true); // Left eye
  37. drawPolyline(im, landmarks, 42, 47, true); // Right Eye
  38. drawPolyline(im, landmarks, 48, 59, true); // Outer lip
  39. drawPolyline(im, landmarks, 60, 67, true); // Inner lip
  40. }
  41. else
  42. { // If the number of points is not 68, we do not know which
  43. // points correspond to which facial features. So, we draw
  44. // one dot per landamrk.
  45. for(int i = 0; i < landmarks.size(); i++)
  46. {
  47. circle(im,landmarks[i],3, COLOR, FILLED);
  48. }
  49. }
  50. }
  51. #endif // _renderFace_H_