Ask Your Question

Mat operation

asked 2017-01-21 21:39:07 -0500

Shabrina gravatar image

updated 2017-01-21 21:39:41 -0500

I have vector ay[4] , then I get the mean of vector. So, I change the vector to matrix. like this

Mat total,rata;
total =  Mat(ay[1]) + Mat(ay[2]) + Mat(ay[3]);
rata = total/3;
cout <<"Total"<< total << endl;
cout <<"Rata"<< rata << endl;

Then, I use the mean of matrix for get the deviation, this is the code.

Mat dev[4], chg[4];
for (int abc=0; abc<4; abc++){
    chg[abc] = Mat(ay[abc]);
for(int s=0; s<4;s++){
cout << "Data" << dev[1] << endl;

when, I operation this code. the program was break. and this is the error

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') in cv::arithm_op, file ........\opencv\modules\core\src\arithm.cpp, line 1287

I dont know why, but that are have the same initialization. Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-01-21 23:26:16 -0500

Tetragramm gravatar image

Whatever you're trying to do this is a terrible way to do it. You're trying to get the mean and standard deviation for each element of a vector, I think?

The technical problem is that rata is not a number, or a Mat the same size as chg[s]. Basically, subtract can remove a single number from every element of the matrix (pass in a double for 1 channel or a Scalar for multiple channels). It can also subtract one matrix from the other, but they must be the same size and number of channels.

The smarter way to do this is this

Mat allVec(ay[0].size(), 4, CV_32F);//Or whatever code matches the type of the vectors.
for(int abc = 0; abc<4; abc++)

for(int size = 0; size<ay[0].size(); size++)
    Scalar mean, stdDev;
    meanStdDev(allVec.row(size), mean, stdDev);
    std::cout<<"Element 1 Mean = "<<mean(0)<<" StdDev = "<<stdDev(0)<<endl;
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-01-21 21:39:07 -0500

Seen: 318 times

Last updated: Jan 21 '17