Specify Output Type of Arithmetic Operation in OpenCV

In OpenCV, I can add two matrices of the same type using an operator +

like:

cv::Mat mat3 = mat1 + mat2;

When I try to add two matrices of different types this way, I get a runtime error that says "When the input arrays in the add / subtract / multiply / divide functions are of different types, the type of the output array must be explicitly specified."

How should I specify the type of inference for operations like this when applying them to matrices of different types?

+3


source to share


2 answers


"How do I set the output type"

Unfortunately, C ++ overloaded operators won't let you specify this.

use a code like:



cv::Mat mat3;
add(mat1, mat2, mat3, Mat(), CV_32F); // the additional Mat() is an empty Mask

      

as always also see docs

+5


source


First declare the size of Mat C. Hope this helps



0


source







All Articles