Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to add 2 Mat objects of different type?

Hi all, When I run the following code:

const Mat A( 10, 20, CV_32FC1, Scalar::all(CV_PI) );
const Mat B( A.size(), CV_8UC1, Scalar::all(10) );
Mat C( A.size(), A.type() );
C = A + B;
I get the run-time error:
OpenCV Error: Bad argument (When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified) in arithm_op, file /usr/local/src/OpenCV/modules/core/src/arithm.cpp, line 1269

So, is there a way to explicitly specify the output array type of A+B as float? Thanks

click to hide/show revision 2
No.2 Revision

How to add 2 Mat objects of different type?

Hi all, When I run the following code:

const Mat A( 10, 20, CV_32FC1, Scalar::all(CV_PI) );
const Mat B( A.size(), CV_8UC1, Scalar::all(10) );
Mat C( A.size(), A.type() );
C = A + B;B;

I get the run-time error: error:

 OpenCV Error: Bad argument (When the input arrays in add/subtract/multiply/divide add/subtract/multiply/divide
functions have different types, the output array type must be explicitly specified) in in
 arithm_op, file /usr/local/src/OpenCV/modules/core/src/arithm.cpp, line 1269

So, is there a way to explicitly specify the output array type of A+B as float? Thanks