title: Convert Python to Java Opencv
body: <p>I am trying to convert this code snippet to Java for days now</p>
  
  <p>ef transformation_from_points(points1, points2):
          """
          points1 and points2 are 68 X 2 matrices.</p>
  
  <pre><code>    Return an affine transformation [s * r | T] such that:
          sum ||s*r*p1,i + T - p2,i||^2
      is minimized.
  
      output is a 3x3 matrix.
      """
      # Solve the procrustes problem by subtracting centroids, scaling by the
      # standard deviation, and then using the SVD to calculate the rotation.
  
      # print("point1 Type = {0}".format(type(points1)))
      # print("point2 Type = {0}".format(type(points2)))
  
      points1 = points1.astype(np.float64)
      points2 = points2.astype(np.float64)
  
      # print("point1 = {0}".format(points1))
      # print("point2 = {0}".format(points2))
  
      c1 = np.mean(points1, axis=0)
      c2 = np.mean(points2, axis=0)
  
      # print("SCALAR ", c1, c2)
  
      #print("c1 = {0}".format(c1))
      # print("c2 = {0}".format(c1))
  
      points1 -= c1
      points2 -= c2
      #
      # print("AFTER SUBTRACTION ", points1)
      # print("AFTER SUBTRACTION ", points2)
  
      s1 = np.std(points1)
      s2 = np.std(points2)
      #
      # print("AFTER STANDARD DEVIATION ", s1)
      # print("AFTER STANDARD DEVIATION", s2)
  
      points1 /= s1
      points2 /= s2
  
      # print("AFTER DIVISION ", points1)
      # print("AFTER DIVISION ", points2)
  
      # print("Points1.T = {0}".format(points1.T))
      # print("Points2.T = {0}".format(points2.T))
  
      u, s, vt = np.linalg.svd(points1.T * points2)
  
      print("POINT 1 ", points1.shape)
      print("POINT 1 TRANSPOSE ", (points1.T).shape)
      print("POINT 2 ", points2.shape)
      print("POINT 1 TRANS POINT 2 ", (points1.T * points2).shape)
  
      #
      # print("POINT 3 ", points1.shape)
      # print("POINT 3 ", type(points1))
  
      # The r we seek is in fact the transpose of the one given by u * vt. This
      # is because the above formulation assumes the matrix goes on the right
      # (with row vectors) where as our solution requires the matrix to be on the
      # left (with column vectors).
      r = (u * vt).T
  
      return np.vstack([np.hstack(((s2 / s1) * r, c2.T - (s2 / s1) * r * c1.T)), np.matrix([0., 0., 1.])])
  </code></pre>
  
  <p>this is how far I have gotten</p>
  
  <p>I have not been able to perform the Matrix multiplication</p>
  
  <p>Please what am I doing wrong??</p>
  
  <p>public Mat transformationFromPoints(ArrayList selfieImageLandmarks,
                                          ArrayList hairModelImageLandmark){</p>
  
  <pre><code>    org.opencv.core.Point selfieImage [] = new org.opencv.core.Point[selfieImageLandmarks.size()];
      for(int i = 0; i &lt; selfieImageLandmarks.size(); i++){
          selfieImage[i] = new org.opencv.core.Point(selfieImageLandmarks.get(i).x,
                                                      selfieImageLandmarks.get(i).y);
      }
  
      org.opencv.core.Point hairModel [] = new org.opencv.core.Point[hairModelImageLandmark.size()];
      for(int i = 0; i &lt; selfieImageLandmarks.size(); i++){
          hairModel[i] = new org.opencv.core.Point(hairModelImageLandmark.get(i).x,
                                                      hairModelImageLandmark.get(i).y);
      }
  
      MatOfPoint point1 = new MatOfPoint(selfieImage);
      MatOfPoint point2 = new MatOfPoint(hairModel);
  
      MatOfDouble mean1 = new MatOfDouble();
      MatOfDouble s1 = new MatOfDouble();
      Core.meanStdDev(point1, mean1, s1);
      Scalar stdScalar1 = new Scalar(s1.get(0, 0)[0]);
  
  
      MatOfDouble mean2 = new MatOfDouble();
      MatOfDouble s2 = new MatOfDouble();
      Core.meanStdDev(point2, mean2, s2);
      Scalar stdScalar2 = new Scalar(s2.get(0, 0)[0]);
  
      Core.divide(point1, stdScalar1, point1);
      Core.divide(point2, stdScalar2, point2);
  
      Mat src = new Mat();
  
      Core.gemm(point1.t(), point2, 1, new Mat(), 0, src);
  
  
      return null;
  }
  </code></pre>