我有一个矩阵D
,我希望将其设置为零,其他矩阵T
为零,否则保持原样。在numpy中,我会这样做:
D[T==0]=0;
但是cv::Mat
,不知道怎么做。我试过这个:
D&=(T!=0);
有了这个结果:
OpenCV Error: Assertion failed (type == B.type()) in gemm, file /build/opencv-AuXD2R/opencv-3.3.1/modules/core/src/matmul.cpp, line 1558
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-AuXD2R/opencv-3.3.1/modules/core/src/matmul.cpp:1558: error: (-215) type == B.type() in function gemm
我是混合数字类型的问题吗?我之后也尝试了这一点(D
也是CV_32F
,我通过输出T.type()
,5
验证了这一点:
cv::Mat TnotZero;
cv::Mat(T!=0).convertTo(TnotZero,CV_32F);
D&=TnotZero;
具有相同的结果。
解决方案是什么?