Ask Your Question

Revision history [back]

I suppose that align is vector of uchar. You have to use substract instead of - to set result type (here float with one channel CV_32FC1):

vector<uchar> align={1,2,3,4};
Mat dev1;

subtract(Mat(align), 2, dev1, Mat(), CV_32FC1);
cout << dev1;
cout << Mat(align)-2;

I suppose that align is vector of uchar. You have to use substract instead of - to set result type (here float with one channel CV_32FC1):

vector<uchar> align={1,2,3,4};
Mat dev1;

subtract(Mat(align), 2, dev1, Mat(), CV_32FC1);
cout << dev1;
cout << Mat(align)-2;
Mat(align)-2; // wrong because uchar cannot be negative

I suppose that align is vector of uchar. You have to use substract instead of - to set result type (here float with one channel CV_32FC1):

vector<uchar> align={1,2,3,4};
Mat dev1;

subtract(Mat(align), 2, dev1, Mat(), CV_32FC1);
cout << dev1;
cout << Mat(align)-2; // wrong because uchar cannot be negative

but @berak solution is better :

you should use meanStdDev()

Mat mean, dev; //you can use Scalar, too.

meanStdDev(image, mean, dev);

PS I will transfer upvote

I suppose that align is vector of uchar. You have to use substract instead of - to set result type (here float with one channel CV_32FC1):

vector<uchar> align={1,2,3,4};
Mat dev1;

subtract(Mat(align), 2, dev1, Mat(), CV_32FC1);
cout << dev1;
cout << Mat(align)-2; // wrong because uchar cannot be negative

but @berak solution is better :

you should use meanStdDev()

Mat mean, dev; //you can use Scalar, too.

meanStdDev(image, mean, dev);

PS I will transfer upvote

I suppose that align is vector of uchar. You have to use substract instead of - to set result type (here float with one channel CV_32FC1):

vector<uchar> align={1,2,3,4};
align={1,1,3,3};
Mat dev1;

subtract(Mat(align), 2, dev1, Mat(), CV_32FC1);
cout << dev1;
cout << Mat(align)-2; // wrong because uchar cannot be negative