To ensure that user-uploaded photos meet the requirements for the Hairstyle Processing API, it’s recommended to split the workflow into two stages: “Face Analysis” and “Hairstyle Processing.” This approach helps minimize long error return times by validating the image at the frontend to confirm it meets the standards before calling the Hairstyle Processing API, ultimately enhancing the user experience.
No Face or Multiple Faces: If no face or multiple faces are detected in the image, the frontend should return an error message, prompting the user to retake or re-upload a suitable photo.
Non-compliant Face-to-Image Ratio: If the face occupies less than the specified percentage of the image (typically 10%), crop the image at the frontend to meet the required face-to-image ratio.
To accomplish the validations above, the frontend can use the Facial Landmarks API to obtain key face data for assessing face count, face-to-image ratio, and face angle.
If the ratio is less than 0.1, it does not meet the requirement. Using the location values for left, top, width, and height and the overall image dimensions, determine the appropriate crop area to adjust the face-to-image ratio.
Face Angle:
Validation criteria: If any criterion is not met, return an error message, prompting the user to retake or re-upload the photo.
The absolute value of angle.yaw should be less than 30
The absolute value of angle.pitch should be less than 30
The absolute value of angle.roll should be less than 30