I have a m-file in MATLAB.It calulates normxcorr2 between an image and a template as follow:
function norm_res = TMatch(temp,image)
c = normxcorr2(temp,image);
norm_res = max(c(:));
when I running this m-file from MATLAB command line with two images as image and template, it gives me 0.8076 as a result. Now I build it as a shared library with following command:
mcc -B cpplib:TMatch TMatch.m
in MATLAB command line and it generates required files for using in C++.
Now I use generated shared library in visual studio as following:
mclInitializaApplication();
TMatchInitialize();
Mat img = imread("image.jpg", IMREAD_GRAYSCALE);
Mat tmp = imread("temp.jpg", IMREAD_GRAYSCALE);
// these files are the same as files which are used in MATLAB
mwArray mwImg(img.rows,img.cols,mxDOUBLE_CLASS,mxREAL);
mwArray mwTemp(tmp.rows,tmp.cols,mxDOUBLE_CLASS,mxREAL);
mwArray result;
mwImg.SetData(img.data,img.cols * img.rows);
mwTemp.SetData(tmp.data,tmp.cols * tmp.rows);
TMatch(1,result,mwTemp,mwImg);
double normed_res;
result.GetData(&normed_res); //finally result will be 0.198949
As you can see when I run m-file in MATLAB result will be:
0.8076
and when I generate a shared library and use it in visual studio C++ the result will be:
0.198949
please tell me why this happens?
Thanks in advance.
(@Miki @A.Riazi)