private static Matrix4x4 CalcPalmMatrix(ref PalmDetect.Palm palm, Vector2 shift, float scale) { // Calc rotation based on // Center of wrist - Middle finger const float RAD_90 = 90f * Mathf.PI / 180f; var vec = palm.keypoints[2] - palm.keypoints[0]; Quaternion rotation = Quaternion.Euler(0, 0, -(RAD_90 + Mathf.Atan2(vec.y, vec.x)) * Mathf.Rad2Deg); // Calc hand scale float handScale = Mathf.Max(palm.rect.width, palm.rect.height) * scale; // Calc hand center position Vector2 center = palm.rect.center + new Vector2(-0.5f, -0.5f); center = (Vector2)(rotation * center); center += (shift * handScale); center /= handScale; Matrix4x4 trs = Matrix4x4.TRS( new Vector3(-center.x, -center.y, 0), rotation, new Vector3(1 / handScale, -1 / handScale, 1) ); return(PUSH_MATRIX * trs * POP_MATRIX); }
public void Invoke(Texture inputTex, PalmDetect.Palm palm) { var options = resizeOptions; cropMatrix = resizer.VertexTransfrom = CalcPalmMatrix(ref palm, PalmShift, PalmScale); resizer.UVRect = TextureResizer.GetTextureST(inputTex, options); RenderTexture rt = resizer.ApplyResize(inputTex, options.width, options.height); ToTensor(rt, input0, false); // interpreter.SetInputTensorData(0, input0); interpreter.Invoke(); interpreter.GetOutputTensorData(0, output0); interpreter.GetOutputTensorData(1, output1); }