# Segmentation fault: 11 after matrix multiplication

Hi everyone: I am a newbie to OpenCV and try to duplicate the work from matlab to C++. Here is my C++ code below

int main(int argc, char const *argv[])
{

//import image
Mat_<double> img1, img2, img3;

//Push all the image it to one vector for SVDecomp
Mat_<double> svd_use;
svd_use.push_back(img1.reshape(0,1));
svd_use.push_back(img2.reshape(0,1));
svd_use.push_back(img3.reshape(0,1));

Mat_<double> source, trans, B, W, U, VT,U;
trans = svd_use.t();
source = svd_use*trans;
SVDecomp(source, W, U, VT);

//To make sure the value is the same as matlab
W = (Mat_<double>(3,3) << W, 0, 0, 0, W, 0, 0, 0,W);
U = (Mat_<double>(3,3) << -U, -U, U , -U, -U, U, -U, -U, U);

B = trans*U//<---this part cause the  Segmentation fault: 11
return 0;
}


Here is my matlab code

source_img1 = rgb2gray(imread('S1.JPG'));

%Vectorize images
img_vector1 = source_img1(:);
img_vector2 = source_img2(:);
img_vector3 = source_img3(:);

%Calculate SVD
t = double([img_vector1'; img_vector2'; img_vector3']);
[U,S,V] = svd(t*t');
B = t'*V*S^(-1/2);


Could someone know how to solve this situation? Thanks!! The size of trans is 3 * 16032768 (row* col) and U is 3*3, so I am pretty sure that can be multiply.

edit retag close merge delete