Run time error
I have this error:
OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 ||
type == CV_32FC2 || type == CV_64FC2)) in gemm, file /build/buildd/opencv-
2.3.1/modules/core/src/matmul.cpp, line 701 terminate called after throwing an instan
ce of 'cv::Exception' what(): /build/buildd/opencv-2.3.1/modules/core/
src/matmul.cpp:701: error: (-215) type == B.type() && (type == CV_32FC1 ||
type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function gemm
I m sure is generated in a function I use because I used a print function after using that function. Originally what I have to do is translate to C with openCV this matlab's code:
function Xdecorr= color Decorrelation(X,numChannels)
if numChannels >1
mu=mean(X);
X=bsxfun(@minus,X,mu);
A=X'*X;
[V,D,notused]=svd(A);
Xdecorr=X*V;
else
Xdecorr=Xdecorr;
end
I translated in C as:
Mat colorDecorrelation(Mat img,int numColComp){
Mat V,D,A,mu,Xdecorr,img_tr;
SVD svd;
if(numColComp>1){
mu=mean(img);
subtract(img,mu,img);
transpose(img,img_tr);
A = img_tr*img;
V = svd(A).u;
Xdecorr = img*V;
}
else
Xdecorr = img;
return Xdecorr;
}
The error is for sure when I do : A=img_tr*img
did you check the type() of img ? gemm wants float types
if img,type() is CV_8UC3, you'd need to img.convertTo(img_f,CV_32FC3); before the transpose
I have the same problem. When I open the img, his datas are:
For this I suppose the type is what you said. Before entrering the function i reshape it and I obtain r=314928 & c=1, fot this I use transpoce to obtain the covariance matrix.But now printing the img_tr datas are:
yes. now what is your question there ?
does the matrix mul work now ?
IT doesn' t work, and running I have this message:
type == CV_32FC2 || type == CV_64FC2)) in gemm, file /build/buildd/opencv- 2.3.1/modules/core/src/matmul.cpp, line 701 terminate called after throwing an instan ce of 'cv::Exception
ouch, sorry , i did not read properly.
the error states, that it wants 1 (or 2) channel matrices for multiplication, 3 channels won't work
also found a little bug in your code: mean() returns a Scalar, not a Mat. please change that( the Mat is just invalid in that case, and subtract will ignore it)