Ask Your Question
0

Runtime Error with OpenCV Core.Multiply method (Java)

asked 2019-04-11 17:14:26 -0600

updated 2019-04-12 01:42:12 -0600

berak gravatar image

Hello,

Some advice here would be appreciated, been looking at this for a number of weeks.

Error given on Matrix Multiply OpenCV: Core.Multiply() Function Goal: After running SolvePnP doing simple Matrix Multiply with the following matrix dimensions : [3x3]*[3x1] = [3x1]

* Log File Excerpt showing Mat Dumps and Error Message *

LmVSM_k_RotInv : [-0.7248091196769779, -0.6670117571281554, 0.1724733483350253;
-0.6771860665621979, 0.7358117890023557, -0.0002059591509784506;
-0.1267705458184306, -0.1169458294167176, -0.9850141631950949]
LmVSM_k_TransVectNeg : [-7.324298797523894;
-2.210406560977737;
1.162266668817123]
VmVSM_k_ImgPlaneZeroWorld : [1.429164061258389e-101;
1.840923297268401e-80;
8.843939164890396e+247]

OpenCV(3.4.4) Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in arithm_op, file /var/lib/jenkins/workspace/OpenCV/OpenCV - Release/arm/opencv/modules/core/src/arithm.cpp, line 660
Unhandled exception: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.4) /var/lib/jenkins/workspace/OpenCV/OpenCV - Release/arm/opencv/modules/core/src/arithm.cpp:660: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'arithm_op']

* Code Snippets *

  private Mat VmVSM_k_RotVect   = new Mat(3,1,CvType.CV_64F);
  private Mat VmVSM_k_TransVect = new Mat(3,1,CvType.CV_64F);
  private Mat VmVSM_k_Rot       = new Mat(3,3,CvType.CV_64F);
  private Mat VmVSM_k_ImgPlaneZeroWorld = new Mat(3,1,CvType.CV_64F);
     .
     .
     .
      Mat LmVSM_k_RotInv       = new Mat(3,3,CvType.CV_64F);
      Mat LmVSM_k_TransVectNeg = new Mat(3,1,CvType.CV_64F);
      Mat LmVSM_k_ZerosVect    = new Mat(3,1,CvType.CV_64F);
        .
    .
    .
        /* Initialize Local Matricies for prior to Angle2 calculation */
        LmVSM_k_RotInv.zeros(3,3,CvType.CV_64F);
        LmVSM_k_TransVectNeg.zeros(1,3,CvType.CV_64F);
        LmVSM_k_ZerosVect.zeros(3,1,CvType.CV_64F);
          .
      .
      .
        /* Angle2: Calculate horiz angle between the target perpendicular and the robot-target line */
        Calib3d.Rodrigues(VmVSM_k_RotVect, VmVSM_k_Rot);
        Core.transpose(VmVSM_k_Rot,LmVSM_k_RotInv);
        Core.scaleAdd(VmVSM_k_TransVect, -1.0, LmVSM_k_ZerosVect, LmVSM_k_TransVectNeg);
        System.out.println("LmVSM_k_RotInv :            " + LmVSM_k_RotInv.dump());
        System.out.println("LmVSM_k_TransVectNeg :      " + LmVSM_k_TransVectNeg.dump());
        System.out.println("VmVSM_k_ImgPlaneZeroWorld : " + VmVSM_k_ImgPlaneZeroWorld.dump());
        **Core.multiply(LmVSM_k_RotInv, LmVSM_k_TransVectNeg, VmVSM_k_ImgPlaneZeroWorld);**  (Error here apparently)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-04-12 01:51:17 -0600

berak gravatar image

updated 2019-04-12 03:02:48 -0600

doing simple Matrix Multiply with the following matrix dimensions : [3x3]*[3x1] = [3x1]

you're confusing matrix and per-element multiplication, you need gemm(), not multiply(), like:

Mat res = new Mat();
Core.gemm(LmVSM_k_RotInv, LmVSM_k_TransVectNeg, 1, new Mat(), 0, res);
System.out.println(res);

Mat [3*1*CV_64FC1, isCont=true, isSubmat=false, nativeObj=0x7f137014ee90, dataAddr=...]

also: please do not preallocate result Mat's (you're only confusing yourself about result sizes / types), just use new Mat() or similar, like in the lines above.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-04-11 17:14:26 -0600

Seen: 352 times

Last updated: Apr 12 '19