0

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

结果相同。

解决办法是什么?

4

0 回答 0