如何将cv :: Mat设置为零,而另一个矩阵是非零的?

时间:2018-01-09 20:34:25

标签: opencv opencv3.3

我有一个矩阵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;

具有相同的结果。

解决方案是什么?

0 个答案:

没有答案