mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Simple matrix multiplication for Mat in iOS/Android
This commit is contained in:
@@ -466,16 +466,32 @@ public class Mat {
|
||||
// C++: Mat Mat::mul(Mat m, double scale = 1)
|
||||
//
|
||||
|
||||
// javadoc: Mat::mul(m, scale)
|
||||
/**
|
||||
* Element-wise multiplication with scale factor
|
||||
* @param m operand with with which to perform element-wise multiplication
|
||||
* @param scale scale factor
|
||||
*/
|
||||
public Mat mul(Mat m, double scale) {
|
||||
return new Mat(n_mul(nativeObj, m.nativeObj, scale));
|
||||
}
|
||||
|
||||
// javadoc: Mat::mul(m)
|
||||
/**
|
||||
* Element-wise multiplication
|
||||
* @param m operand with with which to perform element-wise multiplication
|
||||
*/
|
||||
public Mat mul(Mat m) {
|
||||
return new Mat(n_mul(nativeObj, m.nativeObj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Matrix multiplication
|
||||
* @param m operand with with which to perform matrix multiplication
|
||||
* @see Core#gemm(Mat, Mat, double, Mat, double, Mat, int)
|
||||
*/
|
||||
public Mat matMul(Mat m) {
|
||||
return new Mat(n_matMul(nativeObj, m.nativeObj));
|
||||
}
|
||||
|
||||
//
|
||||
// C++: static Mat Mat::ones(int rows, int cols, int type)
|
||||
//
|
||||
@@ -1732,6 +1748,8 @@ public class Mat {
|
||||
|
||||
private static native long n_mul(long nativeObj, long m_nativeObj);
|
||||
|
||||
private static native long n_matMul(long nativeObj, long m_nativeObj);
|
||||
|
||||
// C++: static Mat Mat::ones(int rows, int cols, int type)
|
||||
private static native long n_ones(int rows, int cols, int type);
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package org.opencv.core
|
||||
|
||||
operator fun Mat.times(other: Mat): Mat = this.matMul(other)
|
||||
@@ -686,6 +686,16 @@ public class MatTest extends OpenCVTestCase {
|
||||
assertMatEqual(truth, dst, EPS);
|
||||
}
|
||||
|
||||
public void testMatMulMat() {
|
||||
Mat m1 = new Mat(2, 2, CvType.CV_32F, new Scalar(2));
|
||||
Mat m2 = new Mat(2, 2, CvType.CV_32F, new Scalar(3));
|
||||
|
||||
dst = m1.matMul(m2);
|
||||
|
||||
truth = new Mat(2, 2, CvType.CV_32F, new Scalar(12));
|
||||
assertMatEqual(truth, dst, EPS);
|
||||
}
|
||||
|
||||
public void testOnesIntIntInt() {
|
||||
dst = Mat.ones(matSize, matSize, CvType.CV_32F);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user