void DrawResults(FaceDetect.Result detection, FaceMesh.Result face) { cameraView.rectTransform.GetWorldCorners(rtCorners); Vector3 min = rtCorners[0]; Vector3 max = rtCorners[2]; // Draw Face Detection { draw.color = Color.blue; Rect rect = MathTF.Lerp(min, max, detection.rect, true); draw.Rect(rect, 0.05f); foreach (Vector2 p in detection.keypoints) { draw.Point(MathTF.Lerp(min, max, new Vector3(p.x, 1f - p.y, 0)), 0.1f); } } draw.Apply(); // Draw face draw.color = Color.green; float zScale = (max.x - min.x) / 2; for (int i = 0; i < face.keypoints.Length; i++) { Vector3 p = MathTF.Lerp(min, max, face.keypoints[i]); p.z = face.keypoints[i].z * zScale; faceKeypoints[i] = p; draw.Point(p, 0.05f); } draw.Apply(); // Update Mesh FaceMeshBuilder.UpdateMesh(faceMeshFilter.sharedMesh, faceKeypoints); }
private void OnTextureUpdate(Texture texture) { if (detectionResult == null || !useLandmarkToDetection) { faceDetect.Invoke(texture); cameraView.material = faceDetect.transformMat; detectionResult = faceDetect.GetResults().FirstOrDefault(); if (detectionResult == null) { return; } } faceMesh.Invoke(texture, detectionResult); croppedView.texture = faceMesh.inputTex; meshResult = faceMesh.GetResult(); if (meshResult.score < 0.5f) { detectionResult = null; return; } if (useLandmarkToDetection) { detectionResult = faceMesh.LandmarkToDetection(meshResult); } }
private void DrawResults(FaceDetect.Result faceDetectionResult, FaceMesh.Result faceMesh, IrisDetect.Result irisLeftResult, IrisDetect.Result irisRightResult) { viewWebCam.rectTransform.GetWorldCorners(m_rtCorners); Vector3 min = m_rtCorners[0]; Vector3 max = m_rtCorners[2]; float zScale = (max.x - min.x) / 2; Color32 faceMeshDetectColor = new Color32(30, 150, 255, 255); Color32 eyeDetectColor = new Color32(255, 255, 0, 255); Color32 irisDetectColor = new Color32(255, 0, 0, 255); // TODO check why 6 landmarks are not showing up properly //DrawFaceDetection(faceDetectionResult, min, max, new Color32(80,200,255,255), 0.05f); DrawFaceMeshDetection(faceMesh, min, max, faceMeshDetectColor, zScale, 0.035f); DrawEyeDetection(min, max, irisLeftResult, irisRightResult, eyeDetectColor, zScale, 0.035f); DrawIrisDetection(min, max, irisLeftResult, irisRightResult, irisDetectColor, zScale, 0.035f); //TODO uncomment this to show up mesh //RenderFaceMesh(); }
private void DrawFaceMeshDetection(FaceMesh.Result face, Vector3 min, Vector3 max, Color color, float zScale, float pntSize) { LerpPointArray(face.keypoints, min, max, zScale, pntSize, color, "FACE"); }