2016-09-15 265 views
0

简单的问题。我找不到任何解决方案! 这是确定:矩阵乘矢量乘法

Mat dst = new Mat(); 
     Mat a = Mat.ones(3,3,CvType.CV_32FC1); 
     Mat b = Mat.ones(3,3,CvType.CV_32FC1); 
     Core.multiply(a, b, dst); 
     System.out.println("DST\n" + dst.dump()); 

但是,这会导致错误:

Mat dst = new Mat(); 

     Mat a = Mat.ones(3,3,CvType.CV_32FC1); 
     Mat b = Mat.ones(1,3,CvType.CV_32FC1); 

//neither this 
     Core.multiply(a, b, dst); ///<<<< ERROR 
//nor this works 
     Core.multiply(a, b.t(), dst); ///<<<< ERROR 
     System.out.println("DST\n" + dst.dump()); 

OpenCV 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 cv::arithm_op, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core\src\arithm.cpp, line 1987

请帮助找到解决的办法。我怎样才能通过矢量来多元化矩阵?

+2

你看过http://stackoverflow.com/questions/10168058/basic-matrix-mu ltiplication-in-opencv-for-android? – SergeyS

+0

@SergeyS哦。谢谢!没有找到它。 – Vyacheslav

回答

0

我不知道opencv框架,但根据错误消息,您的第二个代码示例中的b似乎是单行矩阵。你需要一列矩阵:

像这样定义b尝试:

Mat b = Mat.ones(3,1,CvType.CV_32FC1); 
+0

这与b.t()相同。我试过了。 – Vyacheslav

+0

显然这种乘法是逐个元素乘法,而不是你正在寻找的矩阵乘法。 –