Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1)

if you don't specify the dtype arg in cv::add() the 3rd arg will get reallocated to the type(and size) of the input operands, and your initialization of C will get completely ignored. if you check C.type() after the add(A,B,C) you'll find, that it's type is CV_8UC1, not CV_32S.

so, give it an empty mask param, and specify dtype:

Mat A(4, 4, CV_8UC1, 200);
Mat B(4, 4, CV_8UC1, 200);
Mat C(4, 4, CV_32S, 0);
cv::add(A, B, C,Mat(),CV_32S);
cout << C.type() << endl;
cout << C << endl;

result: 4 [400, 400, 400, 400; 400, 400, 400, 400; 400, 400, 400, 400; 400, 400, 400, 400]

void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1)

if you don't specify the dtype arg in cv::add() the 3rd arg will get reallocated to the type(and size) of the input operands, and your initialization of C will get completely ignored. if you check C.type() after the add(A,B,C) you'll find, that it's type is CV_8UC1, not CV_32S.

so, give it an empty mask param, and specify dtype:

Mat A(4, 4, CV_8UC1, 200);
Mat B(4, 4, CV_8UC1, 200);
Mat C(4, 4, CV_32S, 0);
cv::add(A, B, C,Mat(),CV_32S);
cout << C.type() << endl;
cout << C << endl;

result: result:

4
 [400, 400, 400, 400;
  400, 400, 400, 400;
  400, 400, 400, 400;
  400, 400, 400, 400]

400]
void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1)

if you don't specify the dtype arg in cv::add() the 3rd arg will get reallocated to the type(and size) of the input operands, and your initialization of C will get completely ignored. if you check C.type() after the add(A,B,C) you'll find, that it's type is CV_8UC1, not CV_32S.

so, give it an empty mask param, and specify dtype:

Mat A(4, 4, CV_8UC1, 200);
Mat B(4, 4, CV_8UC1, 200);
Mat C(4, C; //(4, 4, CV_32S, 0);
0);  // allocation will get ignored anyway(OutputArray)
cv::add(A, B, C,Mat(),CV_32S);
cout << C.type() << endl;
cout << C << endl;

result:

4
[400, 400, 400, 400;
 400, 400, 400, 400;
 400, 400, 400, 400;
 400, 400, 400, 400]