Reputation: 427
I have declared a Matrix which contains values equal to 1: cv::Mat mat_cal = cv::Mat::ones(width, height, CV_8U);
Now I want to to be multiplied by a constant, I mean, one matrix whose values are equal to A=0.3 Then I wrote: cv::Mat mat_cal = cv::Mat::ones(width, height, CV_8U)*A;
But, the result? Matrix of 0 0 0 0 0 0 0 0.....
Any solution?
Upvotes: 0
Views: 578
Reputation: 6043
Part of your problem is your matrix type is CV_8U
which is an 8-bit unsigned integer - as such 0.3
gets trunctated to 0
. Instead set it to CV_32F
(32-bit floating point).
Also, if I remember, when multiplying by a scalar, you do as below. Multiplying 2 matrices doesn't work the same way:
float A = 0.3;
cv::Mat mat_cal = cv::Mat::ones(width, height, CV_32F)*A;
Upvotes: 1
Reputation: 39796
char i = 1;
i *= 0.3;
result ? 0
it's just plain old integer rounding.
if you want a Mat with double or float values, use the right type in the first place:
cv::Mat::ones(width, height, CV_32F)*0.3f; // float
or:
cv::Mat::ones(width, height, CV_64F)*0.3; // double
Upvotes: 0