Designing and Implementing a Microsoft Azure AI Solution

Rotate Face for Better Analysis

Question

You provisioned the Face service in Azure.

While you analyzed the results of a set of face data, you observed inefficiencies in analysis where the face was angled.

In your coding you plan to use the necessary attribute to rotate the face for better analysis.

Review the code snippet below and complete it by selecting the attribute to rotate the face rectangle.

(select one answer choice)

if (face.FaceAttributes?...............................

!= null) { faceAngle = face.FaceAttributes.?.................................Roll; var angleToPi = Math.Abs((faceAngle / 180) * Math.PI); var newLeft = face.FaceRectangle.Left + face.FaceRectangle.Width / 2 - (face.FaceRectangle.Width * Math.Sin(angleToPi) + face.FaceRectangle.Height * Math.Cos(angleToPi)) / 2; var newTop = face.FaceRectangle.Top + face.FaceRectangle.Height / 2 - (face.FaceRectangle.Height * Math.Sin(angleToPi) + face.FaceRectangle.Width * Math.Cos(angleToPi)) / 2; left = (int)(newLeft * scale + uiXOffset); top = (int)(newTop * scale + uiYOffset); }

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer: D

Here is the completed code:

<pre class="brush:java;">if (face.FaceAttributes?.HeadPose != null)

{

faceAngle = face.FaceAttributes.HeadPose.Roll;

var angleToPi = Math.Abs((faceAngle / 180) * Math.PI);

var newLeft = face.FaceRectangle.Left +

face.FaceRectangle.Width / 2 -

(face.FaceRectangle.Width * Math.Sin(angleToPi) + face.FaceRectangle.Height * Math.Cos(angleToPi)) / 2;

var newTop = face.FaceRectangle.Top +

face.FaceRectangle.Height / 2 -

(face.FaceRectangle.Height * Math.Sin(angleToPi) + face.FaceRectangle.Width * Math.Cos(angleToPi)) / 2;

left = (int)(newLeft * scale + uiXOffset);

top = (int)(newTop * scale + uiYOffset);

}

</pre>Option A is incorrect because FaceRectangle is not the correct face attribute.

Option B is incorrect because the Occlusion attribute is used to identify if there are any objects blocking the face such as eyes or mouth.

Option C is incorrect because the Exposure attribute is used for the exposure level of the image such as underExposure, goodExposure or overExposure.

Option D is correct because the HeadPose attribute is used for rotating the face rectangle.

It is very helpful in scenarios where the face is angled.

Reference:

To learn more about using the HeadPose attribute, use the link given below:

The correct answer is D. HeadPose.

The code is using the Microsoft Azure Face service to analyze a set of face data. In this code snippet, the goal is to improve the efficiency of the analysis of angled faces.

The code checks whether the FaceAttributes object of the face is not null, which means that the face analysis results contain attributes about the head pose, including the roll, yaw, and pitch angles. The roll angle is the rotation of the face around the vertical axis, which is the attribute that needs to be used to rotate the face rectangle.

Therefore, the correct attribute to complete the code is face.FaceAttributes.HeadPose.Roll, which retrieves the roll angle from the FaceAttributes object. This angle is then converted to radians and used to calculate the new position of the face rectangle to improve the analysis of the angled face.

The newLeft and newTop variables calculate the new position of the face rectangle by applying a rotation transformation to the original face rectangle. The scale and uiXOffset and uiYOffset variables are used to convert the new position to screen coordinates.

In summary, the HeadPose.Roll attribute is used to retrieve the roll angle of the face, which is then used to rotate the face rectangle for better analysis.