Kaathe
Kaathe

Reputation: 335

Specify output type of arithmetic operation in OpenCV

In OpenCV, I can add two matrices of the same type using the + operator, like so:

cv::Mat mat3 = mat1 + mat2;

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

How should I go about specifying the output type for operations like this, when applying them to matrices of different types?

Upvotes: 4

Views: 2870

Answers (2)

Abhishek Ranjan
Abhishek Ranjan

Reputation: 238

Declare the size of Mat C first. Hopefully this can help

Upvotes: 0

berak
berak

Reputation: 39796

"How should I go about specifying the output type"

unfortunately, the overloaded c++ operators won't let you specify that.

use code like:

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

as always, also see docs

Upvotes: 6

Related Questions