1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #20731 from komakai:matrix_mult_android_ios

This commit is contained in:
Alexander Alekhin
2021-10-05 15:35:58 +00:00
8 changed files with 90 additions and 2 deletions
+10
View File
@@ -114,7 +114,17 @@ CV_EXPORTS @interface Mat : NSObject
- (BOOL)isSubmatrix;
- (void)locateROI:(Size2i*)wholeSize ofs:(Point2i*)offset NS_SWIFT_NAME(locateROI(wholeSize:offset:));
- (Mat*)mul:(Mat*)mat scale:(double)scale;
/**
Performs element-wise multiplication
@param mat operand with with which to perform element-wise multiplication
*/
- (Mat*)mul:(Mat*)mat;
/**
Performs matrix multiplication
@param mat operand with with which to perform matrix multiplication
@see `Core.gemm(...)`
*/
- (Mat*)matMul:(Mat*)mat;
+ (Mat*)ones:(int)rows cols:(int)cols type:(int)type NS_SWIFT_NAME(ones(rows:cols:type:));
+ (Mat*)ones:(Size2i*)size type:(int)type NS_SWIFT_NAME(ones(size:type:));
+ (Mat*)onesEx:(NSArray<NSNumber*>*)sizes type:(int)type NS_SWIFT_NAME(ones(sizes:type:));
+5
View File
@@ -372,6 +372,11 @@ static bool updateIdx(cv::Mat* mat, std::vector<int>& indices, size_t inc) {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->mul(*(cv::Mat*)mat.nativePtr))];
}
- (Mat*)matMul:(Mat*)mat {
cv::Mat temp = self.nativeRef * mat.nativeRef;
return [Mat fromNative:temp];
}
+ (Mat*)ones:(int)rows cols:(int)cols type:(int)type {
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::ones(rows, cols, type))];
}
@@ -715,3 +715,9 @@ public extension Mat {
return MatAt(mat: self, indices: indices)
}
}
public extension Mat {
static func *(lhs:Mat, rhs: Mat) -> Mat {
return lhs.matMul(rhs)
}
}
+10
View File
@@ -683,6 +683,16 @@ class MatTests: OpenCVTestCase {
try assertMatEqual(truth!, dst, OpenCVTestCase.EPS)
}
func testMatMulMat() throws {
let m1 = Mat(rows: 2, cols: 2, type: CvType.CV_32F, scalar: Scalar(2))
let m2 = Mat(rows: 2, cols: 2, type: CvType.CV_32F, scalar: Scalar(3))
dst = m1.matMul(m2)
truth = Mat(rows: 2, cols: 2, type: CvType.CV_32F, scalar: Scalar(12))
try assertMatEqual(truth!, dst, OpenCVTestCase.EPS)
}
func testOnesIntIntInt() throws {
dst = Mat.ones(rows: OpenCVTestCase.matSize, cols: OpenCVTestCase.matSize, type: CvType.CV_32F)