void LateUpdate() { // Face landmark detection _detector.ProcessImage(_webcam.Texture); // UI update _previewUI.texture = _webcam.Texture; }
void RunPipeline(Texture input) { if (Time.frameCount < 10) { _usePrev = false; } // Face detection _faceDetector.ProcessImage(input); // Face region cropping _cropMaterial.SetMatrix("_Xform", FaceCropMatrix); Graphics.Blit(input, _faceCrop, _cropMaterial, 0); // Face landmark detection _faceMesh.ProcessImage(_faceCrop); // Eye region cropping (left) _cropMaterial.SetMatrix("_Xform", LeftEyeCropMatrix); Graphics.Blit(input, _irisCropL, _cropMaterial, 0); // Iris landmark detection (left) _irisMeshL.ProcessImage(_irisCropL); // Eye region cropping (right) _cropMaterial.SetMatrix("_Xform", RightEyeCropMatrix); Graphics.Blit(input, _irisCropR, _cropMaterial, 0); // Iris landmark detection (right) _irisMeshR.ProcessImage(_irisCropR); // Face landmark refinement var refine = _resources.refinementCompute; refine.SetBuffer(0, "_FaceVertices", _faceMesh.VertexBuffer); refine.SetBuffer(0, "_RefineBuffer", _refineBuffer); refine.SetMatrix("_FaceXForm", FaceCropMatrix); refine.Dispatch(0, FaceLandmarkDetector.VertexCount / 52, 1, 1); refine.SetBuffer(1, "_EyeToFaceTable", _eyeToFace); refine.SetBuffer(1, "_EyeVerticesL", _irisMeshL.VertexBuffer); refine.SetBuffer(1, "_EyeVerticesR", _irisMeshR.VertexBuffer); refine.SetMatrix("_EyeXFormL", LeftEyeCropMatrix); refine.SetMatrix("_EyeXFormR", RightEyeCropMatrix); refine.SetBuffer(1, "_RefineBuffer", _refineBuffer); refine.Dispatch(1, 1, 1, 1); var angle = MathUtil.Angle(MidwayBetweenEyes - NoseTip) - math.PI / 2; var scale = 1 / FaceCropScale * math.distance(MidwayBetweenEyes.xy, NoseTip.xy) * 3.0f; if (_usePrev) { _prevFaceAngle = math.lerp(_prevFaceAngle, angle, 0.2f); _prevFaceScale = math.lerp(_prevFaceScale, scale, 0.2f); } else { _prevFaceAngle = angle; _prevFaceScale = scale; _usePrev = true; } /* * * refine.SetMatrix("_EyeXFormL", * math.mul(math.mul(float4x4.Translate(math.float3(-FaceCropOffset, 0)), * float4x4.Scale(1 / FaceCropScale)), * math.mul(float4x4.Translate(math.float3(LeftEyeCropOffset, 0)), * float4x4.Scale(EyeCropScale)))); * * //MathUtil.CropMatrix(0, EyeCropScale / FaceCropScale, * //LeftEyeCropOffset - FaceCropOffset)); * * //refine.SetMatrix("_EyeXFormR", * //MathUtil.CropMatrix(0, EyeCropScale / FaceCropScale, * // RightEyeCropOffset - FaceCropOffset)); */ }