25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

154 satır
5.0 KiB

  1. // Copyright 2016 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package vision
  15. import (
  16. "log"
  17. pb "google.golang.org/genproto/googleapis/cloud/vision/v1"
  18. )
  19. // FaceLandmarks contains the positions of facial features detected by the service.
  20. type FaceLandmarks struct {
  21. Eyebrows Eyebrows
  22. Eyes Eyes
  23. Ears Ears
  24. Nose Nose
  25. Mouth Mouth
  26. Chin Chin
  27. Forehead *pb.Position
  28. }
  29. // Eyebrows represents a face's eyebrows.
  30. type Eyebrows struct {
  31. Left, Right Eyebrow
  32. }
  33. // Eyebrow represents a face's eyebrow.
  34. type Eyebrow struct {
  35. Top, Left, Right *pb.Position
  36. }
  37. // Eyes represents a face's eyes.
  38. type Eyes struct {
  39. Left, Right Eye
  40. }
  41. // Eye represents a face's eye.
  42. type Eye struct {
  43. Left, Right, Top, Bottom, Center, Pupil *pb.Position
  44. }
  45. // Ears represents a face's ears.
  46. type Ears struct {
  47. Left, Right *pb.Position
  48. }
  49. // Nose represents a face's nose.
  50. type Nose struct {
  51. Left, Right, Top, Bottom, Tip *pb.Position
  52. }
  53. // Mouth represents a face's mouth.
  54. type Mouth struct {
  55. Left, Center, Right, UpperLip, LowerLip *pb.Position
  56. }
  57. // Chin represents a face's chin.
  58. type Chin struct {
  59. Left, Center, Right *pb.Position
  60. }
  61. // FaceFromLandmarks converts the list of face landmarks returned by the service
  62. // to a FaceLandmarks struct.
  63. func FaceFromLandmarks(landmarks []*pb.FaceAnnotation_Landmark) *FaceLandmarks {
  64. face := &FaceLandmarks{}
  65. for _, lm := range landmarks {
  66. switch lm.Type {
  67. case pb.FaceAnnotation_Landmark_LEFT_OF_LEFT_EYEBROW:
  68. face.Eyebrows.Left.Left = lm.Position
  69. case pb.FaceAnnotation_Landmark_RIGHT_OF_LEFT_EYEBROW:
  70. face.Eyebrows.Left.Right = lm.Position
  71. case pb.FaceAnnotation_Landmark_LEFT_OF_RIGHT_EYEBROW:
  72. face.Eyebrows.Right.Left = lm.Position
  73. case pb.FaceAnnotation_Landmark_RIGHT_OF_RIGHT_EYEBROW:
  74. face.Eyebrows.Right.Right = lm.Position
  75. case pb.FaceAnnotation_Landmark_LEFT_EYEBROW_UPPER_MIDPOINT:
  76. face.Eyebrows.Left.Top = lm.Position
  77. case pb.FaceAnnotation_Landmark_RIGHT_EYEBROW_UPPER_MIDPOINT:
  78. face.Eyebrows.Right.Top = lm.Position
  79. case pb.FaceAnnotation_Landmark_MIDPOINT_BETWEEN_EYES:
  80. face.Nose.Top = lm.Position
  81. case pb.FaceAnnotation_Landmark_NOSE_TIP:
  82. face.Nose.Tip = lm.Position
  83. case pb.FaceAnnotation_Landmark_UPPER_LIP:
  84. face.Mouth.UpperLip = lm.Position
  85. case pb.FaceAnnotation_Landmark_LOWER_LIP:
  86. face.Mouth.LowerLip = lm.Position
  87. case pb.FaceAnnotation_Landmark_MOUTH_LEFT:
  88. face.Mouth.Left = lm.Position
  89. case pb.FaceAnnotation_Landmark_MOUTH_RIGHT:
  90. face.Mouth.Right = lm.Position
  91. case pb.FaceAnnotation_Landmark_MOUTH_CENTER:
  92. face.Mouth.Center = lm.Position
  93. case pb.FaceAnnotation_Landmark_NOSE_BOTTOM_RIGHT:
  94. face.Nose.Right = lm.Position
  95. case pb.FaceAnnotation_Landmark_NOSE_BOTTOM_LEFT:
  96. face.Nose.Left = lm.Position
  97. case pb.FaceAnnotation_Landmark_NOSE_BOTTOM_CENTER:
  98. face.Nose.Bottom = lm.Position
  99. case pb.FaceAnnotation_Landmark_LEFT_EYE:
  100. face.Eyes.Left.Center = lm.Position
  101. case pb.FaceAnnotation_Landmark_RIGHT_EYE:
  102. face.Eyes.Right.Center = lm.Position
  103. case pb.FaceAnnotation_Landmark_LEFT_EYE_TOP_BOUNDARY:
  104. face.Eyes.Left.Top = lm.Position
  105. case pb.FaceAnnotation_Landmark_LEFT_EYE_RIGHT_CORNER:
  106. face.Eyes.Left.Right = lm.Position
  107. case pb.FaceAnnotation_Landmark_LEFT_EYE_BOTTOM_BOUNDARY:
  108. face.Eyes.Left.Bottom = lm.Position
  109. case pb.FaceAnnotation_Landmark_LEFT_EYE_LEFT_CORNER:
  110. face.Eyes.Left.Left = lm.Position
  111. case pb.FaceAnnotation_Landmark_RIGHT_EYE_TOP_BOUNDARY:
  112. face.Eyes.Right.Top = lm.Position
  113. case pb.FaceAnnotation_Landmark_RIGHT_EYE_RIGHT_CORNER:
  114. face.Eyes.Right.Right = lm.Position
  115. case pb.FaceAnnotation_Landmark_RIGHT_EYE_BOTTOM_BOUNDARY:
  116. face.Eyes.Right.Bottom = lm.Position
  117. case pb.FaceAnnotation_Landmark_RIGHT_EYE_LEFT_CORNER:
  118. face.Eyes.Right.Left = lm.Position
  119. case pb.FaceAnnotation_Landmark_LEFT_EYE_PUPIL:
  120. face.Eyes.Left.Pupil = lm.Position
  121. case pb.FaceAnnotation_Landmark_RIGHT_EYE_PUPIL:
  122. face.Eyes.Right.Pupil = lm.Position
  123. case pb.FaceAnnotation_Landmark_LEFT_EAR_TRAGION:
  124. face.Ears.Left = lm.Position
  125. case pb.FaceAnnotation_Landmark_RIGHT_EAR_TRAGION:
  126. face.Ears.Right = lm.Position
  127. case pb.FaceAnnotation_Landmark_FOREHEAD_GLABELLA:
  128. face.Forehead = lm.Position
  129. case pb.FaceAnnotation_Landmark_CHIN_GNATHION:
  130. face.Chin.Center = lm.Position
  131. case pb.FaceAnnotation_Landmark_CHIN_LEFT_GONION:
  132. face.Chin.Left = lm.Position
  133. case pb.FaceAnnotation_Landmark_CHIN_RIGHT_GONION:
  134. face.Chin.Right = lm.Position
  135. default:
  136. log.Printf("vision: ignoring unknown face annotation landmark %s", lm.Type)
  137. }
  138. }
  139. return face
  140. }