code: def estimate_affine_matrix_3d22d(X, x):
      """Using Golden Standard Algorithm for estimating an affine camera
          matrix P from world to image correspondences.
          See Alg.7.2. in MVGCV
          Code Ref: https://github.com/patrikhuber/eos/blob/master/include/eos/fitting/affine_camera_estimation.hpp
          x_homo = X_homo.dot(P_Affine)
      Args:
          X: [n, 3]. corresponding 3d points(fixed)
          x: [n, 2]. n>=4. 2d points(moving). x = PX
      Returns:
          P_Affine: [3, 4]. Affine camera matrix
      """
      X = X.T
      x = x.T
      assert x.shape[1] == X.shape[1]
      n = x.shape[1]
      assert n >= 4
  
      # --- 1. normalization
      # 2d points
      mean = np.mean(x, 1)  # (2,)
      x = x - np.tile(mean[:, np.newaxis], [1, n])
      average_norm = np.mean(np.sqrt(np.sum(x**2, 0)))
      scale = np.sqrt(2) / average_norm
      x = scale * x
  
      T = np.zeros((3, 3), dtype=np.float32)
      T[0, 0] = T[1, 1] = scale
      T[:2, 2] = -mean * scale
      T[2, 2] = 1
  
      # 3d points
      X_homo = np.vstack((X, np.ones((1, n))))
      mean = np.mean(X, 1)  # (3,)
      X = X - np.tile(mean[:, np.newaxis], [1, n])
      m = X_homo[:3, :] - X
      average_norm = np.mean(np.sqrt(np.sum(X**2, 0)))
      scale = np.sqrt(3) / average_norm
      X = scale * X
  
      U = np.zeros((4, 4), dtype=np.float32)
      U[0, 0] = U[1, 1] = U[2, 2] = scale
      U[:3, 3] = -mean * scale
      U[3, 3] = 1
  
      # --- 2. equations
      A = np.zeros((n * 2, 8), dtype=np.float32)
      X_homo = np.vstack((X, np.ones((1, n)))).T
      A[:n, :4] = X_homo
      A[n:, 4:] = X_homo
      b = np.reshape(x, [-1, 1])
  
      # --- 3. solution
      p_8 = np.linalg.pinv(A).dot(b)
      P = np.zeros((3, 4), dtype=np.float32)
      P[0, :] = p_8[:4, 0]
      P[1, :] = p_8[4:, 0]
      P[-1, -1] = 1
  
      # --- 4. denormalization
      P_Affine = np.linalg.inv(T).dot(P.dot(U))
      return P_Affine
  
file_path: insightface/python-package/insightface/thirdparty/face3d/mesh/transform.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import math
  from math import cos, sin
label_desc: Use image node_id 11 for calling a global function with example usage: estimate_affine_matrix_3d22d(X, x) and returns: P_Affine